Skip to content

Commit 53618e8

Browse files
version metrics (#1199)
Adding a sync.once to base worker that allows user to start reporting version metrics on a per host basis. They can start it once and if desired permanantely stop it on that host.
1 parent 6759446 commit 53618e8

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

internal/internal_worker.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import (
5151
"go.uber.org/zap/zapcore"
5252
)
5353

54+
var startVersionMetric sync.Once
55+
var StopMetrics = make(chan struct{})
56+
5457
const (
5558
// Set to 2 pollers for now, can adjust later if needed. The typical RTT (round-trip time) is below 1ms within data
5659
// center. And the poll API latency is about 5ms. With 2 poller, we could achieve around 300~400 RPS.
@@ -72,6 +75,8 @@ const (
7275
defaultMaxConcurrentSessionExecutionSize = 1000 // Large concurrent session execution size (1k)
7376

7477
testTagsContextKey = "cadence-testTags"
78+
clientVersionTag = "cadence_client_version"
79+
clientGauge = "client_version_metric"
7580
)
7681

7782
type (
@@ -1255,3 +1260,21 @@ func getTestTags(ctx context.Context) map[string]map[string]string {
12551260
}
12561261
return nil
12571262
}
1263+
1264+
// StartVersionMetrics starts emitting version metrics
1265+
func StartVersionMetrics(metricsScope tally.Scope) {
1266+
startVersionMetric.Do(func() {
1267+
go func() {
1268+
ticker := time.NewTicker(time.Minute)
1269+
versionTags := map[string]string{clientVersionTag: LibraryVersion}
1270+
for {
1271+
select {
1272+
case <-StopMetrics:
1273+
return
1274+
case <-ticker.C:
1275+
metricsScope.Tagged(versionTags).Gauge(clientGauge).Update(1)
1276+
}
1277+
}
1278+
}()
1279+
})
1280+
}

internal/internal_worker_base.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ func newBaseWorker(options baseWorkerOptions, logger *zap.Logger, metricsScope t
185185
if options.pollerRate > 0 {
186186
bw.pollLimiter = rate.NewLimiter(rate.Limit(options.pollerRate), 1)
187187
}
188-
189188
return bw
190189
}
191190

test/integration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ package test
2424
import (
2525
"context"
2626
"fmt"
27+
"github.com/uber-go/tally"
28+
"go.uber.org/cadence/internal"
2729
"net"
2830
"strings"
2931
"sync"
@@ -109,12 +111,13 @@ func (ts *IntegrationTestSuite) SetupSuite() {
109111
})
110112
ts.domainClient = client.NewDomainClient(ts.rpcClient.Interface, &client.Options{})
111113
ts.registerDomain()
114+
internal.StartVersionMetrics(tally.NoopScope)
112115
}
113116

114117
func (ts *IntegrationTestSuite) TearDownSuite() {
115118
ts.Assertions = require.New(ts.T())
116119
ts.rpcClient.Close()
117-
120+
close(internal.StopMetrics)
118121
// allow the pollers to shut down, and ensure there are no goroutine leaks.
119122
// this will wait for up to 1 minute for leaks to subside, but exit relatively quickly if possible.
120123
max := time.After(time.Minute)

0 commit comments

Comments
 (0)