From 07f1cd45f3147177e7efc7dfe555f3a40efb2224 Mon Sep 17 00:00:00 2001 From: William Dumont Date: Tue, 27 Aug 2024 14:59:00 +0200 Subject: [PATCH] remote tap extension rework --- extension/remotetapextension/README.md | 6 +-- extension/remotetapextension/config.go | 5 +- extension/remotetapextension/extension.go | 47 +++++++++++++++---- extension/remotetapextension/factory.go | 2 +- .../generated_package_test.go | 3 +- extension/remotetapextension/go.mod | 8 +++- extension/remotetapextension/go.sum | 7 +++ extension/remotetapextension/metadata.yaml | 2 +- 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/extension/remotetapextension/README.md b/extension/remotetapextension/README.md index c27be88469f6..34696b7dc3eb 100644 --- a/extension/remotetapextension/README.md +++ b/extension/remotetapextension/README.md @@ -6,14 +6,12 @@ | Stability | [development] | | Distributions | [] | | Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fremotetap%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fremotetap) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fremotetap%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fremotetap) | -| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@atoulme](https://www.github.com/atoulme) | +| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@atoulme](https://www.github.com/atoulme), [@wildum](https://www.github.com/wildum) | [development]: https://github.com/open-telemetry/opentelemetry-collector#development -This extension runs as a Web server that loads the remote observers that are registered against it. - -It allows users of the collectors to visualize data going through pipelines. +This extension runs as a Web server and allows users to visualize data going through pipelines. The following settings are required: diff --git a/extension/remotetapextension/config.go b/extension/remotetapextension/config.go index a9942dc4977f..6d8d081d8860 100644 --- a/extension/remotetapextension/config.go +++ b/extension/remotetapextension/config.go @@ -4,10 +4,13 @@ package remotetapextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension" import ( + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/localhostgate" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" ) +type CallbackID string + type Config struct { confighttp.ServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct } @@ -15,7 +18,7 @@ type Config struct { func createDefaultConfig() component.Config { return &Config{ ServerConfig: confighttp.ServerConfig{ - Endpoint: "127.0.0.1:11000", + Endpoint: localhostgate.EndpointForPort(11000), }, } } diff --git a/extension/remotetapextension/extension.go b/extension/remotetapextension/extension.go index acea71adc3ff..ab71482c3558 100644 --- a/extension/remotetapextension/extension.go +++ b/extension/remotetapextension/extension.go @@ -6,47 +6,76 @@ package remotetapextension // import "github.com/open-telemetry/opentelemetry-co import ( "context" "embed" - "errors" + "fmt" "io/fs" "net/http" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/extension" + "go.opentelemetry.io/collector/pdata/plog" + "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/collector/pdata/ptrace" ) //go:embed http/* var httpFS embed.FS -type remoteObserverExtension struct { +type remoteTapExtension struct { config *Config settings extension.Settings server *http.Server } -func (s *remoteObserverExtension) Start(ctx context.Context, host component.Host) error { +type ComponentID string +// TODO: the extension should implement this interface when available in core +// var _ pdata.Publisher = &remoteTapExtension{} + +func (s *remoteTapExtension) Start(ctx context.Context, host component.Host) error { htmlContent, err := fs.Sub(httpFS, "html") if err != nil { return err } mux := http.NewServeMux() mux.Handle("/", http.FileServer(http.FS(htmlContent))) + + ln, err := s.config.ServerConfig.ToListener(ctx) + if err != nil { + return fmt.Errorf("failed to bind to address %s: %w", s.config.Endpoint, err) + } + s.server, err = s.config.ServerConfig.ToServer(ctx, host, s.settings.TelemetrySettings, mux) if err != nil { return err } go func() { - err := s.server.ListenAndServe() - if err != nil && !errors.Is(err, http.ErrServerClosed) { - componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err)) - } + s.server.Serve(ln) }() return nil } -func (s *remoteObserverExtension) Shutdown(_ context.Context) error { +// IsActive returns true when at least one connection is open for the given componentID. +func (s *remoteTapExtension) IsActive(componentID ComponentID) bool { + return false +} + +// PublishMetrics sends metrics for a given componentID. +func (s *remoteTapExtension) PublishMetrics(componentID ComponentID, md pmetric.Metrics) { + // TODO: do something with the metrics +} + +// PublishTraces sends traces for a given componentID. +func (s *remoteTapExtension) PublishTraces(componentID ComponentID, td ptrace.Traces) { + // TODO: do something with the traces +} + +// PublishLogs sends logs for a given componentID. +func (s *remoteTapExtension) PublishLogs(componentID ComponentID, ld plog.Logs) { + // TODO: do something with the logs +} + +func (s *remoteTapExtension) Shutdown(_ context.Context) error { if s.server == nil { return nil } diff --git a/extension/remotetapextension/factory.go b/extension/remotetapextension/factory.go index f990064c5164..133a5ff99c42 100644 --- a/extension/remotetapextension/factory.go +++ b/extension/remotetapextension/factory.go @@ -22,5 +22,5 @@ func NewFactory() extension.Factory { } func createExtension(_ context.Context, settings extension.Settings, config component.Config) (extension.Extension, error) { - return &remoteObserverExtension{config: config.(*Config), settings: settings}, nil + return &remoteTapExtension{config: config.(*Config), settings: settings}, nil } diff --git a/extension/remotetapextension/generated_package_test.go b/extension/remotetapextension/generated_package_test.go index 5b107f66be70..978955bbb8c7 100644 --- a/extension/remotetapextension/generated_package_test.go +++ b/extension/remotetapextension/generated_package_test.go @@ -3,9 +3,8 @@ package remotetapextension import ( - "testing" - "go.uber.org/goleak" + "testing" ) func TestMain(m *testing.M) { diff --git a/extension/remotetapextension/go.mod b/extension/remotetapextension/go.mod index 4435ed8fd5f3..4db37d58c1fb 100644 --- a/extension/remotetapextension/go.mod +++ b/extension/remotetapextension/go.mod @@ -3,12 +3,13 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/extension/remot go 1.22.0 require ( + github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.107.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.107.1-0.20240827012220-5963d446ca4a - go.opentelemetry.io/collector/component/componentstatus v0.107.1-0.20240827012220-5963d446ca4a go.opentelemetry.io/collector/config/confighttp v0.107.1-0.20240827012220-5963d446ca4a go.opentelemetry.io/collector/confmap v0.107.1-0.20240827012220-5963d446ca4a go.opentelemetry.io/collector/extension v0.107.1-0.20240827012220-5963d446ca4a + go.opentelemetry.io/collector/pdata v1.13.1-0.20240827012220-5963d446ca4a go.uber.org/goleak v1.3.0 ) @@ -25,12 +26,15 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.9 // 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 + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.20.1 // indirect @@ -40,6 +44,7 @@ require ( github.com/rs/cors v1.11.0 // indirect go.opentelemetry.io/collector v0.107.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/client v1.13.1-0.20240827012220-5963d446ca4a // indirect + go.opentelemetry.io/collector/component/componentstatus v0.107.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/config/configauth v0.107.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/config/configcompression v1.13.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/config/configopaque v1.13.1-0.20240827012220-5963d446ca4a // indirect @@ -48,7 +53,6 @@ require ( go.opentelemetry.io/collector/config/internal v0.107.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/extension/auth v0.107.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/collector/featuregate v1.13.1-0.20240827012220-5963d446ca4a // indirect - go.opentelemetry.io/collector/pdata v1.13.1-0.20240827012220-5963d446ca4a // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect diff --git a/extension/remotetapextension/go.sum b/extension/remotetapextension/go.sum index 08df4b8b3822..c638460d2257 100644 --- a/extension/remotetapextension/go.sum +++ b/extension/remotetapextension/go.sum @@ -2,6 +2,7 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= @@ -21,6 +22,7 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 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/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= @@ -47,12 +49,15 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 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/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.107.0 h1:NKH1JyZbqUSDGbIVqTyGJclmdnp6v4TQYfLhNI4tZno= +github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.107.0/go.mod h1:xVn35KHNAGc2JlBhv1BhAIB6F0NkHK+rrDUsibaxRW8= 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/prometheus/client_golang v1.20.1 h1:IMJXHOD6eARkQpxo8KkhgEVFlBNm+nkrFUyGlIu7Na8= @@ -67,6 +72,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po= github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 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= diff --git a/extension/remotetapextension/metadata.yaml b/extension/remotetapextension/metadata.yaml index e0396b389485..5cd67b691ec0 100644 --- a/extension/remotetapextension/metadata.yaml +++ b/extension/remotetapextension/metadata.yaml @@ -6,7 +6,7 @@ status: development: [extension] distributions: [] codeowners: - active: [atoulme] + active: [atoulme, wildum] tests: config: