From 39a2eac13074a209d17f03930223542ff0af8766 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Thu, 27 Jun 2019 14:42:39 +0300 Subject: more tests --- service/metrics/rpc.go | 21 ++------------------- service/metrics/rpc_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'service/metrics') diff --git a/service/metrics/rpc.go b/service/metrics/rpc.go index ca99d4ac..ee8ef984 100644 --- a/service/metrics/rpc.go +++ b/service/metrics/rpc.go @@ -53,25 +53,8 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) (err error) { c.(*prometheus.CounterVec).WithLabelValues(m.Labels...).Add(m.Value) - case prometheus.Summary: - c.(prometheus.Counter).Add(m.Value) - - case *prometheus.SummaryVec: - if len(m.Labels) == 0 { - return fmt.Errorf("required labels for collector `%s`", m.Name) - } - - c.(*prometheus.SummaryVec).WithLabelValues(m.Labels...).Observe(m.Value) - - case prometheus.Histogram: - c.(prometheus.Histogram).Observe(m.Value) - - case *prometheus.HistogramVec: - if len(m.Labels) == 0 { - return fmt.Errorf("required labels for collector `%s`", m.Name) - } - - c.(*prometheus.HistogramVec).WithLabelValues(m.Labels...).Observe(m.Value) + default: + return fmt.Errorf("collector `%s` does not support method `Add`", m.Name) } *ok = true diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go index da991b34..74b067c5 100644 --- a/service/metrics/rpc_test.go +++ b/service/metrics/rpc_test.go @@ -616,3 +616,20 @@ func Test_Add_RPC_MetricError_2(t *testing.T) { Value: 100.0, }, &ok)) } + +func Test_Add_RPC_MetricError_3(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "histogram", + "labels": ["type", "section"] + }`, + ) + defer c.Stop() + + var ok bool + assert.Error(t, client.Call("metrics.Add", Metric{ + Name: "user_gauge", + Value: 100.0, + }, &ok)) +} -- cgit v1.2.3