Skip to content

Commit

Permalink
Replace go-kit with slog in scrape manager calls
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Silva Sens <[email protected]>
  • Loading branch information
ArthurSens committed Jan 10, 2025
1 parent bd40d67 commit 54dfbcc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions receiver/prometheusreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
go.opentelemetry.io/collector/semconv v0.117.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
go.uber.org/zap/exp v0.3.0
google.golang.org/protobuf v1.36.2
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
2 changes: 2 additions & 0 deletions receiver/prometheusreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions receiver/prometheusreceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"reflect"
"regexp"
"sync"
"time"
"unsafe"

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
commonconfig "github.com/prometheus/common/config"
promconfig "github.com/prometheus/prometheus/config"
Expand All @@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.uber.org/zap"
"go.uber.org/zap/exp/zapslog"

Check failure on line 27 in receiver/prometheusreceiver/metrics_receiver.go

View workflow job for this annotation

GitHub Actions / govulncheck (receiver-3)

could not import go.uber.org/zap/exp/zapslog (invalid package name: "")

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/targetallocator"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (r *pReceiver) Start(ctx context.Context, host component.Host) error {
discoveryCtx, cancel := context.WithCancel(context.Background())
r.cancelFunc = cancel

logger := internal.NewZapToGokitLogAdapter(r.settings.Logger)
logger := slog.New(zapslog.NewHandler(r.settings.Logger.Core()))

err := r.initPrometheusComponents(discoveryCtx, logger, host)
if err != nil {
Expand All @@ -98,7 +99,7 @@ func (r *pReceiver) Start(ctx context.Context, host component.Host) error {
return nil
}

func (r *pReceiver) initPrometheusComponents(ctx context.Context, logger log.Logger, host component.Host) error {
func (r *pReceiver) initPrometheusComponents(ctx context.Context, logger *slog.Logger, host component.Host) error {
// Some SD mechanisms use the "refresh" package, which has its own metrics.
refreshSdMetrics := discovery.NewRefreshMetrics(r.registerer)

Expand Down
4 changes: 2 additions & 2 deletions receiver/prometheusreceiver/targetallocator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"testing"
"time"

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
promconfig "github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery"
promHTTP "github.com/prometheus/prometheus/discovery/http"
Expand Down Expand Up @@ -930,7 +930,7 @@ func TestManagerSyncWithInitialScrapeConfigs(t *testing.T) {
}

func initPrometheusManagers(ctx context.Context, t *testing.T) (*scrape.Manager, *discovery.Manager) {
logger := log.NewNopLogger()
logger := promslog.NewNopLogger()
reg := prometheus.NewRegistry()
sdMetrics, err := discovery.RegisterSDMetrics(reg, discovery.NewRefreshMetrics(reg))
require.NoError(t, err)
Expand Down

0 comments on commit 54dfbcc

Please sign in to comment.