Skip to content

Commit

Permalink
Remove singleton and allow unix exporter to be used multiple times (#…
Browse files Browse the repository at this point in the history
…5361)

* Initial checkin for the removing of singleton and modifying unix exporter to allow multiple configs to be defined.

* Change documentation.

* Remove unused configuration.

* Cleanup code.

* PR feedback.

* Add check back in for labels that I removed.

* Update with breaking changes.

* Update with newest node_exporter changes.

* Fix tests for integrations.

* Update docs/sources/flow/release-notes.md

Co-authored-by: Robert Fratto <[email protected]>

* Change name to default from u

* Merge and update node_exporter reference

* merge code changes for node_exporter

---------

Co-authored-by: Robert Fratto <[email protected]>
  • Loading branch information
mattdurham and rfratto authored Oct 4, 2023
1 parent 570c771 commit ec9dfc1
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 394 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Main (unreleased)
got replaced by the pair of `__meta_component_name` and `__meta_component_id`
labels. (@tpaschalis)

- Flow: Allow `prometheus.exporter.unix` to be specified multiple times and used in modules. This now means all
`prometheus.exporter.unix` references will need a label `prometheus.exporter.unix "example"`. (@mattdurham)

### Features

- New Grafana Agent Flow components:
Expand Down
1 change: 0 additions & 1 deletion component/prometheus/exporter/unix/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func init() {
Name: "prometheus.exporter.unix",
Args: Arguments{},
Exports: exporter.Exports{},
Singleton: true,
NeedsServices: exporter.RequiredServices(),
Build: exporter.New(createExporter, "unix"),
})
Expand Down
1 change: 0 additions & 1 deletion component/prometheus/exporter/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func init() {
Name: "prometheus.exporter.windows",
Args: Arguments{},
Exports: exporter.Exports{},
Singleton: false,
NeedsServices: exporter.RequiredServices(),
Build: exporter.New(createExporter, "windows"),
})
Expand Down
23 changes: 0 additions & 23 deletions component/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,6 @@ type Registration struct {
// any number of underscores or alphanumeric ASCII characters.
Name string

// A singleton component only supports one instance of itself across the
// whole process. Normally, multiple components of the same type may be
// created.
//
// The fully-qualified name of a component is the combination of River block
// name and all of its labels. Fully-qualified names must be unique across
// the process. Components which are *NOT* singletons automatically support
// user-supplied identifiers:
//
// // Fully-qualified names: remote.s3.object-a, remote.s3.object-b
// remote.s3 "object-a" { ... }
// remote.s3 "object-b" { ... }
//
// This allows for multiple instances of the same component to be defined.
// However, components registered as a singleton do not support user-supplied
// identifiers:
//
// node_exporter { ... }
//
// This prevents the user from defining multiple instances of node_exporter
// with different fully-qualified names.
Singleton bool

// An example Arguments value that the registered component expects to
// receive as input. Components should provide the zero value of their
// Arguments type here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func (b *IntegrationsV1ConfigBuilder) appendNodeExporter(config *node_exporter.C
args := toNodeExporter(config)
b.f.Body().AppendBlock(common.NewBlockWithOverride(
[]string{"prometheus", "exporter", "unix"},
"",
"default",
args,
))

return prometheusconvert.NewDiscoveryExports("prometheus.exporter.unix.targets")
return prometheusconvert.NewDiscoveryExports("prometheus.exporter.unix.default.targets")
}

func toNodeExporter(config *node_exporter.Config) *unix.Arguments {
Expand Down
4 changes: 2 additions & 2 deletions converter/internal/staticconvert/testdata/integrations.river
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ prometheus.scrape "integrations_mysqld_exporter" {
}
}

prometheus.exporter.unix { }
prometheus.exporter.unix "default" { }

discovery.relabel "integrations_node_exporter" {
targets = prometheus.exporter.unix.targets
targets = prometheus.exporter.unix.default.targets

rule {
source_labels = ["__address__"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ The `node_exporter` itself is comprised of various _collectors_, which can be
enabled and disabled at will. For more information on collectors, refer to the
[`collectors-list`](#collectors-list) section.

The `prometheus.exporter.unix` component can only appear once per
configuration file, and a block label must not be passed to it.

## Usage

```river
Expand Down Expand Up @@ -381,11 +378,11 @@ This example uses a [`prometheus.scrape` component][scrape] to collect metrics
from `prometheus.exporter.unix`:

```river
prometheus.exporter.unix { }
prometheus.exporter.unix "demo" { }
// Configure a prometheus.scrape component to collect unix metrics.
prometheus.scrape "demo" {
targets = prometheus.exporter.unix.targets
targets = prometheus.exporter.unix.demo.targets
forward_to = [prometheus.remote_write.demo.receiver]
}
Expand Down
17 changes: 17 additions & 0 deletions docs/sources/flow/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ to `true` and controlled via the `include_scope_labels` argument.
`name` to `otel_scope_name` and `version` to `otel_scope_version`. This is
now correct with the OTLP Instrumentation Scope specification.

### Breaking change: `prometheus.exporter.unix` now requires a label.

Previously the exporter was a singleton and did not require a label. The exporter now can be used multiple times and
needs a label.

Old configuration example:

```river
prometheus.exporter.unix { /* ... */ }
```

New configuration example:

```river
prometheus.exporter.unix "example" { /* ... */ }
```

## v0.36

### Breaking change: The default value of `retry_on_http_429` is changed to `true` for the `queue_config` in `prometheus.remote_write`
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect
github.com/beevik/ntp v0.3.0 // indirect
github.com/beevik/ntp v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.2-0.20180723201105-3c1074078d32+incompatible // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand Down Expand Up @@ -344,7 +344,7 @@ require (
github.com/efficientgo/tools/core v0.0.0-20220817170617-6c25e3b627dd // indirect
github.com/elastic/go-sysinfo v1.8.1 // indirect
github.com/elastic/go-windows v1.0.1 // indirect
github.com/ema/qdisc v0.0.0-20230120214811-5b708f463de3 // indirect
github.com/ema/qdisc v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/envoyproxy/go-control-plane v0.11.1 // indirect
Expand Down Expand Up @@ -456,7 +456,7 @@ require (
github.com/josharian/native v1.1.0 // indirect
github.com/joyent/triton-go v0.0.0-20180628001255-830d2b111e62 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jsimonetti/rtnetlink v1.3.2 // indirect
github.com/jsimonetti/rtnetlink v1.3.5 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/kevinburke/ssh_config v1.1.0 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
Expand All @@ -476,11 +476,11 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-xmlrpc v0.0.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mdlayher/ethtool v0.0.0-20221212131811-ba3b4bc2e02c // indirect
github.com/mdlayher/genetlink v1.3.1 // indirect
github.com/mdlayher/ethtool v0.1.0 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mdlayher/wifi v0.0.0-20220330172155-a44c70b6d3c8 // indirect
github.com/mdlayher/wifi v0.1.0 // indirect
github.com/microsoft/go-mssqldb v0.19.0 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
Expand Down Expand Up @@ -621,10 +621,9 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
)

require (
github.com/githubexporter/github-exporter v0.0.0-20230925090839-9e31cd0e7721
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab
)
require github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab

require github.com/githubexporter/github-exporter v0.0.0-20230925090839-9e31cd0e7721

require (
dario.cat/mergo v1.0.0 // indirect
Expand Down Expand Up @@ -711,6 +710,9 @@ replace (
// TODO(mattdurham): this is to allow defaults to propogate properly.
github.com/prometheus-community/windows_exporter => github.com/grafana/windows_exporter v0.15.1-0.20230612134738-fdb3ba7accd8
github.com/prometheus/mysqld_exporter => github.com/grafana/mysqld_exporter v0.12.2-0.20201015182516-5ac885b2d38a

// Replace node_export with custom fork for multi usage. https://github.com/prometheus/node_exporter/pull/2812
github.com/prometheus/node_exporter => github.com/grafana/node_exporter v0.18.1-grafana-r01.0.20231004161416-702318429731
)

// Excluding fixes a conflict in test packages and allows "go mod tidy" to run.
Expand Down
Loading

0 comments on commit ec9dfc1

Please sign in to comment.