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

Fix duplicate registry.MustRegister call in Promtail Kafka #4866

Merged
merged 2 commits into from
Dec 3, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

* [4865](https://github.com/grafana/loki/pull/4865) **taisho6339**: Fix duplicate registry.MustRegister call in Promtail Kafka
* [4845](https://github.com/grafana/loki/pull/4845) **chaudum** Return error responses consistently as JSON
* [4826](https://github.com/grafana/loki/pull/4826) **cyriltovena**: Adds the ability to hedge storage requests.
* [4828](https://github.com/grafana/loki/pull/4282) **chaudum**: Set correct `Content-Type` header in query response
Expand Down
30 changes: 15 additions & 15 deletions clients/pkg/promtail/targets/kafka/target_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"github.com/Shopify/sarama"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"

"github.com/grafana/loki/clients/pkg/logentry/stages"
"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig"
"github.com/grafana/loki/clients/pkg/promtail/targets/target"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"

"github.com/grafana/loki/pkg/util"
)
Expand All @@ -28,10 +29,11 @@ type TopicManager interface {
}

type TargetSyncer struct {
logger log.Logger
cfg scrapeconfig.Config
reg prometheus.Registerer
client api.EntryHandler
logger log.Logger
cfg scrapeconfig.Config
pipeline *stages.Pipeline
reg prometheus.Registerer
client api.EntryHandler

topicManager TopicManager
consumer
Expand Down Expand Up @@ -86,8 +88,11 @@ func NewSyncer(
if err != nil {
return nil, fmt.Errorf("error creating topic manager: %w", err)
}
pipeline, err := stages.NewPipeline(log.With(logger, "component", "kafka_pipeline"), cfg.PipelineStages, &cfg.JobName, reg)
if err != nil {
return nil, fmt.Errorf("error creating pipeline: %w", err)
}
ctx, cancel := context.WithCancel(context.Background())

t := &TargetSyncer{
logger: logger,
ctx: ctx,
Expand All @@ -96,6 +101,7 @@ func NewSyncer(
cfg: cfg,
reg: reg,
client: pushClient,
pipeline: pipeline,
close: func() error {
if err := group.Close(); err != nil {
level.Warn(logger).Log("msg", "error while closing consumer group", "err", err)
Expand Down Expand Up @@ -280,19 +286,13 @@ func (ts *TargetSyncer) NewTarget(session sarama.ConsumerGroupSession, claim sar
},
}, nil
}

pipeline, err := stages.NewPipeline(log.With(ts.logger, "component", "kafka_pipeline"), ts.cfg.PipelineStages, &ts.cfg.JobName, ts.reg)
if err != nil {
return nil, err
}

t := NewTarget(
session,
claim,
discoveredLabels,
labelOut,
ts.cfg.RelabelConfigs,
pipeline.Wrap(ts.client),
ts.pipeline.Wrap(ts.client),
ts.cfg.KafkaConfig.UseIncomingTimestamp,
)

Expand Down
10 changes: 8 additions & 2 deletions clients/pkg/promtail/targets/kafka/target_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
"testing"
"time"

"github.com/grafana/loki/clients/pkg/logentry/stages"

"github.com/grafana/dskit/flagext"
"github.com/prometheus/common/config"

"github.com/Shopify/sarama"
"github.com/go-kit/log"
"github.com/grafana/loki/clients/pkg/promtail/client/fake"
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/clients/pkg/promtail/client/fake"
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig"
)

func Test_TopicDiscovery(t *testing.T) {
Expand Down Expand Up @@ -102,6 +105,9 @@ func Test_NewTarget(t *testing.T) {
},
},
}
pipeline, err := stages.NewPipeline(ts.logger, ts.cfg.PipelineStages, &ts.cfg.JobName, ts.reg)
require.NoError(t, err)
ts.pipeline = pipeline
tg, err := ts.NewTarget(&testSession{}, newTestClaim("foo", 10, 1))

require.NoError(t, err)
Expand Down