Skip to content

Commit 4f6ec89

Browse files
committed
Add some high level pipeline tests for prometheus
1 parent 96b4e9d commit 4f6ec89

File tree

11 files changed

+416
-83
lines changed

11 files changed

+416
-83
lines changed

internal/component/otelcol/exporter/prometheus/prometheus.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
"time"
99

1010
"github.com/go-kit/log"
11+
"github.com/prometheus/prometheus/storage"
12+
1113
"github.com/grafana/alloy/internal/component"
1214
"github.com/grafana/alloy/internal/component/otelcol"
1315
"github.com/grafana/alloy/internal/component/otelcol/exporter/prometheus/internal/convert"
1416
"github.com/grafana/alloy/internal/component/otelcol/internal/lazyconsumer"
1517
"github.com/grafana/alloy/internal/component/prometheus"
1618
"github.com/grafana/alloy/internal/featuregate"
1719
"github.com/grafana/alloy/internal/service/labelstore"
18-
"github.com/prometheus/prometheus/storage"
1920
)
2021

2122
func init() {
@@ -87,7 +88,7 @@ func New(o component.Options, c Arguments) (*Component, error) {
8788
return nil, err
8889
}
8990
ls := service.(labelstore.LabelStore)
90-
fanout := prometheus.NewFanout(nil, o.ID, o.Registerer, ls)
91+
fanout := prometheus.NewFanout(nil, o.Registerer, ls)
9192

9293
converter := convert.New(o.Logger, fanout, convertArgumentsToConvertOptions(c))
9394

internal/component/prometheus/enrich/enrich.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func New(opts component.Options, args Arguments) (*Component, error) {
9797
}
9898
}
9999

100-
c.fanout = prometheus.NewFanout(args.ForwardTo, opts.ID, opts.Registerer, ls)
100+
c.fanout = prometheus.NewFanout(args.ForwardTo, opts.Registerer, ls)
101101
c.receiver = prometheus.NewInterceptor(
102102
c.fanout,
103103
ls,

internal/component/prometheus/fanout.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ var _ storage.Appendable = (*Fanout)(nil)
2626
type Fanout struct {
2727
mut sync.RWMutex
2828
// children is where to fan out.
29-
children []storage.Appendable
30-
// ComponentID is what component this belongs to.
31-
componentID string
29+
children []storage.Appendable
3230
writeLatency prometheus.Histogram
3331
samplesCounter prometheus.Counter
3432
ls labelstore.LabelStore
@@ -39,7 +37,7 @@ type Fanout struct {
3937
}
4038

4139
// NewFanout creates a fanout appendable.
42-
func NewFanout(children []storage.Appendable, componentID string, register prometheus.Registerer, ls labelstore.LabelStore) *Fanout {
40+
func NewFanout(children []storage.Appendable, register prometheus.Registerer, ls labelstore.LabelStore) *Fanout {
4341
wl := prometheus.NewHistogram(prometheus.HistogramOpts{
4442
Name: "prometheus_fanout_latency",
4543
Help: "Write latency for sending to direct and indirect components",
@@ -55,7 +53,6 @@ func NewFanout(children []storage.Appendable, componentID string, register prome
5553

5654
return &Fanout{
5755
children: children,
58-
componentID: componentID,
5956
writeLatency: wl,
6057
samplesCounter: s,
6158
ls: ls,

internal/component/prometheus/fanout_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313

1414
func TestRollback(t *testing.T) {
1515
ls := labelstore.New(nil, prometheus.DefaultRegisterer)
16-
fanout := NewFanout([]storage.Appendable{NewFanout(nil, "1", prometheus.DefaultRegisterer, ls)}, "", prometheus.DefaultRegisterer, ls)
16+
fanout := NewFanout([]storage.Appendable{NewFanout(nil, prometheus.DefaultRegisterer, ls)}, prometheus.DefaultRegisterer, ls)
1717
app := fanout.Appender(t.Context())
1818
err := app.Rollback()
1919
require.NoError(t, err)
2020
}
2121

2222
func TestCommit(t *testing.T) {
2323
ls := labelstore.New(nil, prometheus.DefaultRegisterer)
24-
fanout := NewFanout([]storage.Appendable{NewFanout(nil, "1", prometheus.DefaultRegisterer, ls)}, "", prometheus.DefaultRegisterer, ls)
24+
fanout := NewFanout([]storage.Appendable{NewFanout(nil, prometheus.DefaultRegisterer, ls)}, prometheus.DefaultRegisterer, ls)
2525
app := fanout.Appender(t.Context())
2626
err := app.Commit()
2727
require.NoError(t, err)

internal/component/prometheus/operator/common/crdmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (c *crdManager) Run(ctx context.Context) error {
145145
}()
146146

147147
// Start prometheus scrape manager.
148-
alloyAppendable := prometheus.NewFanout(c.args.ForwardTo, c.opts.ID, c.opts.Registerer, c.ls)
148+
alloyAppendable := prometheus.NewFanout(c.args.ForwardTo, c.opts.Registerer, c.ls)
149149
opts := &scrape.Options{}
150150
c.scrapeManager, err = scrape.NewManager(opts, slog.New(logging.NewSlogGoKitHandler(c.logger)), nil, alloyAppendable, unregisterer)
151151
if err != nil {

0 commit comments

Comments
 (0)