From 099fc0fa2cedfdf8443c140fcb103e9d3fe7cf34 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Wed, 18 Sep 2024 10:44:12 +0100 Subject: [PATCH] chore: Remove unused OTEL flags --- serve/opentelemetry.go | 46 +----------------------------------------- serve/plugin.go | 6 +----- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/serve/opentelemetry.go b/serve/opentelemetry.go index 667ae9f72d..4e5b777c2f 100644 --- a/serve/opentelemetry.go +++ b/serve/opentelemetry.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "reflect" - "strings" "time" "github.com/cloudquery/plugin-sdk/v4/plugin" @@ -41,23 +40,9 @@ func newResource(p *plugin.Plugin) *resource.Resource { return r } -func parseOtelHeaders(headers []string) map[string]string { - headerMap := make(map[string]string, len(headers)) - for _, h := range headers { - parts := strings.SplitN(h, ":", 2) - if len(parts) != 2 { - continue - } - headerMap[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1]) - } - return headerMap -} - type otelConfig struct { endpoint string insecure bool - headers []string - urlPath string } func getTraceExporter(ctx context.Context, opts otelConfig) (*otlptrace.Exporter, error) { @@ -73,15 +58,6 @@ func getTraceExporter(ctx context.Context, opts otelConfig) (*otlptrace.Exporter traceOptions = append(traceOptions, otlptracehttp.WithInsecure()) } - if len(opts.headers) > 0 { - headers := parseOtelHeaders(opts.headers) - traceOptions = append(traceOptions, otlptracehttp.WithHeaders(headers)) - } - - if opts.urlPath != "" { - traceOptions = append(traceOptions, otlptracehttp.WithURLPath(opts.urlPath)) - } - traceClient := otlptracehttp.NewClient(traceOptions...) traceExporter, err := otlptrace.New(ctx, traceClient) if err != nil { @@ -104,15 +80,6 @@ func getMetricReader(ctx context.Context, opts otelConfig) (*metric.PeriodicRead metricOptions = append(metricOptions, otlpmetrichttp.WithInsecure()) } - if len(opts.headers) > 0 { - headers := parseOtelHeaders(opts.headers) - metricOptions = append(metricOptions, otlpmetrichttp.WithHeaders(headers)) - } - - if opts.urlPath != "" { - metricOptions = append(metricOptions, otlpmetrichttp.WithURLPath(opts.urlPath)) - } - metricExporter, err := otlpmetrichttp.New(ctx, metricOptions...) if err != nil { return nil, fmt.Errorf("creating OTLP metric exporter: %w", err) @@ -136,15 +103,6 @@ func getLogsProcessor(ctx context.Context, opts otelConfig) (*log.BatchProcessor logOptions = append(logOptions, otlploghttp.WithInsecure()) } - if len(opts.headers) > 0 { - headers := parseOtelHeaders(opts.headers) - logOptions = append(logOptions, otlploghttp.WithHeaders(headers)) - } - - if opts.urlPath != "" { - logOptions = append(logOptions, otlploghttp.WithURLPath(opts.urlPath)) - } - exporter, err := otlploghttp.New(ctx, logOptions...) if err != nil { return nil, fmt.Errorf("creating OTLP log exporter: %w", err) @@ -154,15 +112,13 @@ func getLogsProcessor(ctx context.Context, opts otelConfig) (*log.BatchProcessor return processor, nil } -func setupOtel(ctx context.Context, logger zerolog.Logger, p *plugin.Plugin, otelEndpoint string, otelEndpointInsecure bool, otelEndpointHeaders []string, otelEndpointURLPath string) (shutdown func(), err error) { +func setupOtel(ctx context.Context, logger zerolog.Logger, p *plugin.Plugin, otelEndpoint string, otelEndpointInsecure bool) (shutdown func(), err error) { if otelEndpoint == "" { return nil, nil } opts := otelConfig{ endpoint: otelEndpoint, insecure: otelEndpointInsecure, - headers: otelEndpointHeaders, - urlPath: otelEndpointURLPath, } traceExporter, err := getTraceExporter(ctx, opts) if err != nil { diff --git a/serve/plugin.go b/serve/plugin.go index 904b486cf5..6efde17940 100644 --- a/serve/plugin.go +++ b/serve/plugin.go @@ -106,9 +106,7 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command { var network string var noSentry bool var otelEndpoint string - var otelEndpointHeaders []string var otelEndpointInsecure bool - var otelEndpointURLPath string var licenseFile string logLevel := newEnum([]string{"trace", "debug", "info", "warn", "error"}, "info") logFormat := newEnum([]string{"text", "json"}, "text") @@ -136,7 +134,7 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command { logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout}).Level(zerologLevel) } - shutdown, err := setupOtel(cmd.Context(), logger, s.plugin, otelEndpoint, otelEndpointInsecure, otelEndpointHeaders, otelEndpointURLPath) + shutdown, err := setupOtel(cmd.Context(), logger, s.plugin, otelEndpoint, otelEndpointInsecure) if err != nil { return fmt.Errorf("failed to setup OpenTelemetry: %w", err) } @@ -234,8 +232,6 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command { cmd.Flags().Var(logLevel, "log-level", fmt.Sprintf("log level. one of: %s", strings.Join(logLevel.Allowed, ","))) cmd.Flags().Var(logFormat, "log-format", fmt.Sprintf("log format. one of: %s", strings.Join(logFormat.Allowed, ","))) cmd.Flags().StringVar(&otelEndpoint, "otel-endpoint", "", "Open Telemetry HTTP collector endpoint") - cmd.Flags().StringVar(&otelEndpointURLPath, "otel-endpoint-urlpath", "", "Open Telemetry HTTP collector endpoint URL path") - cmd.Flags().StringArrayVar(&otelEndpointHeaders, "otel-endpoint-headers", []string{}, "Open Telemetry HTTP collector endpoint headers") cmd.Flags().BoolVar(&otelEndpointInsecure, "otel-endpoint-insecure", false, "use Open Telemetry HTTP endpoint (for development only)") cmd.Flags().BoolVar(&noSentry, "no-sentry", false, "disable sentry") cmd.Flags().StringVar(&licenseFile, "license", "", "Path to offline license file or directory")