Skip to content

Commit

Permalink
Add livedebugging support for discovery components
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishankar15 committed Dec 21, 2024
1 parent 2b42ec4 commit 2fc3259
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Main (unreleased)
- Live Debugging button should appear in UI only for supported components (@ravishankar15)
- 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 discovery components (@ravishankar15)
- Add livedebugging support for `discover.relabel` (@ravishankar15)

- Upgrade `github.com/goccy/go-json` to v0.10.4, which reduces the memory consumption of an Alloy instance by 20MB.
Expand Down
30 changes: 30 additions & 0 deletions docs/sources/troubleshoot/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ Supported components:
* `prometheus.relabel`
{{< /admonition >}}
* `discovery.relabel`
* `discovery.azure`
* `discovery.consul`
* `discovery.consulagent`
* `discovery.digitalocean`
* `discovery.dns`
* `discovery.docker`
* `discovery.dockerswarm`
* `discovery.ec2`
* `discovery.eureka`
* `discovery.file`
* `discovery.gce`
* `discovery.hetzner`
* `discovery.http`
* `discovery.ionos`
* `discovery.kubelet`
* `discovery.kubernetes`
* `discovery.kuma`
* `discovery.lightsail`
* `discovery.linode`
* `discovery.marathon`
* `discovery.nerve`
* `discovery.nomad`
* `discovery.openstack`
* `discovery.ovhcloud`
* `discovery.process`
* `discovery.puppetdb`
* `discovery.scaleway`
* `discovery.serverset`
* `discovery.triton`
* `discovery.uyuni`

## Debug using the UI

Expand Down
22 changes: 20 additions & 2 deletions internal/component/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discovery

import (
"context"
"fmt"
"slices"
"sort"
"strings"
Expand All @@ -15,6 +16,7 @@ import (

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/runtime/logging/level"
"github.com/grafana/alloy/internal/service/livedebugging"
)

// Target refers to a singular discovered endpoint found by a discovery
Expand Down Expand Up @@ -74,16 +76,26 @@ type Component struct {
latestDisc DiscovererWithMetrics
newDiscoverer chan struct{}

creator Creator
creator Creator
debugDataPublisher livedebugging.DebugDataPublisher
}

var _ component.Component = (*Component)(nil)
var _ component.LiveDebugging = (*Component)(nil)

// New creates a discovery component given arguments and a concrete Discovery implementation function.
func New(o component.Options, args component.Arguments, creator Creator) (*Component, error) {
debugDataPublisher, err := o.GetServiceData(livedebugging.ServiceName)
if err != nil {
return nil, err
}

c := &Component{
opts: o,
creator: creator,
// buffered to avoid deadlock from the first immediate update
newDiscoverer: make(chan struct{}, 1),
newDiscoverer: make(chan struct{}, 1),
debugDataPublisher: debugDataPublisher.(livedebugging.DebugDataPublisher),
}
return c, c.Update(args)
}
Expand Down Expand Up @@ -224,6 +236,10 @@ func (c *Component) runDiscovery(ctx context.Context, d DiscovererWithMetrics) {
allTargets = append(allTargets, labels)
}
}
componenentID := livedebugging.ComponentID(c.opts.ID)
if c.debugDataPublisher.IsActive(componenentID) {
c.debugDataPublisher.Publish(componenentID, fmt.Sprintf("%s", allTargets))
}
c.opts.OnStateChange(Exports{Targets: allTargets})
}

Expand Down Expand Up @@ -257,3 +273,5 @@ func (c *Component) runDiscovery(ctx context.Context, d DiscovererWithMetrics) {
}
}
}

func (c *Component) LiveDebugging(_ int) {}

0 comments on commit 2fc3259

Please sign in to comment.