Skip to content

Commit 4198859

Browse files
mergify[bot]faec
andauthored
Fix and test initialization of queue monitors (#40480) (#40481)
A stray `:=` instead of `=` overwrote the intended queue metrics namespace. This PR fixes it and adds a test to make sure the correct namespace is used. Fixes #40477 (cherry picked from commit d7ae68c) Co-authored-by: Fae Charlton <[email protected]>
1 parent f170d88 commit 4198859

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

libbeat/publisher/pipeline/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (c *outputController) createQueueIfNeeded(outGrp outputs.Group) {
274274
// Queue metrics are reported under the pipeline namespace
275275
var pipelineMetrics *monitoring.Registry
276276
if c.monitors.Metrics != nil {
277-
pipelineMetrics := c.monitors.Metrics.GetRegistry("pipeline")
277+
pipelineMetrics = c.monitors.Metrics.GetRegistry("pipeline")
278278
if pipelineMetrics == nil {
279279
pipelineMetrics = c.monitors.Metrics.NewRegistry("pipeline")
280280
}

libbeat/publisher/pipeline/controller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue"
3434
conf "github.com/elastic/elastic-agent-libs/config"
3535
"github.com/elastic/elastic-agent-libs/logp"
36+
"github.com/elastic/elastic-agent-libs/monitoring"
3637

3738
//"github.com/elastic/beats/v7/libbeat/tests/resources"
3839

@@ -243,3 +244,26 @@ func TestQueueProducerBlocksUntilOutputIsSet(t *testing.T) {
243244
})
244245
assert.True(t, allFinished, "All queueProducer requests should be unblocked once an output is set")
245246
}
247+
248+
func TestQueueMetrics(t *testing.T) {
249+
// More thorough testing of queue metrics are in the queue package,
250+
// here we just want to make sure that they appear under the right
251+
// monitoring namespace.
252+
reg := monitoring.NewRegistry()
253+
controller := outputController{
254+
queueFactory: memqueue.FactoryForSettings(memqueue.Settings{Events: 1000}),
255+
consumer: &eventConsumer{
256+
targetChan: make(chan consumerTarget, 4),
257+
retryObserver: nilObserver,
258+
},
259+
monitors: Monitors{Metrics: reg},
260+
}
261+
controller.Set(outputs.Group{
262+
Clients: []outputs.Client{newMockClient(nil)},
263+
})
264+
entry := reg.Get("pipeline.queue.max_events")
265+
require.NotNil(t, entry, "pipeline.queue.max_events must exist")
266+
value, ok := entry.(*monitoring.Uint)
267+
require.True(t, ok, "pipeline.queue.max_events must be a *monitoring.Uint")
268+
assert.Equal(t, uint64(1000), value.Get(), "pipeline.queue.max_events should match the events configuration key")
269+
}

0 commit comments

Comments
 (0)