Skip to content

Commit b603439

Browse files
author
maksim.konovalov
committed
Add replicaset name to metrics
1 parent 084a0d8 commit b603439

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CHANGES:
66
* Bump go-tarantool from v2.3.0 to v2.3.1.
77
* Get rid of nameToReplicasetMutex, use atomic instead.
88
* Add configurable pause before retrying r.Route in Router.Call method.
9+
* Metrics provider now requires replicaset name.
10+
11+
FEATURES:
12+
* Add replicaset name support for prometheus provider.
913

1014
## v2.0.5
1115

api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
281281

282282
for {
283283
if spent := time.Since(requestStartTime); spent > timeout {
284-
r.metrics().RequestDuration(spent, fnc, false, false)
284+
r.metrics().RequestDuration(spent, fnc, "", false, false)
285285

286286
r.log().Debugf(ctx, "Return result on timeout; spent %s of timeout %s", spent, timeout)
287287
if err == nil {
@@ -407,7 +407,7 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
407407
}
408408
}
409409

410-
r.metrics().RequestDuration(time.Since(requestStartTime), fnc, true, false)
410+
r.metrics().RequestDuration(time.Since(requestStartTime), fnc, rs.info.Name, true, false)
411411

412412
return storageCallResponse.CallResp, nil
413413
}
@@ -681,7 +681,7 @@ func RouterMapCallRW[T any](r *Router, ctx context.Context,
681681
nameToResult[rsFuture.name] = storageMapResponse.value
682682
}
683683

684-
r.metrics().RequestDuration(time.Since(timeStart), fnc, true, true)
684+
r.metrics().RequestDuration(time.Since(timeStart), fnc, "all", true, true)
685685

686686
return nameToResult, nil
687687
}

providers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ func (s StdoutLoggerf) Errorf(_ context.Context, format string, v ...any) {
9191
type MetricsProvider interface {
9292
CronDiscoveryEvent(ok bool, duration time.Duration, reason string)
9393
RetryOnCall(reason string)
94-
RequestDuration(duration time.Duration, procedure string, ok, mapReduce bool)
94+
RequestDuration(duration time.Duration, procedure, rsName string, ok, mapReduce bool)
9595
}
9696

9797
// EmptyMetrics is default empty metrics provider
9898
// you can embed this type and realize just some metrics
9999
type EmptyMetrics struct{}
100100

101-
func (e *EmptyMetrics) CronDiscoveryEvent(_ bool, _ time.Duration, _ string) {}
102-
func (e *EmptyMetrics) RetryOnCall(_ string) {}
103-
func (e *EmptyMetrics) RequestDuration(_ time.Duration, _ string, _, _ bool) {}
101+
func (e *EmptyMetrics) CronDiscoveryEvent(_ bool, _ time.Duration, _ string) {}
102+
func (e *EmptyMetrics) RetryOnCall(_ string) {}
103+
func (e *EmptyMetrics) RequestDuration(_ time.Duration, _, _ string, _, _ bool) {}
104104

105105
// TopologyProvider is external module that can lookup current topology of cluster
106106
// it might be etcd/config/consul or smth else

providers/prometheus/prometheus.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ func (pp *Provider) RetryOnCall(reason string) {
5555
}
5656

5757
// RequestDuration records the duration of a request with labels for success and map-reduce usage.
58-
func (pp *Provider) RequestDuration(duration time.Duration, procedure string, ok, mapReduce bool) {
58+
func (pp *Provider) RequestDuration(duration time.Duration, procedure, rsName string, ok, mapReduce bool) {
5959
pp.requestDuration.With(prometheus.Labels{
6060
"ok": strconv.FormatBool(ok),
6161
"map_reduce": strconv.FormatBool(mapReduce),
6262
"procedure": procedure,
63+
"replicaset": rsName,
6364
}).Observe(float64(duration.Milliseconds()))
6465
}
6566

@@ -98,6 +99,6 @@ func NewPrometheusProvider() *Provider {
9899
requestDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
99100
Name: "request_duration",
100101
Namespace: "vshard",
101-
}, []string{"procedure", "ok", "map_reduce"}), // Histogram for request durations
102+
}, []string{"procedure", "ok", "map_reduce", "replicaset"}), // Histogram for request durations
102103
}
103104
}

providers/prometheus/prometheus_example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func ExampleNewPrometheusProvider() {
3535

3636
provider.CronDiscoveryEvent(true, 150*time.Millisecond, "success")
3737
provider.RetryOnCall("timeout")
38-
provider.RequestDuration(200*time.Millisecond, "test", true, false)
38+
provider.RequestDuration(200*time.Millisecond, "test", "test-rs", true, false)
3939

4040
resp, err := http.Get(server.URL + "/metrics")
4141
if err != nil {

providers/prometheus/prometheus_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestPrometheusMetricsServer(t *testing.T) {
2323

2424
provider.CronDiscoveryEvent(true, 150*time.Millisecond, "success")
2525
provider.RetryOnCall("timeout")
26-
provider.RequestDuration(200*time.Millisecond, "test", true, false)
26+
provider.RequestDuration(200*time.Millisecond, "test", "test-rs", true, false)
2727

2828
resp, err := http.Get(server.URL + "/metrics")
2929
require.NoError(t, err)

providers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestEmptyMetrics_RetryOnCall(t *testing.T) {
2323

2424
func TestEmptyMetrics_RequestDuration(t *testing.T) {
2525
require.NotPanics(t, func() {
26-
emptyMetrics.RequestDuration(time.Second, "test", false, false)
26+
emptyMetrics.RequestDuration(time.Second, "test", "test-rs", false, false)
2727
})
2828
}
2929

0 commit comments

Comments
 (0)