Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote tap extension rework #34872

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions extension/remotetapextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- end autogenerated section -->

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:

Expand Down
5 changes: 4 additions & 1 deletion extension/remotetapextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
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
}

func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
Endpoint: "127.0.0.1:11000",
Endpoint: localhostgate.EndpointForPort(11000),
},
}
}
47 changes: 38 additions & 9 deletions extension/remotetapextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion extension/remotetapextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions extension/remotetapextension/generated_package_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions extension/remotetapextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions extension/remotetapextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extension/remotetapextension/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ status:
development: [extension]
distributions: []
codeowners:
active: [atoulme]
active: [atoulme, wildum]

tests:
config:
Loading