From 46d0f7361e34629f3f715a844df1fe0b8bae16e6 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Wed, 4 Sep 2024 12:37:27 +0200 Subject: [PATCH] [extension] Move optional interfaces to extensioncapabilities (#11000) #### Description Moves extension optional interfaces to a new module, `extensioncapabilities`. The intent is to be able to evolve these interfaces independently from the core interfaces on core. These are used by at most one component/project, so I think they are not mature yet for 1.0 --------- Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> --- .../mx-psi_extensioncapabilities-depr.yaml | 25 ++++++ .chloggen/mx-psi_extensioncapabilities.yaml | 25 ++++++ Makefile | 1 + cmd/builder/internal/builder/main_test.go | 1 + cmd/builder/test/core.builder.yaml | 1 + cmd/otelcorecol/builder-config.yaml | 1 + cmd/otelcorecol/go.mod | 3 + extension/extension.go | 44 ++------- extension/extensioncapabilities/Makefile | 1 + extension/extensioncapabilities/go.mod | 43 +++++++++ extension/extensioncapabilities/go.sum | 90 +++++++++++++++++++ extension/extensioncapabilities/interfaces.go | 25 ++++++ extension/internal/interfaces.go | 48 ++++++++++ internal/e2e/go.mod | 3 + internal/e2e/status_test.go | 6 +- otelcol/go.mod | 3 + otelcol/otelcoltest/go.mod | 3 + service/extensions/extensions.go | 7 +- service/extensions/extensions_test.go | 3 +- service/extensions/graph.go | 4 +- service/go.mod | 3 + versions.yaml | 1 + 22 files changed, 297 insertions(+), 44 deletions(-) create mode 100644 .chloggen/mx-psi_extensioncapabilities-depr.yaml create mode 100644 .chloggen/mx-psi_extensioncapabilities.yaml create mode 100644 extension/extensioncapabilities/Makefile create mode 100644 extension/extensioncapabilities/go.mod create mode 100644 extension/extensioncapabilities/go.sum create mode 100644 extension/extensioncapabilities/interfaces.go create mode 100644 extension/internal/interfaces.go diff --git a/.chloggen/mx-psi_extensioncapabilities-depr.yaml b/.chloggen/mx-psi_extensioncapabilities-depr.yaml new file mode 100644 index 00000000000..00752d6dc24 --- /dev/null +++ b/.chloggen/mx-psi_extensioncapabilities-depr.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: extension + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate `extension.ConfigWatcher`, `extension.PipelineWatcher` and `extension.Dependent` in favor of equivalents in the `extensioncapabilities` module. + +# One or more tracking issues or pull requests related to the change +issues: [11000] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/.chloggen/mx-psi_extensioncapabilities.yaml b/.chloggen/mx-psi_extensioncapabilities.yaml new file mode 100644 index 00000000000..2c92154a3af --- /dev/null +++ b/.chloggen/mx-psi_extensioncapabilities.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: new_component + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: extensioncapabilities + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Create a new module for optional extension capabilities. + +# One or more tracking issues or pull requests related to the change +issues: [11000] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/Makefile b/Makefile index f55fc160db3..de08431f92a 100644 --- a/Makefile +++ b/Makefile @@ -293,6 +293,7 @@ check-contrib: -replace go.opentelemetry.io/collector/extension=$(CURDIR)/extension \ -replace go.opentelemetry.io/collector/extension/auth=$(CURDIR)/extension/auth \ -replace go.opentelemetry.io/collector/extension/experimental/storage=$(CURDIR)/extension/experimental/storage \ + -replace go.opentelemetry.io/collector/extension/extensioncapabilities=$(CURDIR)/extension/extensioncapabilities \ -replace go.opentelemetry.io/collector/extension/memorylimiterextension=$(CURDIR)/extension/memorylimiterextension \ -replace go.opentelemetry.io/collector/extension/zpagesextension=$(CURDIR)/extension/zpagesextension \ -replace go.opentelemetry.io/collector/featuregate=$(CURDIR)/featuregate \ diff --git a/cmd/builder/internal/builder/main_test.go b/cmd/builder/internal/builder/main_test.go index beb86c9117c..400740610cf 100644 --- a/cmd/builder/internal/builder/main_test.go +++ b/cmd/builder/internal/builder/main_test.go @@ -74,6 +74,7 @@ var ( "/extension", "/extension/auth", "/extension/experimental/storage", + "/extension/extensioncapabilities", "/extension/zpagesextension", "/featuregate", "/internal/globalgates", diff --git a/cmd/builder/test/core.builder.yaml b/cmd/builder/test/core.builder.yaml index 2ea0f8b3590..39f998e63bd 100644 --- a/cmd/builder/test/core.builder.yaml +++ b/cmd/builder/test/core.builder.yaml @@ -50,6 +50,7 @@ replaces: - go.opentelemetry.io/collector/extension => ${WORKSPACE_DIR}/extension - go.opentelemetry.io/collector/extension/auth => ${WORKSPACE_DIR}/extension/auth - go.opentelemetry.io/collector/extension/experimental/storage => ${WORKSPACE_DIR}/extension/experimental/storage + - go.opentelemetry.io/collector/extension/extensioncapabilities => ${WORKSPACE_DIR}/extension/extensioncapabilities - go.opentelemetry.io/collector/extension/zpagesextension => ${WORKSPACE_DIR}/extension/zpagesextension - go.opentelemetry.io/collector/featuregate => ${WORKSPACE_DIR}/featuregate - go.opentelemetry.io/collector/internal/globalgates => ${WORKSPACE_DIR}/internal/globalgates diff --git a/cmd/otelcorecol/builder-config.yaml b/cmd/otelcorecol/builder-config.yaml index 9c919cc2afe..fac10859836 100644 --- a/cmd/otelcorecol/builder-config.yaml +++ b/cmd/otelcorecol/builder-config.yaml @@ -78,6 +78,7 @@ replaces: - go.opentelemetry.io/collector/extension => ../../extension - go.opentelemetry.io/collector/extension/auth => ../../extension/auth - go.opentelemetry.io/collector/extension/experimental/storage => ../../extension/experimental/storage + - go.opentelemetry.io/collector/extension/extensioncapabilities => ../../extension/extensioncapabilities - go.opentelemetry.io/collector/extension/memorylimiterextension => ../../extension/memorylimiterextension - go.opentelemetry.io/collector/extension/zpagesextension => ../../extension/zpagesextension - go.opentelemetry.io/collector/featuregate => ../../featuregate diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index 8ee213b30fa..735ad56b28b 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -100,6 +100,7 @@ require ( go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect go.opentelemetry.io/collector/extension/experimental/storage v0.0.0-20240902085631-cd1f7623fe67 // indirect + go.opentelemetry.io/collector/extension/extensioncapabilities v0.108.1 // indirect go.opentelemetry.io/collector/featuregate v1.14.1 // indirect go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect go.opentelemetry.io/collector/pdata v1.14.1 // indirect @@ -223,6 +224,8 @@ replace go.opentelemetry.io/collector/extension/auth => ../../extension/auth replace go.opentelemetry.io/collector/extension/experimental/storage => ../../extension/experimental/storage +replace go.opentelemetry.io/collector/extension/extensioncapabilities => ../../extension/extensioncapabilities + replace go.opentelemetry.io/collector/extension/memorylimiterextension => ../../extension/memorylimiterextension replace go.opentelemetry.io/collector/extension/zpagesextension => ../../extension/zpagesextension diff --git a/extension/extension.go b/extension/extension.go index 06bce2cd1d5..cfa39016784 100644 --- a/extension/extension.go +++ b/extension/extension.go @@ -8,48 +8,22 @@ import ( "fmt" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/collector/extension/internal" ) // Extension is the interface for objects hosted by the OpenTelemetry Collector that // don't participate directly on data pipelines but provide some functionality // to the service, examples: health check endpoint, z-pages, etc. -type Extension = component.Component - -// Dependent is an optional interface that can be implemented by extensions -// that depend on other extensions and must be started only after their dependencies. -// See https://github.com/open-telemetry/opentelemetry-collector/pull/8768 for examples. -type Dependent interface { - Extension - Dependencies() []component.ID -} +type Extension = internal.Extension -// PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry -// Collector that is to be implemented by extensions interested in changes to pipeline -// states. Typically this will be used by extensions that change their behavior if data is -// being ingested or not, e.g.: a k8s readiness probe. -type PipelineWatcher interface { - // Ready notifies the Extension that all pipelines were built and the - // receivers were started, i.e.: the service is ready to receive data - // (note that it may already have received data when this method is called). - Ready() error - - // NotReady notifies the Extension that all receivers are about to be stopped, - // i.e.: pipeline receivers will not accept new data. - // This is sent before receivers are stopped, so the Extension can take any - // appropriate actions before that happens. - NotReady() error -} +// Deprecated: [v0.109.0] Use [extensioncapabilities.Dependent] instead. +type Dependent = internal.Dependent -// ConfigWatcher is an interface that should be implemented by an extension that -// wishes to be notified of the Collector's effective configuration. -type ConfigWatcher interface { - // NotifyConfig notifies the extension of the Collector's current effective configuration. - // The extension owns the `confmap.Conf`. Callers must ensure that it's safe for - // extensions to store the `conf` pointer and use it concurrently with any other - // instances of `conf`. - NotifyConfig(ctx context.Context, conf *confmap.Conf) error -} +// Deprecated: [v0.109.0] Use [extensioncapabilities.PipelineWatcher] instead. +type PipelineWatcher = internal.PipelineWatcher + +// Deprecated: [v0.109.0] Use [extensioncapabilities.ConfigWatcher] instead. +type ConfigWatcher = internal.ConfigWatcher // ModuleInfo describes the go module for each component. type ModuleInfo struct { diff --git a/extension/extensioncapabilities/Makefile b/extension/extensioncapabilities/Makefile new file mode 100644 index 00000000000..ded7a36092d --- /dev/null +++ b/extension/extensioncapabilities/Makefile @@ -0,0 +1 @@ +include ../../Makefile.Common diff --git a/extension/extensioncapabilities/go.mod b/extension/extensioncapabilities/go.mod new file mode 100644 index 00000000000..0376a9cfc2d --- /dev/null +++ b/extension/extensioncapabilities/go.mod @@ -0,0 +1,43 @@ +module go.opentelemetry.io/collector/extension/extensioncapabilities + +go 1.22.0 + +require go.opentelemetry.io/collector/extension v0.108.0 + +require ( + github.com/go-viper/mapstructure/v2 v2.1.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/knadh/koanf/providers/confmap v0.1.0 // indirect + github.com/knadh/koanf/v2 v2.1.1 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + go.opentelemetry.io/collector/component v0.108.1 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.108.1 // indirect + go.opentelemetry.io/collector/confmap v1.14.1 // indirect + go.opentelemetry.io/collector/pdata v1.14.1 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/net v0.27.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect + google.golang.org/grpc v1.66.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace go.opentelemetry.io/collector/extension => ../ + +replace go.opentelemetry.io/collector/pdata => ../../pdata + +replace go.opentelemetry.io/collector/confmap => ../../confmap + +replace go.opentelemetry.io/collector/config/configtelemetry => ../../config/configtelemetry + +replace go.opentelemetry.io/collector/component => ../../component + +replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus diff --git a/extension/extensioncapabilities/go.sum b/extension/extensioncapabilities/go.sum new file mode 100644 index 00000000000..ca41db78172 --- /dev/null +++ b/extension/extensioncapabilities/go.sum @@ -0,0 +1,90 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-viper/mapstructure/v2 v2.1.0 h1:gHnMa2Y/pIxElCH2GlZZ1lZSsn6XMtufpGyP1XxdC/w= +github.com/go-viper/mapstructure/v2 v2.1.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= +github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= +github.com/knadh/koanf/v2 v2.1.1 h1:/R8eXqasSTsmDCsAyYj+81Wteg8AqrV9CP6gvsTsOmM= +github.com/knadh/koanf/v2 v2.1.1/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/extension/extensioncapabilities/interfaces.go b/extension/extensioncapabilities/interfaces.go new file mode 100644 index 00000000000..2f2c6706431 --- /dev/null +++ b/extension/extensioncapabilities/interfaces.go @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package extensioncapabilities provides interfaces that can be implemented by extensions +// to provide additional capabilities. +package extensioncapabilities // import "go.opentelemetry.io/collector/extension/extensioncapabilities" + +import ( + "go.opentelemetry.io/collector/extension/internal" +) + +// Dependent is an optional interface that can be implemented by extensions +// that depend on other extensions and must be started only after their dependencies. +// See https://github.com/open-telemetry/opentelemetry-collector/pull/8768 for examples. +type Dependent = internal.Dependent + +// PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry +// Collector that is to be implemented by extensions interested in changes to pipeline +// states. Typically this will be used by extensions that change their behavior if data is +// being ingested or not, e.g.: a k8s readiness probe. +type PipelineWatcher = internal.PipelineWatcher + +// ConfigWatcher is an interface that should be implemented by an extension that +// wishes to be notified of the Collector's effective configuration. +type ConfigWatcher = internal.ConfigWatcher diff --git a/extension/internal/interfaces.go b/extension/internal/interfaces.go new file mode 100644 index 00000000000..49a504106fa --- /dev/null +++ b/extension/internal/interfaces.go @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package internal // import "go.opentelemetry.io/collector/extension/internal" + +import ( + "context" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/confmap" +) + +type Extension = component.Component + +// Dependent is an optional interface that can be implemented by extensions +// that depend on other extensions and must be started only after their dependencies. +// See https://github.com/open-telemetry/opentelemetry-collector/pull/8768 for examples. +type Dependent interface { + Extension + Dependencies() []component.ID +} + +// PipelineWatcher is an extra interface for Extension hosted by the OpenTelemetry +// Collector that is to be implemented by extensions interested in changes to pipeline +// states. Typically this will be used by extensions that change their behavior if data is +// being ingested or not, e.g.: a k8s readiness probe. +type PipelineWatcher interface { + // Ready notifies the Extension that all pipelines were built and the + // receivers were started, i.e.: the service is ready to receive data + // (note that it may already have received data when this method is called). + Ready() error + + // NotReady notifies the Extension that all receivers are about to be stopped, + // i.e.: pipeline receivers will not accept new data. + // This is sent before receivers are stopped, so the Extension can take any + // appropriate actions before that happens. + NotReady() error +} + +// ConfigWatcher is an interface that should be implemented by an extension that +// wishes to be notified of the Collector's effective configuration. +type ConfigWatcher interface { + // NotifyConfig notifies the extension of the Collector's current effective configuration. + // The extension owns the `confmap.Conf`. Callers must ensure that it's safe for + // extensions to store the `conf` pointer and use it concurrently with any other + // instances of `conf`. + NotifyConfig(ctx context.Context, conf *confmap.Conf) error +} diff --git a/internal/e2e/go.mod b/internal/e2e/go.mod index 2c6d1af3092..d3f0df829f2 100644 --- a/internal/e2e/go.mod +++ b/internal/e2e/go.mod @@ -81,6 +81,7 @@ require ( go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect go.opentelemetry.io/collector/extension/experimental/storage v0.0.0-20240902085631-cd1f7623fe67 // indirect + go.opentelemetry.io/collector/extension/extensioncapabilities v0.108.1 // indirect go.opentelemetry.io/collector/featuregate v1.14.1 // indirect go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect @@ -196,6 +197,8 @@ replace go.opentelemetry.io/collector/component/componentprofiles => ../../compo replace go.opentelemetry.io/collector/internal/globalgates => ../globalgates +replace go.opentelemetry.io/collector/extension/extensioncapabilities => ../../extension/extensioncapabilities + replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles replace go.opentelemetry.io/collector/processor/processorprofiles => ../../processor/processorprofiles diff --git a/internal/e2e/status_test.go b/internal/e2e/status_test.go index 3d886d5c999..c0ca4a6372b 100644 --- a/internal/e2e/status_test.go +++ b/internal/e2e/status_test.go @@ -279,17 +279,17 @@ func (t *testExtension) ComponentStatusChanged( } } -// NotifyConfig implements the extension.ConfigWatcher interface. +// NotifyConfig implements the extensioncapabilities.ConfigWatcher interface. func (t *testExtension) NotifyConfig(_ context.Context, _ *confmap.Conf) error { return nil } -// Ready implements the extension.PipelineWatcher interface. +// Ready implements the extensioncapabilities.PipelineWatcher interface. func (t *testExtension) Ready() error { return nil } -// NotReady implements the extension.PipelineWatcher interface. +// NotReady implements the extensioncapabilities.PipelineWatcher interface. func (t *testExtension) NotReady() error { return nil } diff --git a/otelcol/go.mod b/otelcol/go.mod index 346abef22e0..4706bda5943 100644 --- a/otelcol/go.mod +++ b/otelcol/go.mod @@ -69,6 +69,7 @@ require ( go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect + go.opentelemetry.io/collector/extension/extensioncapabilities v0.108.1 // indirect go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect go.opentelemetry.io/collector/pdata v1.14.1 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect @@ -168,6 +169,8 @@ replace go.opentelemetry.io/collector/client => ../client replace go.opentelemetry.io/collector/component/componentstatus => ../component/componentstatus +replace go.opentelemetry.io/collector/extension/extensioncapabilities => ../extension/extensioncapabilities + replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../receiver/receiverprofiles replace go.opentelemetry.io/collector/processor/processorprofiles => ../processor/processorprofiles diff --git a/otelcol/otelcoltest/go.mod b/otelcol/otelcoltest/go.mod index 4f8150edd28..1319703c474 100644 --- a/otelcol/otelcoltest/go.mod +++ b/otelcol/otelcoltest/go.mod @@ -67,6 +67,7 @@ require ( go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect + go.opentelemetry.io/collector/extension/extensioncapabilities v0.108.1 // indirect go.opentelemetry.io/collector/featuregate v1.14.1 // indirect go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect go.opentelemetry.io/collector/pdata v1.14.1 // indirect @@ -183,6 +184,8 @@ replace go.opentelemetry.io/collector/client => ../../client replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus +replace go.opentelemetry.io/collector/extension/extensioncapabilities => ../../extension/extensioncapabilities + replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles replace go.opentelemetry.io/collector/processor/processorprofiles => ../../processor/processorprofiles diff --git a/service/extensions/extensions.go b/service/extensions/extensions.go index c3a83192158..7cf4aaed6c6 100644 --- a/service/extensions/extensions.go +++ b/service/extensions/extensions.go @@ -16,6 +16,7 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/extension/extensioncapabilities" "go.opentelemetry.io/collector/service/internal/builders" "go.opentelemetry.io/collector/service/internal/components" "go.opentelemetry.io/collector/service/internal/status" @@ -92,7 +93,7 @@ func (bes *Extensions) Shutdown(ctx context.Context) error { func (bes *Extensions) NotifyPipelineReady() error { for _, extID := range bes.extensionIDs { ext := bes.extMap[extID] - if pw, ok := ext.(extension.PipelineWatcher); ok { + if pw, ok := ext.(extensioncapabilities.PipelineWatcher); ok { if err := pw.Ready(); err != nil { return fmt.Errorf("failed to notify extension %q: %w", extID, err) } @@ -105,7 +106,7 @@ func (bes *Extensions) NotifyPipelineNotReady() error { var errs error for _, extID := range bes.extensionIDs { ext := bes.extMap[extID] - if pw, ok := ext.(extension.PipelineWatcher); ok { + if pw, ok := ext.(extensioncapabilities.PipelineWatcher); ok { errs = multierr.Append(errs, pw.NotReady()) } } @@ -116,7 +117,7 @@ func (bes *Extensions) NotifyConfig(ctx context.Context, conf *confmap.Conf) err var errs error for _, extID := range bes.extensionIDs { ext := bes.extMap[extID] - if cw, ok := ext.(extension.ConfigWatcher); ok { + if cw, ok := ext.(extensioncapabilities.ConfigWatcher); ok { clonedConf := confmap.NewFromStringMap(conf.ToStringMap()) errs = multierr.Append(errs, cw.NotifyConfig(ctx, clonedConf)) } diff --git a/service/extensions/extensions_test.go b/service/extensions/extensions_test.go index 96bfa36071d..1dd86596def 100644 --- a/service/extensions/extensions_test.go +++ b/service/extensions/extensions_test.go @@ -17,6 +17,7 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/extension/extensioncapabilities" "go.opentelemetry.io/collector/extension/extensiontest" "go.opentelemetry.io/collector/service/internal/builders" "go.opentelemetry.io/collector/service/internal/status" @@ -508,7 +509,7 @@ type recordingExtension struct { createSettings extension.Settings } -var _ extension.Dependent = (*recordingExtension)(nil) +var _ extensioncapabilities.Dependent = (*recordingExtension)(nil) func (ext *recordingExtension) Dependencies() []component.ID { if len(ext.config.dependencies) == 0 { diff --git a/service/extensions/graph.go b/service/extensions/graph.go index 7099d018a1f..f8bdde04889 100644 --- a/service/extensions/graph.go +++ b/service/extensions/graph.go @@ -13,7 +13,7 @@ import ( "gonum.org/v1/gonum/graph/topo" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/extension/extensioncapabilities" ) type node struct { @@ -38,7 +38,7 @@ func computeOrder(exts *Extensions) ([]component.ID, error) { } for extID, ext := range exts.extMap { n := nodes[extID] - if dep, ok := ext.(extension.Dependent); ok { + if dep, ok := ext.(extensioncapabilities.Dependent); ok { for _, depID := range dep.Dependencies() { if d, ok := nodes[depID]; ok { graph.SetEdge(graph.NewEdge(d, n)) diff --git a/service/go.mod b/service/go.mod index 676c4e12f63..38c63585b21 100644 --- a/service/go.mod +++ b/service/go.mod @@ -24,6 +24,7 @@ require ( go.opentelemetry.io/collector/exporter v0.108.1 go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 go.opentelemetry.io/collector/extension v0.108.1 + go.opentelemetry.io/collector/extension/extensioncapabilities v0.108.1 go.opentelemetry.io/collector/extension/zpagesextension v0.108.1 go.opentelemetry.io/collector/featuregate v1.14.1 go.opentelemetry.io/collector/internal/globalgates v0.108.1 @@ -152,6 +153,8 @@ replace go.opentelemetry.io/collector/extension/auth => ../extension/auth replace go.opentelemetry.io/collector/extension/experimental/storage => ../extension/experimental/storage +replace go.opentelemetry.io/collector/extension/extensioncapabilities => ../extension/extensioncapabilities + replace go.opentelemetry.io/collector/config/configopaque => ../config/configopaque replace go.opentelemetry.io/collector/config/confighttp => ../config/confighttp diff --git a/versions.yaml b/versions.yaml index 5c948f13f6f..d488a9560c9 100644 --- a/versions.yaml +++ b/versions.yaml @@ -49,6 +49,7 @@ module-sets: - go.opentelemetry.io/collector/exporter/otlpexporter - go.opentelemetry.io/collector/exporter/otlphttpexporter - go.opentelemetry.io/collector/extension + - go.opentelemetry.io/collector/extension/extensioncapabilities - go.opentelemetry.io/collector/extension/auth - go.opentelemetry.io/collector/extension/experimental/storage - go.opentelemetry.io/collector/extension/zpagesextension