Skip to content

Commit

Permalink
Remove NeedsServices from components (grafana#5780)
Browse files Browse the repository at this point in the history
* service/cluster: stop using dependant components

Update the cluster service to stop looking at dependant components when
notifying clustered components of a cluster update.

Related to grafana#5777, as components will no longer be able to declare a
dependancy on a service.

* service: add soft requirement that data must not rely on runtime config

Change the doc comment of service.Data to note that the returned data
must not rely on runtime config.

Related to grafana#5777, as components will no longer directly depend on
services. If service.Data relied on the runtime config, it would open
the door for hidden circular dependencies.

* flow: remove dependency from components to services

This commit fully removes the dependency from components to services,
leaving the NeedsServices field in component.Registration ignored.

Related to grafana#5777.

* component: remove NeedsServices field

Remove the unused NeedsServices field.

Related to grafana#5777.

* misc: update CHANGELOG and docs for grafana#5777

Update the CHANGELOG and docs to reflect the dropped requirement that
components must depend on consumed services.

Closes grafana#5777.
  • Loading branch information
rfratto authored and hainenber committed Nov 25, 2023
1 parent 98ecc9f commit 9ca95e2
Show file tree
Hide file tree
Showing 81 changed files with 307 additions and 549 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Main (unreleased)
- Added metrics, alerts and dashboard visualisations to help diagnose issues
with unhealthy components and components that take too long to evaluate. (@thampiotr)

- The `http` config block may now reference exports from any component.
Previously, only `remote.*` and `local.*` components could be referenced
without a circular dependency. (@rfratto)

### Bugfixes

- Permit `X-Faro-Session-ID` header in CORS requests for the `faro.receiver`
Expand Down Expand Up @@ -218,6 +222,9 @@ v0.37.4 (2023-11-06)
- Fix a bug where reloading the configuration of a `loki.write` component lead
to a panic. (@tpaschalis)

- Added Kubernetes service resolver to static node's loadbalancing exporter
and to Flow's `otelcol.exporter.loadbalancing`. (@ptodev)

v0.37.3 (2023-10-26)
-----------------

Expand Down
5 changes: 2 additions & 3 deletions component/loki/source/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.source.kubernetes",
Args: Arguments{},
NeedsServices: []string{cluster.ServiceName},
Name: "loki.source.kubernetes",
Args: Arguments{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
5 changes: 2 additions & 3 deletions component/loki/source/podlogs/podlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import (

func init() {
component.Register(component.Registration{
Name: "loki.source.podlogs",
Args: Arguments{},
NeedsServices: []string{cluster.ServiceName},
Name: "loki.source.podlogs",
Args: Arguments{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
11 changes: 3 additions & 8 deletions component/module/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/local/file"
"github.com/grafana/agent/component/module"
"github.com/grafana/agent/service/cluster"
"github.com/grafana/agent/service/http"
"github.com/grafana/agent/service/labelstore"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
)

func init() {
component.Register(component.Registration{
Name: "module.file",
Args: Arguments{},
Exports: module.Exports{},
NeedsServices: []string{http.ServiceName, cluster.ServiceName, otel_service.ServiceName, labelstore.ServiceName},
Name: "module.file",
Args: Arguments{},
Exports: module.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
11 changes: 3 additions & 8 deletions component/module/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ import (
"github.com/grafana/agent/component/module"
"github.com/grafana/agent/component/module/git/internal/vcs"
"github.com/grafana/agent/pkg/flow/logging/level"
"github.com/grafana/agent/service/cluster"
"github.com/grafana/agent/service/http"
"github.com/grafana/agent/service/labelstore"
otel_service "github.com/grafana/agent/service/otel"
)

func init() {
component.Register(component.Registration{
Name: "module.git",
Args: Arguments{},
Exports: module.Exports{},
NeedsServices: []string{http.ServiceName, cluster.ServiceName, otel_service.ServiceName, labelstore.ServiceName},
Name: "module.git",
Args: Arguments{},
Exports: module.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
11 changes: 3 additions & 8 deletions component/module/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/module"
remote_http "github.com/grafana/agent/component/remote/http"
"github.com/grafana/agent/service/cluster"
http_service "github.com/grafana/agent/service/http"
"github.com/grafana/agent/service/labelstore"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
)

func init() {
component.Register(component.Registration{
Name: "module.http",
Args: Arguments{},
Exports: module.Exports{},
NeedsServices: []string{http_service.ServiceName, cluster.ServiceName, otel_service.ServiceName, labelstore.ServiceName},
Name: "module.http",
Args: Arguments{},
Exports: module.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
11 changes: 3 additions & 8 deletions component/module/string/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import (

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/module"
"github.com/grafana/agent/service/cluster"
"github.com/grafana/agent/service/http"
"github.com/grafana/agent/service/labelstore"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
)

func init() {
component.Register(component.Registration{
Name: "module.string",
Args: Arguments{},
Exports: module.Exports{},
NeedsServices: []string{http.ServiceName, cluster.ServiceName, otel_service.ServiceName, labelstore.ServiceName},
Name: "module.string",
Args: Arguments{},
Exports: module.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/auth/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package basic
import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/basicauthextension"
otelcomponent "go.opentelemetry.io/collector/component"
Expand All @@ -14,10 +13,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.auth.basic",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.auth.basic",
Args: Arguments{},
Exports: auth.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := basicauthextension.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/auth/bearer/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package bearer
import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension"
otelcomponent "go.opentelemetry.io/collector/component"
Expand All @@ -14,10 +13,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.auth.bearer",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.auth.bearer",
Args: Arguments{},
Exports: auth.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := bearertokenauthextension.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/auth/headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river"
"github.com/grafana/river/rivertypes"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension"
Expand All @@ -18,10 +17,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.auth.headers",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.auth.headers",
Args: Arguments{},
Exports: auth.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := headerssetterextension.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/auth/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river/rivertypes"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/oauth2clientauthextension"
otelcomponent "go.opentelemetry.io/collector/component"
Expand All @@ -17,10 +16,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.auth.oauth2",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.auth.oauth2",
Args: Arguments{},
Exports: auth.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := oauth2clientauthextension.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/auth/sigv4/sigv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ package sigv4
import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol/auth"
otel_service "github.com/grafana/agent/service/otel"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension"
otelcomponent "go.opentelemetry.io/collector/component"
otelextension "go.opentelemetry.io/collector/extension"
)

func init() {
component.Register(component.Registration{
Name: "otelcol.auth.sigv4",
Args: Arguments{},
Exports: auth.Exports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.auth.sigv4",
Args: Arguments{},
Exports: auth.Exports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := sigv4authextension.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/connector/servicegraph/servicegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/connector"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river"
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/servicegraphconnector"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor"
Expand All @@ -17,10 +16,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.connector.servicegraph",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.connector.servicegraph",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := servicegraphconnector.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/connector/spanmetrics/spanmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/connector"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river"
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector"
otelcomponent "go.opentelemetry.io/collector/component"
Expand All @@ -17,10 +16,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.connector.spanmetrics",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.connector.spanmetrics",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := spanmetricsconnector.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/exporter/loadbalancing/loadbalancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/auth"
"github.com/grafana/agent/component/otelcol/exporter"
otel_service "github.com/grafana/agent/service/otel"
"github.com/grafana/river"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter"
otelcomponent "go.opentelemetry.io/collector/component"
Expand All @@ -24,10 +23,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.loadbalancing",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.exporter.loadbalancing",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := loadbalancingexporter.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/exporter/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/exporter"
otel_service "github.com/grafana/agent/service/otel"
otelcomponent "go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
loggingexporter "go.opentelemetry.io/collector/exporter/loggingexporter"
Expand All @@ -14,10 +13,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.logging",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.exporter.logging",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := loggingexporter.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/exporter/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/exporter"
otel_service "github.com/grafana/agent/service/otel"
otelcomponent "go.opentelemetry.io/collector/component"
otelpexporterhelper "go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/otlpexporter"
Expand All @@ -16,10 +15,9 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.otlp",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.exporter.otlp",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := otlpexporter.NewFactory()
Expand Down
8 changes: 3 additions & 5 deletions component/otelcol/exporter/otlphttp/otlphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import (
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/otelcol"
"github.com/grafana/agent/component/otelcol/exporter"
otel_service "github.com/grafana/agent/service/otel"
otelcomponent "go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
otelextension "go.opentelemetry.io/collector/extension"
)

func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.otlphttp",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{otel_service.ServiceName},
Name: "otelcol.exporter.otlphttp",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
fact := otlphttpexporter.NewFactory()
Expand Down
8 changes: 4 additions & 4 deletions component/otelcol/exporter/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

func init() {
component.Register(component.Registration{
Name: "otelcol.exporter.prometheus",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},
NeedsServices: []string{labelstore.ServiceName},
Name: "otelcol.exporter.prometheus",
Args: Arguments{},
Exports: otelcol.ConsumerExports{},

Build: func(o component.Options, a component.Arguments) (component.Component, error) {
return New(o, a.(Arguments))
},
Expand Down
Loading

0 comments on commit 9ca95e2

Please sign in to comment.