diff options
author | Valery Piashchynski <[email protected]> | 2020-11-13 17:36:22 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-11-13 17:36:22 +0300 |
commit | 99b6012400ab407cfcb04aab833640af565d550d (patch) | |
tree | 75a228cf96d90f99e7ee6367c5d7cbb4c465c61d /plugins/metrics | |
parent | 6eefd067f4c08ed51834926abd1a4c60ec55b56d (diff) |
Metrics config test
Config proper parsing
Add metrics tests to the CI and Makefile
Diffstat (limited to 'plugins/metrics')
-rw-r--r-- | plugins/metrics/config.go | 4 | ||||
-rw-r--r-- | plugins/metrics/config_test.go | 52 | ||||
-rw-r--r-- | plugins/metrics/doc.go | 1 | ||||
-rw-r--r-- | plugins/metrics/plugin.go | 45 | ||||
-rw-r--r-- | plugins/metrics/plugin_test.go | 457 | ||||
-rw-r--r-- | plugins/metrics/tests/metrics_test.go | 103 | ||||
-rw-r--r-- | plugins/metrics/tests/plugin1.go | 67 | ||||
-rw-r--r-- | plugins/metrics/tests/plugin2.go | 49 |
8 files changed, 453 insertions, 325 deletions
diff --git a/plugins/metrics/config.go b/plugins/metrics/config.go index a7919654..73fb64ba 100644 --- a/plugins/metrics/config.go +++ b/plugins/metrics/config.go @@ -134,3 +134,7 @@ func (c *Config) getCollectors() (map[string]prometheus.Collector, error) { return collectors, nil } + +func (c *Config) InitDefaults() { + +} diff --git a/plugins/metrics/config_test.go b/plugins/metrics/config_test.go index a64e9047..24c8406c 100644 --- a/plugins/metrics/config_test.go +++ b/plugins/metrics/config_test.go @@ -1,47 +1,54 @@ package metrics import ( + "bytes" + "testing" + json "github.com/json-iterator/go" "github.com/prometheus/client_golang/prometheus" - "github.com/spiral/roadrunner/service" "github.com/stretchr/testify/assert" - "testing" ) -type mockCfg struct{ cfg string } - -func (cfg *mockCfg) Get(name string) service.Config { return nil } -func (cfg *mockCfg) Unmarshal(out interface{}) error { - j := json.ConfigCompatibleWithStandardLibrary - return j.Unmarshal([]byte(cfg.cfg), out) -} - func Test_Config_Hydrate_Error1(t *testing.T) { - cfg := &mockCfg{`{"request": {"From": "Something"}}`} + cfg := `{"request": {"From": "Something"}}` c := &Config{} + f := new(bytes.Buffer) + f.WriteString(cfg) - assert.NoError(t, c.Hydrate(cfg)) + err := json.Unmarshal(f.Bytes(), &c) + if err != nil { + t.Fatal(err) + } } func Test_Config_Hydrate_Error2(t *testing.T) { - cfg := &mockCfg{`{"dir": "/dir/"`} + cfg := `{"dir": "/dir/"` c := &Config{} - assert.Error(t, c.Hydrate(cfg)) + f := new(bytes.Buffer) + f.WriteString(cfg) + + err := json.Unmarshal(f.Bytes(), &c) + assert.Error(t, err) } func Test_Config_Metrics(t *testing.T) { - cfg := &mockCfg{`{ + cfg := `{ "collect":{ "metric1":{"type": "gauge"}, "metric2":{ "type": "counter"}, "metric3":{"type": "summary"}, "metric4":{"type": "histogram"} } -}`} +}` c := &Config{} + f := new(bytes.Buffer) + f.WriteString(cfg) - assert.NoError(t, c.Hydrate(cfg)) + err := json.Unmarshal(f.Bytes(), &c) + if err != nil { + t.Fatal(err) + } m, err := c.getCollectors() assert.NoError(t, err) @@ -53,17 +60,22 @@ func Test_Config_Metrics(t *testing.T) { } func Test_Config_MetricsVector(t *testing.T) { - cfg := &mockCfg{`{ + cfg := `{ "collect":{ "metric1":{"type": "gauge","labels":["label"]}, "metric2":{ "type": "counter","labels":["label"]}, "metric3":{"type": "summary","labels":["label"]}, "metric4":{"type": "histogram","labels":["label"]} } -}`} +}` c := &Config{} + f := new(bytes.Buffer) + f.WriteString(cfg) - assert.NoError(t, c.Hydrate(cfg)) + err := json.Unmarshal(f.Bytes(), &c) + if err != nil { + t.Fatal(err) + } m, err := c.getCollectors() assert.NoError(t, err) diff --git a/plugins/metrics/doc.go b/plugins/metrics/doc.go new file mode 100644 index 00000000..1abe097a --- /dev/null +++ b/plugins/metrics/doc.go @@ -0,0 +1 @@ +package metrics diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index fad8ca80..8e87029a 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -49,58 +49,50 @@ func (m *Plugin) Init(cfg config.Configurer, log log.Logger) error { return err } - //m.cfg.InitDefaults() + // TODO figure out what is Init + m.cfg.InitDefaults() m.log = log m.registry = prometheus.NewRegistry() + // Default err = m.registry.Register(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) if err != nil { return errors.E(op, err) } + + // Default err = m.registry.Register(prometheus.NewGoCollector()) if err != nil { return errors.E(op, err) } - //m.collectors = make([]statsProvider, 0, 2) - - //if r != nil { - // if err := r.Register(ID, &rpcServer{s}); err != nil { - // return false, err - // } - //} + collectors, err := m.cfg.getCollectors() + if err != nil { + return errors.E(op, err) + } + // Register invocation will be later in the Serve method + for k, v := range collectors { + m.collectors.Store(k, statsProvider{ + collector: v, + name: k, + }) + } return nil } -// Enabled indicates that server is able to collect metrics. -//func (m *Plugin) Enabled() bool { -// return m.cfg != nil -//} -// // Register new prometheus collector. func (m *Plugin) Register(c prometheus.Collector) error { return m.registry.Register(c) } -// MustRegister registers new collector or fails with panic. -//func (m *Plugin) MustRegister(c prometheus.Collector) { -// m.registry.MustRegister(c) -//} - // Serve prometheus metrics service. func (m *Plugin) Serve() chan error { errCh := make(chan error, 1) - // register application specific metrics - //collectors, err := m.cfg.getCollectors() - //if err != nil { - // return err - //} - m.collectors.Range(func(key, value interface{}) bool { // key - name - // value - collector + // value - statsProvider struct c := value.(statsProvider) if err := m.registry.Register(c.collector); err != nil { errCh <- err @@ -207,6 +199,7 @@ func (m *Plugin) Stop() error { return nil } +// Collects used to collect all plugins which implement metrics.StatProvider interface (and Named) func (m *Plugin) Collects() []interface{} { return []interface{}{ m.AddStatProvider, @@ -222,10 +215,12 @@ func (m *Plugin) AddStatProvider(name endure.Named, stat metrics.StatProvider) e return nil } +// RPC interface satisfaction func (m *Plugin) Name() string { return ServiceName } +// RPC interface satisfaction func (m *Plugin) RPC() interface{} { return &rpcServer{svc: m} } diff --git a/plugins/metrics/plugin_test.go b/plugins/metrics/plugin_test.go index aa150504..0f0cbfcc 100644 --- a/plugins/metrics/plugin_test.go +++ b/plugins/metrics/plugin_test.go @@ -1,247 +1,214 @@ package metrics -import ( - json "github.com/json-iterator/go" - "github.com/prometheus/client_golang/prometheus" - "github.com/sirupsen/logrus" - "github.com/sirupsen/logrus/hooks/test" - "github.com/spiral/roadrunner/service" - "github.com/spiral/roadrunner/service/rpc" - "github.com/stretchr/testify/assert" - "io/ioutil" - "net/http" - "testing" - "time" -) - -type testCfg struct { - rpcCfg string - metricsCfg string - target string -} - -func (cfg *testCfg) Get(name string) service.Config { - if name == ID { - return &testCfg{target: cfg.metricsCfg} - } - - if name == rpc.ID { - return &testCfg{target: cfg.rpcCfg} - } - - return nil -} - -func (cfg *testCfg) Unmarshal(out interface{}) error { - j := json.ConfigCompatibleWithStandardLibrary - err := j.Unmarshal([]byte(cfg.target), out) - return err -} - -// get request and return body -func get(url string) (string, *http.Response, error) { - r, err := http.Get(url) - if err != nil { - return "", nil, err - } - - b, err := ioutil.ReadAll(r.Body) - if err != nil { - return "", nil, err - } - - err = r.Body.Close() - if err != nil { - return "", nil, err - } - return string(b), r, err -} - -func TestService_Serve(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2116" - }`})) - - s, _ := c.Get(ID) - assert.NotNil(t, s) - - go func() { - err := c.Serve() - if err != nil { - t.Errorf("error during the Serve: error %v", err) - } - }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - - out, _, err := get("http://localhost:2116/metrics") - assert.NoError(t, err) - - assert.Contains(t, out, "go_gc_duration_seconds") -} - -func Test_ServiceCustomMetric(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2115" - }`})) - - s, _ := c.Get(ID) - assert.NotNil(t, s) - - collector := prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "my_gauge", - Help: "My gauge value", - }) - - assert.NoError(t, s.(*Plugin).Register(collector)) - - go func() { - err := c.Serve() - if err != nil { - t.Errorf("error during the Serve: error %v", err) - } - }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - - collector.Set(100) - - out, _, err := get("http://localhost:2115/metrics") - assert.NoError(t, err) - - assert.Contains(t, out, "my_gauge 100") -} - -func Test_ServiceCustomMetricMust(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2114" - }`})) - - s, _ := c.Get(ID) - assert.NotNil(t, s) - - collector := prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "my_gauge_2", - Help: "My gauge value", - }) - - s.(*Plugin).MustRegister(collector) - - go func() { - err := c.Serve() - if err != nil { - t.Errorf("error during the Serve: error %v", err) - } - }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - - collector.Set(100) - - out, _, err := get("http://localhost:2114/metrics") - assert.NoError(t, err) - - assert.Contains(t, out, "my_gauge_2 100") -} - -func Test_ConfiguredMetric(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2113", - "collect":{ - "user_gauge":{ - "type": "gauge" - } - } - }`})) - - s, _ := c.Get(ID) - assert.NotNil(t, s) - - assert.True(t, s.(*Plugin).Enabled()) - - go func() { - err := c.Serve() - if err != nil { - t.Errorf("error during the Serve: error %v", err) - } - }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - - s.(*Plugin).Collector("user_gauge").(prometheus.Gauge).Set(100) - - assert.Nil(t, s.(*Plugin).Collector("invalid")) - - out, _, err := get("http://localhost:2113/metrics") - assert.NoError(t, err) - - assert.Contains(t, out, "user_gauge 100") -} - -func Test_ConfiguredDuplicateMetric(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2112", - "collect":{ - "go_gc_duration_seconds":{ - "type": "gauge" - } - } - }`})) - - s, _ := c.Get(ID) - assert.NotNil(t, s) - - assert.True(t, s.(*Plugin).Enabled()) - - assert.Error(t, c.Serve()) -} - -func Test_ConfiguredInvalidMetric(t *testing.T) { - logger, _ := test.NewNullLogger() - logger.SetLevel(logrus.DebugLevel) - - c := service.NewContainer(logger) - c.Register(ID, &Plugin{}) - - assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ - "address": "localhost:2112", - "collect":{ - "user_gauge":{ - "type": "invalid" - } - } - - }`})) - - assert.Error(t, c.Serve()) -} +//type testCfg struct { +// rpcCfg string +// metricsCfg string +// target string +//} +// +//func (cfg *testCfg) Get(name string) service.Config { +// if name == ID { +// return &testCfg{target: cfg.metricsCfg} +// } +// +// if name == rpc.ID { +// return &testCfg{target: cfg.rpcCfg} +// } +// +// return nil +//} +// +//func (cfg *testCfg) Unmarshal(out interface{}) error { +// j := json.ConfigCompatibleWithStandardLibrary +// err := j.Unmarshal([]byte(cfg.target), out) +// return err +//} +// +//func TestService_Serve(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2116" +// }`})) +// +// s, _ := c.Get(ID) +// assert.NotNil(t, s) +// +// go func() { +// err := c.Serve() +// if err != nil { +// t.Errorf("error during the Serve: error %v", err) +// } +// }() +// time.Sleep(time.Millisecond * 100) +// defer c.Stop() +// +// out, _, err := get("http://localhost:2116/metrics") +// assert.NoError(t, err) +// +// assert.Contains(t, out, "go_gc_duration_seconds") +//} +// +//func Test_ServiceCustomMetric(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2115" +// }`})) +// +// s, _ := c.Get(ID) +// assert.NotNil(t, s) +// +// collector := prometheus.NewGauge(prometheus.GaugeOpts{ +// Name: "my_gauge", +// Help: "My gauge value", +// }) +// +// assert.NoError(t, s.(*Plugin).Register(collector)) +// +// go func() { +// err := c.Serve() +// if err != nil { +// t.Errorf("error during the Serve: error %v", err) +// } +// }() +// time.Sleep(time.Millisecond * 100) +// defer c.Stop() +// +// collector.Set(100) +// +// out, _, err := get("http://localhost:2115/metrics") +// assert.NoError(t, err) +// +// assert.Contains(t, out, "my_gauge 100") +//} +// +//func Test_ServiceCustomMetricMust(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2114" +// }`})) +// +// s, _ := c.Get(ID) +// assert.NotNil(t, s) +// +// collector := prometheus.NewGauge(prometheus.GaugeOpts{ +// Name: "my_gauge_2", +// Help: "My gauge value", +// }) +// +// s.(*Plugin).MustRegister(collector) +// +// go func() { +// err := c.Serve() +// if err != nil { +// t.Errorf("error during the Serve: error %v", err) +// } +// }() +// time.Sleep(time.Millisecond * 100) +// defer c.Stop() +// +// collector.Set(100) +// +// out, _, err := get("http://localhost:2114/metrics") +// assert.NoError(t, err) +// +// assert.Contains(t, out, "my_gauge_2 100") +//} +// +//func Test_ConfiguredMetric(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2113", +// "collect":{ +// "user_gauge":{ +// "type": "gauge" +// } +// } +// }`})) +// +// s, _ := c.Get(ID) +// assert.NotNil(t, s) +// +// assert.True(t, s.(*Plugin).Enabled()) +// +// go func() { +// err := c.Serve() +// if err != nil { +// t.Errorf("error during the Serve: error %v", err) +// } +// }() +// time.Sleep(time.Millisecond * 100) +// defer c.Stop() +// +// s.(*Plugin).Collector("user_gauge").(prometheus.Gauge).Set(100) +// +// assert.Nil(t, s.(*Plugin).Collector("invalid")) +// +// out, _, err := get("http://localhost:2113/metrics") +// assert.NoError(t, err) +// +// assert.Contains(t, out, "user_gauge 100") +//} +// +//func Test_ConfiguredDuplicateMetric(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2112", +// "collect":{ +// "go_gc_duration_seconds":{ +// "type": "gauge" +// } +// } +// }`})) +// +// s, _ := c.Get(ID) +// assert.NotNil(t, s) +// +// assert.True(t, s.(*Plugin).Enabled()) +// +// assert.Error(t, c.Serve()) +//} +// +//func Test_ConfiguredInvalidMetric(t *testing.T) { +// logger, _ := test.NewNullLogger() +// logger.SetLevel(logrus.DebugLevel) +// +// c := service.NewContainer(logger) +// c.Register(ID, &Plugin{}) +// +// assert.NoError(t, c.Init(&testCfg{metricsCfg: `{ +// "address": "localhost:2112", +// "collect":{ +// "user_gauge":{ +// "type": "invalid" +// } +// } +// +// }`})) +// +// assert.Error(t, c.Serve()) +//} diff --git a/plugins/metrics/tests/metrics_test.go b/plugins/metrics/tests/metrics_test.go index f21016d4..2900c38f 100644 --- a/plugins/metrics/tests/metrics_test.go +++ b/plugins/metrics/tests/metrics_test.go @@ -1,6 +1,8 @@ package tests import ( + "io/ioutil" + "net/http" "os" "os/signal" "syscall" @@ -15,6 +17,26 @@ import ( "github.com/stretchr/testify/assert" ) +// get request and return body +func get(url string) (string, *http.Response, error) { + r, err := http.Get(url) + if err != nil { + return "", nil, err + } + + b, err := ioutil.ReadAll(r.Body) + if err != nil { + return "", nil, err + } + + err = r.Body.Close() + if err != nil { + return "", nil, err + } + // unsafe + return string(b), r, err +} + func TestMetricsInit(t *testing.T) { cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel)) if err != nil { @@ -62,6 +84,87 @@ func TestMetricsInit(t *testing.T) { tt := time.NewTimer(time.Second * 5) + out, _, err := get("http://localhost:2112/metrics") + assert.NoError(t, err) + + assert.Contains(t, out, "go_gc_duration_seconds") + + for { + select { + case e := <-ch: + assert.Fail(t, "error", e.Error.Error()) + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + case <-sig: + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + case <-tt.C: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + } + } +} + +func TestMetricsGaugeCollector(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, "")) + if err != nil { + t.Fatal(err) + } + + cfg := &config.Viper{} + cfg.Prefix = "rr" + cfg.Path = ".rr-test.yaml" + + err = cont.Register(cfg) + if err != nil { + t.Fatal(err) + } + + err = cont.Register(&metrics.Plugin{}) + if err != nil { + t.Fatal(err) + } + + err = cont.Register(&rpc.Plugin{}) + if err != nil { + t.Fatal(err) + } + + err = cont.Register(&logger.ZapLogger{}) + if err != nil { + t.Fatal(err) + } + err = cont.Register(&Plugin1{}) + if err != nil { + t.Fatal(err) + } + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + time.Sleep(time.Second) + tt := time.NewTimer(time.Second * 5) + + out, _, err := get("http://localhost:2112/metrics") + assert.Contains(t, out, "my_gauge 100") + for { select { case e := <-ch: diff --git a/plugins/metrics/tests/plugin1.go b/plugins/metrics/tests/plugin1.go index fdf10e54..cac41c82 100644 --- a/plugins/metrics/tests/plugin1.go +++ b/plugins/metrics/tests/plugin1.go @@ -1,12 +1,11 @@ package tests import ( - "fmt" - "github.com/prometheus/client_golang/prometheus" "github.com/spiral/roadrunner/v2/plugins/config" ) +// Gauge ////////////// type Plugin1 struct { config config.Configurer } @@ -30,6 +29,39 @@ func (p1 *Plugin1) Name() string { } func (p1 *Plugin1) MetricsCollector() prometheus.Collector { + collector := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "my_gauge", + Help: "My gauge value", + }) + + collector.Set(100) + return collector +} + +//////////////////////////////////////////////////////////////// +type Plugin3 struct { + config config.Configurer +} + +func (p *Plugin3) Init(cfg config.Configurer) error { + p.config = cfg + return nil +} + +func (p *Plugin3) Serve() chan error { + errCh := make(chan error, 1) + return errCh +} + +func (p *Plugin3) Stop() error { + return nil +} + +func (p *Plugin3) Name() string { + return "metrics_test.plugin1" +} + +func (p *Plugin3) MetricsCollector() prometheus.Collector { var ( cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "cpu_temperature_celsius", @@ -39,11 +71,34 @@ func (p1 *Plugin1) MetricsCollector() prometheus.Collector { return cpuTemp } -type PluginRpc struct { - srv *Plugin1 +type Plugin4 struct { + config config.Configurer +} + +func (p *Plugin4) Init(cfg config.Configurer) error { + p.config = cfg + return nil +} + +func (p *Plugin4) Serve() chan error { + errCh := make(chan error, 1) + return errCh } -func (r *PluginRpc) Hello(in string, out *string) error { - *out = fmt.Sprintf("Hello, username: %s", in) +func (p *Plugin4) Stop() error { return nil } + +func (p *Plugin4) Name() string { + return "metrics_test.plugin1" +} + +func (p *Plugin4) MetricsCollector() prometheus.Collector { + var ( + cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "cpu_temperature_celsius", + Help: "Current temperature of the CPU.", + }) + ) + return cpuTemp +} diff --git a/plugins/metrics/tests/plugin2.go b/plugins/metrics/tests/plugin2.go index 4156db6d..4369971b 100644 --- a/plugins/metrics/tests/plugin2.go +++ b/plugins/metrics/tests/plugin2.go @@ -1,14 +1,5 @@ package tests -import ( - "net" - "net/rpc" - "time" - - "github.com/spiral/errors" - "github.com/spiral/goridge/v2" -) - // plugin2 makes a call to the plugin1 via RPC // this is just a simulation of external call FOR TEST // you don't need to do such things :) @@ -23,26 +14,26 @@ func (p2 *Plugin2) Serve() chan error { errCh := make(chan error, 1) go func() { - time.Sleep(time.Second * 3) - - conn, err := net.Dial("tcp", "127.0.0.1:7001") - if err != nil { - errCh <- errors.E(errors.Serve, err) - return - } - client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn)) - var ret string - err = client.Call("metrics_test.plugin1.Hello", "Valery", &ret) - if err != nil { - errCh <- err - return - } - if ret != "Hello, username: Valery" { - errCh <- errors.E("wrong response") - return - } - // to stop exec - errCh <- errors.E(errors.Disabled) + //time.Sleep(time.Second * 3) + // + //conn, err := net.Dial("tcp", "127.0.0.1:6001") + //if err != nil { + // errCh <- errors.E(errors.Serve, err) + // return + //} + //client := rpc.NewClientWithCodec(goridge.NewClientCodec(conn)) + //var ret string + //err = client.Call("metrics_test.plugin1.Hello", "Valery", &ret) + //if err != nil { + // errCh <- err + // return + //} + //if ret != "Hello, username: Valery" { + // errCh <- errors.E("wrong response") + // return + //} + //// to stop exec + //errCh <- errors.E(errors.Disabled) return }() |