From 8a1c816f47175b16c427ebdbdb1b1c521964a182 Mon Sep 17 00:00:00 2001 From: Ravishankar Date: Tue, 17 Dec 2024 07:59:11 +0530 Subject: [PATCH 1/3] Add livedebugging support for discover.relabel --- CHANGELOG.md | 3 ++- .../components/discovery/discovery.relabel.md | 4 +++- .../component/discovery/relabel/relabel.go | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bf82b5d54..9fc413ca49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,10 +50,11 @@ Main (unreleased) - Add three new stdlib functions to_base64, from_URLbase64 and to_URLbase64 (@ravishankar15) - Add `ignore_older_than` option for local.file_match (@ravishankar15) +- Add livedebugging support for `discover.relabel` (@ravishankar15) - Use a forked `github.com/goccy/go-json` module which reduces the memory consumption of an Alloy instance by 20MB. If Alloy is running certain otelcol components, this reduction will not apply. (@ptodev) - + - Update `prometheus.write.queue` library for performance increases in cpu. (@mattdurham) ### Bugfixes diff --git a/docs/sources/reference/components/discovery/discovery.relabel.md b/docs/sources/reference/components/discovery/discovery.relabel.md index 8abd5501e6..7164681463 100644 --- a/docs/sources/reference/components/discovery/discovery.relabel.md +++ b/docs/sources/reference/components/discovery/discovery.relabel.md @@ -78,7 +78,9 @@ In those cases, exported fields retain their last healthy values. ## Debug information -`discovery.relabel` does not expose any component-specific debug information. +`discovery.relabel` exposes some target-level debug information per target: + +* The current label and the relabelled value associated with each target. ## Debug metrics diff --git a/internal/component/discovery/relabel/relabel.go b/internal/component/discovery/relabel/relabel.go index 551f361d76..6613c6c801 100644 --- a/internal/component/discovery/relabel/relabel.go +++ b/internal/component/discovery/relabel/relabel.go @@ -2,12 +2,14 @@ package relabel import ( "context" + "fmt" "sync" "github.com/grafana/alloy/internal/component" alloy_relabel "github.com/grafana/alloy/internal/component/common/relabel" "github.com/grafana/alloy/internal/component/discovery" "github.com/grafana/alloy/internal/featuregate" + "github.com/grafana/alloy/internal/service/livedebugging" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/relabel" ) @@ -46,13 +48,23 @@ type Component struct { mut sync.RWMutex rcs []*relabel.Config + + debugDataPublisher livedebugging.DebugDataPublisher } var _ component.Component = (*Component)(nil) +var _ component.LiveDebugging = (*Component)(nil) // New creates a new discovery.relabel component. func New(o component.Options, args Arguments) (*Component, error) { - c := &Component{opts: o} + debugDataPublisher, err := o.GetServiceData(livedebugging.ServiceName) + if err != nil { + return nil, err + } + c := &Component{ + opts: o, + debugDataPublisher: debugDataPublisher.(livedebugging.DebugDataPublisher), + } // Call to Update() to set the output once at the start if err := c.Update(args); err != nil { @@ -81,9 +93,13 @@ func (c *Component) Update(args component.Arguments) error { for _, t := range newArgs.Targets { lset := componentMapToPromLabels(t) - lset, keep := relabel.Process(lset, relabelConfigs...) + relabelled, keep := relabel.Process(lset, relabelConfigs...) if keep { - targets = append(targets, promLabelsToComponent(lset)) + targets = append(targets, promLabelsToComponent(relabelled)) + } + componentID := livedebugging.ComponentID(c.opts.ID) + if c.debugDataPublisher.IsActive(componentID) { + c.debugDataPublisher.Publish(componentID, fmt.Sprintf("%s => %s", lset.String(), relabelled.String())) } } @@ -95,6 +111,8 @@ func (c *Component) Update(args component.Arguments) error { return nil } +func (c *Component) LiveDebugging(_ int) {} + func componentMapToPromLabels(ls discovery.Target) labels.Labels { res := make([]labels.Label, 0, len(ls)) for k, v := range ls { From 5fd933f755f72c001f6cbe120c0a847cf2a963a5 Mon Sep 17 00:00:00 2001 From: Ravishankar Date: Tue, 17 Dec 2024 18:56:33 +0530 Subject: [PATCH 2/3] Update docs --- .../sources/reference/components/discovery/discovery.relabel.md | 2 -- docs/sources/troubleshoot/debug.md | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/sources/reference/components/discovery/discovery.relabel.md b/docs/sources/reference/components/discovery/discovery.relabel.md index 7164681463..13ad9f912e 100644 --- a/docs/sources/reference/components/discovery/discovery.relabel.md +++ b/docs/sources/reference/components/discovery/discovery.relabel.md @@ -80,8 +80,6 @@ In those cases, exported fields retain their last healthy values. `discovery.relabel` exposes some target-level debug information per target: -* The current label and the relabelled value associated with each target. - ## Debug metrics `discovery.relabel` does not expose any component-specific debug metrics. diff --git a/docs/sources/troubleshoot/debug.md b/docs/sources/troubleshoot/debug.md index 0e674aa1a1..5b8518515d 100644 --- a/docs/sources/troubleshoot/debug.md +++ b/docs/sources/troubleshoot/debug.md @@ -111,6 +111,7 @@ Supported components: * `otelcol.receiver.*` * `prometheus.relabel` {{< /admonition >}} +* `discovery.relabel` ## Debug using the UI From a7304598105ffce854123daa6af57d11ac9da976 Mon Sep 17 00:00:00 2001 From: Ravishankar Date: Tue, 17 Dec 2024 19:35:11 +0530 Subject: [PATCH 3/3] Update docs/sources/reference/components/discovery/discovery.relabel.md Co-authored-by: William Dumont --- .../sources/reference/components/discovery/discovery.relabel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/reference/components/discovery/discovery.relabel.md b/docs/sources/reference/components/discovery/discovery.relabel.md index 13ad9f912e..8abd5501e6 100644 --- a/docs/sources/reference/components/discovery/discovery.relabel.md +++ b/docs/sources/reference/components/discovery/discovery.relabel.md @@ -78,7 +78,7 @@ In those cases, exported fields retain their last healthy values. ## Debug information -`discovery.relabel` exposes some target-level debug information per target: +`discovery.relabel` does not expose any component-specific debug information. ## Debug metrics