summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-27 14:10:00 +0300
committerWolfy-J <[email protected]>2019-06-27 14:10:00 +0300
commit3a0b68638e54caeedaed5d0b3a7f4be0fac3c8c2 (patch)
treed4ac4db397e43eb03aca79cbaf6a24fbcb993da8 /service
parent0ffb62f682721637370f2c9f0e5480a69eb5dc4b (diff)
more tests
Diffstat (limited to 'service')
-rw-r--r--service/metrics/rpc_test.go228
1 files changed, 228 insertions, 0 deletions
diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go
index e50b8cf6..ee9b142f 100644
--- a/service/metrics/rpc_test.go
+++ b/service/metrics/rpc_test.go
@@ -463,3 +463,231 @@ func Test_Observe_RPC_MetricError_2(t *testing.T) {
Value: 100.0,
}, &ok))
}
+
+// -- observe summary
+
+func Test_Observe2_RPC(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rpc.ID, &rpc.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`,
+ metricsCfg: `{
+ "address": "localhost:2112",
+ "collect":{
+ "user_histogram":{
+ "type": "summary"
+ }
+ }
+
+ }`}))
+
+ s, _ := c.Get(ID)
+ assert.NotNil(t, s)
+
+ s2, _ := c.Get(rpc.ID)
+ rs := s2.(*rpc.Service)
+
+ assert.True(t, s.(*Service).Enabled())
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ client, err := rs.Client()
+ assert.NoError(t, err)
+
+ var ok bool
+ assert.NoError(t, client.Call("metrics.Observe", Metric{
+ Name: "user_histogram",
+ Value: 100.0,
+ }, &ok))
+ assert.True(t, ok)
+
+ out, _, err := get("http://localhost:2112/metrics")
+ assert.NoError(t, err)
+ assert.Contains(t, out, `user_histogram`)
+}
+
+func Test_Observe2_RPC_Vector(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rpc.ID, &rpc.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`,
+ metricsCfg: `{
+ "address": "localhost:2112",
+ "collect":{
+ "user_histogram":{
+ "type": "summary",
+ "labels": ["type", "section"]
+ }
+ }
+
+ }`}))
+
+ s, _ := c.Get(ID)
+ assert.NotNil(t, s)
+
+ s2, _ := c.Get(rpc.ID)
+ rs := s2.(*rpc.Service)
+
+ assert.True(t, s.(*Service).Enabled())
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ client, err := rs.Client()
+ assert.NoError(t, err)
+
+ var ok bool
+ assert.NoError(t, client.Call("metrics.Observe", Metric{
+ Name: "user_histogram",
+ Value: 100.0,
+ Labels: []string{"core", "first"},
+ }, &ok))
+ assert.True(t, ok)
+
+ out, _, err := get("http://localhost:2112/metrics")
+ assert.NoError(t, err)
+ assert.Contains(t, out, `user_histogram`)
+}
+
+func Test_Observe2_RPC_CollectorError(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rpc.ID, &rpc.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`,
+ metricsCfg: `{
+ "address": "localhost:2112",
+ "collect":{
+ "user_histogram":{
+ "type": "summary",
+ "labels": ["type", "section"]
+ }
+ }
+ }`}))
+
+ s, _ := c.Get(ID)
+ assert.NotNil(t, s)
+
+ s2, _ := c.Get(rpc.ID)
+ rs := s2.(*rpc.Service)
+
+ assert.True(t, s.(*Service).Enabled())
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ client, err := rs.Client()
+ assert.NoError(t, err)
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Observe", Metric{
+ Name: "user_histogram",
+ Value: 100.0,
+ Labels: []string{"missing"},
+ }, &ok))
+}
+
+func Test_Observe2_RPC_MetricError(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rpc.ID, &rpc.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`,
+ metricsCfg: `{
+ "address": "localhost:2112",
+ "collect":{
+ "user_histogram":{
+ "type": "summary",
+ "labels": ["type", "section"]
+ }
+ }
+
+ }`}))
+
+ s, _ := c.Get(ID)
+ assert.NotNil(t, s)
+
+ s2, _ := c.Get(rpc.ID)
+ rs := s2.(*rpc.Service)
+
+ assert.True(t, s.(*Service).Enabled())
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ client, err := rs.Client()
+ assert.NoError(t, err)
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Observe", Metric{
+ Name: "user_histogram",
+ Value: 100.0,
+ Labels: []string{"missing"},
+ }, &ok))
+}
+
+func Test_Observe2_RPC_MetricError_2(t *testing.T) {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rpc.ID, &rpc.Service{})
+ c.Register(ID, &Service{})
+
+ assert.NoError(t, c.Init(&testCfg{
+ rpcCfg: `{"enable":true, "listen":"tcp://:5004"}`,
+ metricsCfg: `{
+ "address": "localhost:2112",
+ "collect":{
+ "user_histogram":{
+ "type": "summary",
+ "labels": ["type", "section"]
+ }
+ }
+
+ }`}))
+
+ s, _ := c.Get(ID)
+ assert.NotNil(t, s)
+
+ s2, _ := c.Get(rpc.ID)
+ rs := s2.(*rpc.Service)
+
+ assert.True(t, s.(*Service).Enabled())
+
+ go func() { c.Serve() }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
+
+ client, err := rs.Client()
+ assert.NoError(t, err)
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Observe", Metric{
+ Name: "user_histogram",
+ Value: 100.0,
+ }, &ok))
+}