Skip to content

Commit

Permalink
Add livedebugging support for discover.relabel
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishankar15 committed Dec 17, 2024
1 parent 70dbba8 commit 8a1c816
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 8a1c816

Please sign in to comment.