Skip to content

Commit 784b111

Browse files
Fix internal metrics namespace for certain components (#2803) (#2804)
Signed-off-by: Paschalis Tsilias <[email protected]> Co-authored-by: Paschalis Tsilias <[email protected]>
1 parent 658f837 commit 784b111

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ This document contains a historical list of changes between releases. Only
77
changes that impact end-user behavior are listed; changes to documentation or
88
internal API changes are not present.
99

10+
v1.7.0-rc.3
11+
-----------------
12+
13+
### Bugfixes
14+
15+
- Fixed a bug where `loki.source.awsfirehose` and `loki.source.gcplog` could
16+
not be used from within a module. (@tpaschalis)
17+
18+
1019
v1.7.0-rc.2
1120
-----------------
1221

internal/component/loki/source/aws_firehose/component.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ func (c *Component) Update(args component.Arguments) error {
155155
c.rbs = newRelabels
156156
}
157157

158-
jobName := strings.Replace(c.opts.ID, ".", "_", -1)
158+
r := strings.NewReplacer(".", "_", "/", "_")
159+
jobName := r.Replace(c.opts.ID)
159160

160161
registry := prometheus.NewRegistry()
161162
c.serverMetrics.SetCollector(registry)

internal/component/loki/source/aws_firehose/component_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/prometheus/client_golang/prometheus"
1515
"github.com/prometheus/common/model"
1616
"github.com/stretchr/testify/require"
17+
"go.uber.org/goleak"
1718

1819
"github.com/grafana/alloy/internal/component"
1920
"github.com/grafana/alloy/internal/component/common/loki"
@@ -56,6 +57,45 @@ func (r *receiver) run(ctx context.Context) {
5657
}
5758
}
5859

60+
func TestComponentFromNestedController(t *testing.T) {
61+
goleak.VerifyNone(t, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
62+
63+
opts := component.Options{
64+
ID: "foo/loki.source.awsfirehose.default",
65+
Logger: util.TestAlloyLogger(t),
66+
Registerer: prometheus.NewRegistry(),
67+
OnStateChange: func(e component.Exports) {},
68+
}
69+
ch1, ch2 := loki.NewLogsReceiver(), loki.NewLogsReceiver()
70+
r1, r2 := newReceiver(ch1.Chan()), newReceiver(ch2.Chan())
71+
72+
// call cancelReceivers to terminate them
73+
receiverContext, cancelReceivers := context.WithCancel(context.Background())
74+
go r1.run(receiverContext)
75+
go r2.run(receiverContext)
76+
77+
args := Arguments{}
78+
79+
port, err := freeport.GetFreePort()
80+
require.NoError(t, err)
81+
args.Server = &fnet.ServerConfig{
82+
HTTP: &fnet.HTTPConfig{
83+
ListenAddress: "localhost",
84+
ListenPort: port,
85+
},
86+
// assign random grpc port
87+
GRPC: &fnet.GRPCConfig{ListenPort: 0},
88+
}
89+
args.ForwardTo = []loki.LogsReceiver{ch1, ch2}
90+
91+
// Create and run the component.
92+
c, err := New(opts, args)
93+
require.NoError(t, err)
94+
require.NotNil(t, c)
95+
96+
cancelReceivers()
97+
}
98+
5999
func TestComponent(t *testing.T) {
60100
opts := component.Options{
61101
ID: "loki.source.awsfirehose",

internal/component/loki/source/gcplog/gcplog.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func (c *Component) Update(args component.Arguments) error {
132132
}
133133
}
134134
entryHandler := loki.NewEntryHandler(c.handler.Chan(), func() {})
135-
jobName := strings.Replace(c.opts.ID, ".", "_", -1)
135+
r := strings.NewReplacer(".", "_", "/", "_")
136+
jobName := r.Replace(c.opts.ID)
136137

137138
if newArgs.PullTarget != nil {
138139
// TODO(@tpaschalis) Are there any options from "google.golang.org/api/option"

internal/component/loki/source/gcplog/gcplog_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/prometheus/client_golang/prometheus"
1414
"github.com/prometheus/common/model"
1515
"github.com/stretchr/testify/require"
16+
"go.uber.org/goleak"
1617

1718
"github.com/grafana/alloy/internal/component"
1819
"github.com/grafana/alloy/internal/component/common/loki"
@@ -26,6 +27,43 @@ import (
2627
// the mock PubSub client inside the component, but we'll find a workaround.
2728
func TestPull(t *testing.T) {}
2829

30+
func TestPushFromNestedController(t *testing.T) {
31+
goleak.VerifyNone(t, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
32+
33+
opts := component.Options{
34+
ID: "foo/loki.source.gcplog.default",
35+
Logger: util.TestAlloyLogger(t),
36+
Registerer: prometheus.NewRegistry(),
37+
OnStateChange: func(e component.Exports) {},
38+
}
39+
40+
ch1, ch2 := loki.NewLogsReceiver(), loki.NewLogsReceiver()
41+
args := Arguments{}
42+
43+
port, err := freeport.GetFreePort()
44+
require.NoError(t, err)
45+
args.PushTarget = &gcptypes.PushConfig{
46+
Server: &fnet.ServerConfig{
47+
HTTP: &fnet.HTTPConfig{
48+
ListenAddress: "localhost",
49+
ListenPort: port,
50+
},
51+
// assign random grpc port
52+
GRPC: &fnet.GRPCConfig{ListenPort: 0},
53+
},
54+
Labels: map[string]string{
55+
"foo": "bar",
56+
},
57+
}
58+
args.ForwardTo = []loki.LogsReceiver{ch1, ch2}
59+
args.RelabelRules = exportedRules
60+
61+
// Create and run the component.
62+
c, err := New(opts, args)
63+
require.NoError(t, err)
64+
require.NotNil(t, c)
65+
}
66+
2967
func TestPush(t *testing.T) {
3068
opts := component.Options{
3169
Logger: util.TestAlloyLogger(t),

0 commit comments

Comments
 (0)