Skip to content

Commit 4944146

Browse files
author
maksim.konovalov
committed
Add replicaset name to metrics
1 parent 094a538 commit 4944146

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ CHANGES:
55
* More strict check of vshard.storage.call response.
66
* Bump go-tarantool from v2.3.0 to v2.3.1.
77
* Get rid of nameToReplicasetMutex, use atomic instead.
8+
* Metrics provider now requires replicaset name.
9+
10+
FEATURES:
11+
* Add replicaset name support for prometheus provider.
812

913
## v2.0.5
1014

api.go

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

278278
for {
279279
if spent := time.Since(requestStartTime); spent > timeout {
280-
r.metrics().RequestDuration(spent, fnc, false, false)
280+
r.metrics().RequestDuration(spent, fnc, "", false, false)
281281

282282
r.log().Debugf(ctx, "Return result on timeout; spent %s of timeout %s", spent, timeout)
283283
if err == nil {
@@ -400,7 +400,7 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
400400
}
401401
}
402402

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

405405
return storageCallResponse.CallResp, nil
406406
}
@@ -674,7 +674,7 @@ func RouterMapCallRW[T any](r *Router, ctx context.Context,
674674
nameToResult[rsFuture.name] = storageMapResponse.value
675675
}
676676

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

679679
return nameToResult, nil
680680
}

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)

0 commit comments

Comments
 (0)