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

Promtil: Fix a panic when using the loki push api target. #5761

Merged
merged 1 commit into from
Apr 4, 2022
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
7 changes: 3 additions & 4 deletions clients/pkg/promtail/targets/lokipush/pushtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ type PushTarget struct {
relabelConfig []*relabel.Config
jobName string
server *server.Server
registerer prometheus.Registerer
}

func NewPushTarget(logger log.Logger,
handler api.EntryHandler,
relabel []*relabel.Config,
jobName string,
config *scrapeconfig.PushTargetConfig,
reg prometheus.Registerer,
) (*PushTarget, error) {

pt := &PushTarget{
Expand All @@ -54,7 +52,6 @@ func NewPushTarget(logger log.Logger,
relabelConfig: relabel,
jobName: jobName,
config: config,
registerer: reg,
}

// Bit of a chicken and egg problem trying to register the defaults and apply overrides from the loaded config.
Expand Down Expand Up @@ -92,7 +89,9 @@ func (t *PushTarget) run() error {
// We don't want the /debug and /metrics endpoints running
t.config.Server.RegisterInstrumentation = false

util_log.InitLogger(&t.config.Server, t.registerer)
// The logger registers a metric which will cause a duplicate registry panic unless we provide an empty registry
// The metric created is for counting log lines and isn't likely to be missed.
util_log.InitLogger(&t.config.Server, prometheus.NewRegistry())

srv, err := server.New(t.config.Server)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/promtail/targets/lokipush/pushtarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestLokiPushTarget(t *testing.T) {
},
}

pt, err := NewPushTarget(logger, eh, rlbl, "job1", config, nil)
pt, err := NewPushTarget(logger, eh, rlbl, "job1", config)
require.NoError(t, err)

// Build a client to send logs
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestPlaintextPushTarget(t *testing.T) {
KeepTimestamp: true,
}

pt, err := NewPushTarget(logger, eh, []*relabel.Config{}, "job2", config, nil)
pt, err := NewPushTarget(logger, eh, []*relabel.Config{}, "job2", config)
require.NoError(t, err)

// Send some logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewPushTargetManager(
return nil, err
}

t, err := NewPushTarget(logger, pipeline.Wrap(client), cfg.RelabelConfigs, cfg.JobName, cfg.PushConfig, reg)
t, err := NewPushTarget(logger, pipeline.Wrap(client), cfg.RelabelConfigs, cfg.JobName, cfg.PushConfig)
if err != nil {
return nil, err
}
Expand Down