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

Add livedebugging support for discover.relabel #2291

Merged
merged 3 commits into from
Dec 17, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/sources/troubleshoot/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Supported components:
* `otelcol.receiver.*`
* `prometheus.relabel`
{{< /admonition >}}
* `discovery.relabel`

## Debug using the UI

Expand Down
24 changes: 21 additions & 3 deletions internal/component/discovery/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()))
}
}

Expand All @@ -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 {
Expand Down
Loading