diff options
author | David Štrop <[email protected]> | 2021-03-20 02:59:33 +0100 |
---|---|---|
committer | David Štrop <[email protected]> | 2021-03-20 02:59:33 +0100 |
commit | c8f3b79de529b85b4910157f2cafbc25349ad8de (patch) | |
tree | 6d3db5c8a3e477420c11b6d8b3cd57c36b652281 /tests | |
parent | bd91ca0f3e444405f0f6cf9d1dabbeef93de2d85 (diff) |
fix(metrics): remove statsProvider from metrics collectors sync.Map
Signed-off-by: David Štrop <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/plugins/metrics/.rr-test.yaml | 3 | ||||
-rw-r--r-- | tests/plugins/metrics/metrics_test.go | 25 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/plugins/metrics/.rr-test.yaml b/tests/plugins/metrics/.rr-test.yaml index bc68b90f..4890076f 100644 --- a/tests/plugins/metrics/.rr-test.yaml +++ b/tests/plugins/metrics/.rr-test.yaml @@ -10,6 +10,9 @@ metrics: help: "Custom application metric" labels: [ "type" ] buckets: [ 0.1, 0.2, 0.3, 1.0 ] + app_metric_counter: + type: counter + help: "Custom application counter." logs: mode: development level: error
\ No newline at end of file diff --git a/tests/plugins/metrics/metrics_test.go b/tests/plugins/metrics/metrics_test.go index b5a4fd4f..d552107e 100644 --- a/tests/plugins/metrics/metrics_test.go +++ b/tests/plugins/metrics/metrics_test.go @@ -83,6 +83,7 @@ func TestMetricsInit(t *testing.T) { assert.NoError(t, err) assert.Contains(t, out, "go_gc_duration_seconds") + assert.Contains(t, out, "app_metric_counter") for { select { @@ -199,6 +200,7 @@ func TestMetricsDifferentRPCCalls(t *testing.T) { mockLogger.EXPECT().Info("adding metric", "name", "sub_gauge_subVector", "value", gomock.Any(), "labels", []string{"core", "first"}).MinTimes(1) mockLogger.EXPECT().Info("adding metric", "name", "sub_gauge_subMetric", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("adding metric", "name", "test_metrics_named_collector", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Info("adding metric", "name", "app_metric_counter", "value", gomock.Any(), "labels", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "observe_observeMetricNotEnoughLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "observe_observeMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) @@ -216,6 +218,7 @@ func TestMetricsDifferentRPCCalls(t *testing.T) { mockLogger.EXPECT().Info("metric successfully added", "name", "test_metrics_named_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "test_metrics_named_collector", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "user_gauge_collector", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Info("metric successfully added", "name", "app_metric_counter", "labels", gomock.Any(), "value", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("declaring new metric", "name", "observe_observeMetricNotEnoughLabels", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("declaring new metric", "name", "observe_observeMetric", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) @@ -361,9 +364,31 @@ func TestMetricsDifferentRPCCalls(t *testing.T) { t.Run("ObserveMetricNotEnoughLabels", observeMetricNotEnoughLabels) + t.Run("ConfiguredCounterMetric", configuredCounterMetric) + genericOut, err = get() + assert.NoError(t, err) + assert.Contains(t, genericOut, "HELP app_metric_counter Custom application counter.") + assert.Contains(t, genericOut, `app_metric_counter 100`) + close(sig) } +func configuredCounterMetric(t *testing.T) { + conn, err := net.Dial(dialNetwork, dialAddr) + assert.NoError(t, err) + defer func() { + _ = conn.Close() + }() + client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)) + var ret bool + + assert.NoError(t, client.Call("metrics.Add", metrics.Metric{ + Name: "app_metric_counter", + Value: 100.0, + }, &ret)) + assert.True(t, ret) +} + func observeMetricNotEnoughLabels(t *testing.T) { conn, err := net.Dial(dialNetwork, dialAddr) assert.NoError(t, err) |