Skip to content

Commit

Permalink
instrumentation: golangci-lint fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Dec 10, 2024
1 parent 331b1ec commit ac40e1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 8 additions & 6 deletions pkg/instrumentation/instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package instrumentation

import (
"io/ioutil"
"io"
"net/http"
"strings"

"testing"

"github.com/stretchr/testify/require"
)

func TestPrometheusConfiguration(t *testing.T) {
Expand All @@ -29,7 +31,7 @@ func TestPrometheusConfiguration(t *testing.T) {
cfg.HTTPEndpoint = ":0"
}

Start()
require.NoError(t, Start(), "start test server")

address := srv.GetAddress()
if strings.HasSuffix(cfg.HTTPEndpoint, ":0") {
Expand All @@ -40,17 +42,17 @@ func TestPrometheusConfiguration(t *testing.T) {

newCfg := *cfg
newCfg.PrometheusExport = !newCfg.PrometheusExport
Reconfigure(&newCfg)
require.NoError(t, Reconfigure(&newCfg), "reconfigure test server")
checkPrometheus(t, address, !newCfg.PrometheusExport)

newCfg = *cfg
newCfg.PrometheusExport = !newCfg.PrometheusExport
Reconfigure(&newCfg)
require.NoError(t, Reconfigure(&newCfg), "reconfigure test server")
checkPrometheus(t, address, !newCfg.PrometheusExport)

newCfg = *cfg
newCfg.PrometheusExport = !newCfg.PrometheusExport
Reconfigure(&newCfg)
require.NoError(t, Reconfigure(&newCfg), "reconfigure test server")
checkPrometheus(t, address, !newCfg.PrometheusExport)

srv.Shutdown(true)
Expand All @@ -73,7 +75,7 @@ func checkPrometheus(t *testing.T, server string, shouldFail bool) {
return
}

_, err = ioutil.ReadAll(rpl.Body)
_, err = io.ReadAll(rpl.Body)
rpl.Body.Close()
if err != nil {
t.Errorf("failed to read Prometheus response: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/instrumentation/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type (

var (
disabled bool
namespace string
namespace = "nri"
enabled []string
polled []string
reportPeriod time.Duration
Expand Down Expand Up @@ -99,7 +99,7 @@ func Start(m *http.ServeMux, options ...Option) error {
log.Info("starting metrics exporter...")

g, err := metrics.NewGatherer(
metrics.WithNamespace("nri"),
metrics.WithNamespace(namespace),
metrics.WithPollInterval(reportPeriod),
metrics.WithMetrics(enabled, polled),
)
Expand Down
4 changes: 3 additions & 1 deletion pkg/instrumentation/tracing/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (e *spanExporter) Shutdown(ctx context.Context) error {
}

func (e *spanExporter) setEndpoint(endpoint string) error {
e.shutdown()
if err := e.shutdown(); err != nil {
log.Warnf("failed to shutdown tracing exporter: %v", err)
}

if endpoint == "" {
return nil
Expand Down

0 comments on commit ac40e1e

Please sign in to comment.