summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-13 17:43:20 +0300
committerValery Piashchynski <[email protected]>2020-11-13 17:43:20 +0300
commit9fd0b28d3a6a60b5e08af03bd86bcef042152e1c (patch)
tree2e925c736eb8cf3b27995db0882d06557432925f
parent99b6012400ab407cfcb04aab833640af565d550d (diff)
golangci linters warnings fix
-rw-r--r--Makefile2
-rw-r--r--plugins/metrics/config.go5
-rw-r--r--plugins/metrics/plugin.go2
-rw-r--r--plugins/metrics/rpc.go27
-rw-r--r--plugins/metrics/tests/metrics_test.go15
-rw-r--r--plugins/metrics/tests/plugin1.go4
-rwxr-xr-xstatic_pool.go11
7 files changed, 15 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index 981b50b3..08627760 100644
--- a/Makefile
+++ b/Makefile
@@ -5,4 +5,4 @@ test:
go test -v -race -cover ./plugins/config/tests -tags=debug
go test -v -race -cover ./plugins/app/tests -tags=debug
go test -v -race -cover ./plugins/logger/tests -tags=debug
- go test -v -race ./plugins/metrics/tests -tags=debug \ No newline at end of file
+ go test -v -race -cover ./plugins/metrics/tests -tags=debug \ No newline at end of file
diff --git a/plugins/metrics/config.go b/plugins/metrics/config.go
index 73fb64ba..933b7eb8 100644
--- a/plugins/metrics/config.go
+++ b/plugins/metrics/config.go
@@ -56,11 +56,6 @@ type Collector struct {
Buckets []float64 `json:"buckets"`
}
-// Hydrate configuration.
-//func (c *Config) Hydrate(cfg service.Config) error {
-// return cfg.Unmarshal(c)
-//}
-
// register application specific metrics.
func (c *Config) getCollectors() (map[string]prometheus.Collector, error) {
if c.Collect == nil {
diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go
index 8e87029a..ff075bc6 100644
--- a/plugins/metrics/plugin.go
+++ b/plugins/metrics/plugin.go
@@ -37,7 +37,7 @@ type Plugin struct {
log log.Logger
mu sync.Mutex // all receivers are pointers
http *http.Server
- collectors sync.Map //[]statsProvider
+ collectors sync.Map // all receivers are pointers
registry *prometheus.Registry
}
diff --git a/plugins/metrics/rpc.go b/plugins/metrics/rpc.go
index a5be2204..9799db3f 100644
--- a/plugins/metrics/rpc.go
+++ b/plugins/metrics/rpc.go
@@ -24,12 +24,6 @@ type Metric struct {
// Add new metric to the designated collector.
func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
const op = errors.Op("Add metric")
- //defer func() {
- // if r, fail := recover().(error); fail {
- // err = r
- // }
- //}()
-
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
return errors.E(op, errors.Errorf("undefined collector `%s`", m.Name))
@@ -68,12 +62,6 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
// Sub subtract the value from the specific metric (gauge only).
func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
const op = errors.Op("Sub metric")
- //defer func() {
- // if r, fail := recover().(error); fail {
- // err = r
- // }
- //}()
-
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
return errors.E(op, errors.Errorf("undefined collector `%s`", m.Name))
@@ -105,12 +93,6 @@ func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
// Observe the value (histogram and summary only).
func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
const op = errors.Op("Observe metrics")
- //defer func() {
- // if r, fail := recover().(error); fail {
- // err = r
- // }
- //}()
-
c, exist := rpc.svc.collectors.Load(m.Name)
if !exist {
return errors.E(op, errors.Errorf("undefined collector `%s`", m.Name))
@@ -153,14 +135,6 @@ func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
// error
func (rpc *rpcServer) Declare(nc *NamedCollector, ok *bool) error {
const op = errors.Op("Declare metric")
- // MustRegister could panic, so, to return error and not shutdown whole app
- // we recover and return error
- //defer func() {
- // if r, fail := recover().(error); fail {
- // err = r
- // }
- //}()
-
_, exist := rpc.svc.collectors.Load(nc.Name)
if exist {
return errors.E(op, errors.Errorf("tried to register existing collector with the name `%s`", nc.Name))
@@ -224,7 +198,6 @@ func (rpc *rpcServer) Declare(nc *NamedCollector, ok *bool) error {
default:
return errors.E(op, errors.Errorf("unknown collector type `%s`", nc.Type))
-
}
// add collector to sync.Map
diff --git a/plugins/metrics/tests/metrics_test.go b/plugins/metrics/tests/metrics_test.go
index 2900c38f..2df011e6 100644
--- a/plugins/metrics/tests/metrics_test.go
+++ b/plugins/metrics/tests/metrics_test.go
@@ -18,23 +18,23 @@ import (
)
// get request and return body
-func get(url string) (string, *http.Response, error) {
+func get(url string) (string, error) {
r, err := http.Get(url)
if err != nil {
- return "", nil, err
+ return "", err
}
b, err := ioutil.ReadAll(r.Body)
if err != nil {
- return "", nil, err
+ return "", err
}
err = r.Body.Close()
if err != nil {
- return "", nil, err
+ return "", err
}
// unsafe
- return string(b), r, err
+ return string(b), err
}
func TestMetricsInit(t *testing.T) {
@@ -84,7 +84,7 @@ func TestMetricsInit(t *testing.T) {
tt := time.NewTimer(time.Second * 5)
- out, _, err := get("http://localhost:2112/metrics")
+ out, err := get("http://localhost:2112/metrics")
assert.NoError(t, err)
assert.Contains(t, out, "go_gc_duration_seconds")
@@ -162,7 +162,8 @@ func TestMetricsGaugeCollector(t *testing.T) {
time.Sleep(time.Second)
tt := time.NewTimer(time.Second * 5)
- out, _, err := get("http://localhost:2112/metrics")
+ out, err := get("http://localhost:2112/metrics")
+ assert.NoError(t, err)
assert.Contains(t, out, "my_gauge 100")
for {
diff --git a/plugins/metrics/tests/plugin1.go b/plugins/metrics/tests/plugin1.go
index cac41c82..345a3ec6 100644
--- a/plugins/metrics/tests/plugin1.go
+++ b/plugins/metrics/tests/plugin1.go
@@ -58,7 +58,7 @@ func (p *Plugin3) Stop() error {
}
func (p *Plugin3) Name() string {
- return "metrics_test.plugin1"
+ return "metrics_test.plugin3"
}
func (p *Plugin3) MetricsCollector() prometheus.Collector {
@@ -90,7 +90,7 @@ func (p *Plugin4) Stop() error {
}
func (p *Plugin4) Name() string {
- return "metrics_test.plugin1"
+ return "metrics_test.plugin4"
}
func (p *Plugin4) MetricsCollector() prometheus.Collector {
diff --git a/static_pool.go b/static_pool.go
index 2d23f518..0e5ee050 100755
--- a/static_pool.go
+++ b/static_pool.go
@@ -70,12 +70,7 @@ func NewPool(ctx context.Context, cmd func() *exec.Cmd, factory Factory, cfg Con
before: make([]Before, 0, 0),
}
- var err error
- p.allocator, err = newPoolAllocator(factory, cmd)
- if err != nil {
- return nil, errors.E(op, err)
- }
-
+ p.allocator = newPoolAllocator(factory, cmd)
p.ww = newWorkerWatcher(p.allocator, p.cfg.NumWorkers, p.events)
workers, err := p.allocateWorkers(ctx, p.cfg.NumWorkers)
@@ -279,7 +274,7 @@ func defaultErrEncoder(sp *StaticPool) ErrorEncoder {
}
}
-func newPoolAllocator(factory Factory, cmd func() *exec.Cmd) (Allocator, error) {
+func newPoolAllocator(factory Factory, cmd func() *exec.Cmd) Allocator {
return func() (WorkerBase, error) {
w, err := factory.SpawnWorkerWithContext(bCtx, cmd())
if err != nil {
@@ -291,7 +286,7 @@ func newPoolAllocator(factory Factory, cmd func() *exec.Cmd) (Allocator, error)
return nil, err
}
return sw, nil
- }, nil
+ }
}
func (sp *StaticPool) execDebug(p Payload) (Payload, error) {