Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instrumentation: golangci-lint fixes. #435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
Loading