diff --git a/.golangci.yml b/.golangci.yml index 7b92f5aa8..25de20ba1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -263,7 +263,7 @@ linters: - path: pkg/provider/kubernetes/(crd|gateway)/client.go linters: - interfacebloat - - path: pkg/metrics/metrics.go + - path: pkg/observability/metrics/metrics.go linters: - interfacebloat - path: integration/healthcheck_test.go diff --git a/cmd/traefik/logger.go b/cmd/traefik/logger.go index 5e84e9118..2f1d1b8a0 100644 --- a/cmd/traefik/logger.go +++ b/cmd/traefik/logger.go @@ -14,7 +14,7 @@ import ( "github.com/rs/zerolog/log" "github.com/sirupsen/logrus" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "gopkg.in/natefinch/lumberjack.v2" ) diff --git a/cmd/traefik/plugins.go b/cmd/traefik/plugins.go index ef939d2a0..2c19cb365 100644 --- a/cmd/traefik/plugins.go +++ b/cmd/traefik/plugins.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/go-retryablehttp" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/plugins" ) diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 97d70747c..8c2cab62c 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -30,9 +30,11 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/metrics" + "github.com/traefik/traefik/v3/pkg/observability/tracing" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/provider/acme" "github.com/traefik/traefik/v3/pkg/provider/aggregator" "github.com/traefik/traefik/v3/pkg/provider/tailscale" @@ -46,8 +48,6 @@ import ( "github.com/traefik/traefik/v3/pkg/server/service" "github.com/traefik/traefik/v3/pkg/tcp" traefiktls "github.com/traefik/traefik/v3/pkg/tls" - "github.com/traefik/traefik/v3/pkg/tracing" - "github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/version" ) @@ -505,7 +505,7 @@ func initTailscaleProviders(cfg *static.Configuration, providerAggregator *aggre return providers } -func registerMetricClients(metricsConfig *types.Metrics) []metrics.Registry { +func registerMetricClients(metricsConfig *otypes.Metrics) []metrics.Registry { if metricsConfig == nil { return nil } @@ -586,7 +586,7 @@ func appendCertMetric(gauge gokitmetrics.Gauge, certificate *x509.Certificate) { gauge.With(labels...).Set(notAfter) } -func setupAccessLog(ctx context.Context, conf *types.AccessLog) *accesslog.Handler { +func setupAccessLog(ctx context.Context, conf *otypes.AccessLog) *accesslog.Handler { if conf == nil { return nil } diff --git a/pkg/api/handler_overview_test.go b/pkg/api/handler_overview_test.go index d3ef01f72..7b07106b9 100644 --- a/pkg/api/handler_overview_test.go +++ b/pkg/api/handler_overview_test.go @@ -13,12 +13,12 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/config/static" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/provider/docker" "github.com/traefik/traefik/v3/pkg/provider/file" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/ingress" "github.com/traefik/traefik/v3/pkg/provider/rest" - "github.com/traefik/traefik/v3/pkg/types" ) func TestHandler_Overview(t *testing.T) { @@ -255,8 +255,8 @@ func TestHandler_Overview(t *testing.T) { confStatic: static.Configuration{ Global: &static.Global{}, API: &static.API{}, - Metrics: &types.Metrics{ - Prometheus: &types.Prometheus{}, + Metrics: &otypes.Metrics{ + Prometheus: &otypes.Prometheus{}, }, Tracing: &static.Tracing{}, }, diff --git a/pkg/config/dynamic/http_config.go b/pkg/config/dynamic/http_config.go index 6393c9c03..96e16f7b4 100644 --- a/pkg/config/dynamic/http_config.go +++ b/pkg/config/dynamic/http_config.go @@ -5,6 +5,7 @@ import ( "time" ptypes "github.com/traefik/paerser/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" "google.golang.org/grpc/codes" @@ -97,12 +98,12 @@ type RouterObservabilityConfig struct { // TraceVerbosity defines the verbosity level of the tracing for this router. // +kubebuilder:validation:Enum=minimal;detailed // +kubebuilder:default=minimal - TraceVerbosity types.TracingVerbosity `json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` + TraceVerbosity otypes.TracingVerbosity `json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` } // SetDefaults Default values for a RouterObservabilityConfig. func (r *RouterObservabilityConfig) SetDefaults() { - r.TraceVerbosity = types.MinimalVerbosity + r.TraceVerbosity = otypes.MinimalVerbosity } // +k8s:deepcopy-gen=true diff --git a/pkg/config/runtime/runtime.go b/pkg/config/runtime/runtime.go index 4034fa077..7e8db0a5e 100644 --- a/pkg/config/runtime/runtime.go +++ b/pkg/config/runtime/runtime.go @@ -6,7 +6,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // Status of the router/service. diff --git a/pkg/config/runtime/runtime_http.go b/pkg/config/runtime/runtime_http.go index 97a89f066..69d7e540f 100644 --- a/pkg/config/runtime/runtime_http.go +++ b/pkg/config/runtime/runtime_http.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // GetRoutersByEntryPoints returns all the http routers by entry points name and routers name. diff --git a/pkg/config/runtime/runtime_tcp.go b/pkg/config/runtime/runtime_tcp.go index 1c213f7b1..b8bc08981 100644 --- a/pkg/config/runtime/runtime_tcp.go +++ b/pkg/config/runtime/runtime_tcp.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // GetTCPRoutersByEntryPoints returns all the tcp routers by entry points name and routers name. diff --git a/pkg/config/runtime/runtime_udp.go b/pkg/config/runtime/runtime_udp.go index e1a867506..912f986f1 100644 --- a/pkg/config/runtime/runtime_udp.go +++ b/pkg/config/runtime/runtime_udp.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // GetUDPRoutersByEntryPoints returns all the UDP routers by entry points name and routers name. diff --git a/pkg/config/static/entrypoints.go b/pkg/config/static/entrypoints.go index 3ac50e048..ed1eb008b 100644 --- a/pkg/config/static/entrypoints.go +++ b/pkg/config/static/entrypoints.go @@ -7,6 +7,7 @@ import ( "strings" ptypes "github.com/traefik/paerser/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/types" ) @@ -165,10 +166,10 @@ func (u *UDPConfig) SetDefaults() { // ObservabilityConfig holds the observability configuration for an entry point. type ObservabilityConfig struct { - AccessLogs *bool `description:"Enables access-logs for this entryPoint." json:"accessLogs,omitempty" toml:"accessLogs,omitempty" yaml:"accessLogs,omitempty" export:"true"` - Metrics *bool `description:"Enables metrics for this entryPoint." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` - Tracing *bool `description:"Enables tracing for this entryPoint." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" export:"true"` - TraceVerbosity types.TracingVerbosity `description:"Defines the tracing verbosity level for this entryPoint." json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` + AccessLogs *bool `description:"Enables access-logs for this entryPoint." json:"accessLogs,omitempty" toml:"accessLogs,omitempty" yaml:"accessLogs,omitempty" export:"true"` + Metrics *bool `description:"Enables metrics for this entryPoint." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` + Tracing *bool `description:"Enables tracing for this entryPoint." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" export:"true"` + TraceVerbosity otypes.TracingVerbosity `description:"Defines the tracing verbosity level for this entryPoint." json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` } // SetDefaults sets the default values. @@ -177,5 +178,5 @@ func (o *ObservabilityConfig) SetDefaults() { o.AccessLogs = &defaultValue o.Metrics = &defaultValue o.Tracing = &defaultValue - o.TraceVerbosity = types.MinimalVerbosity + o.TraceVerbosity = otypes.MinimalVerbosity } diff --git a/pkg/config/static/static_config.go b/pkg/config/static/static_config.go index f236da3fb..33729e069 100644 --- a/pkg/config/static/static_config.go +++ b/pkg/config/static/static_config.go @@ -11,7 +11,8 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/ping" acmeprovider "github.com/traefik/traefik/v3/pkg/provider/acme" "github.com/traefik/traefik/v3/pkg/provider/consulcatalog" @@ -64,13 +65,13 @@ type Configuration struct { EntryPoints EntryPoints `description:"Entry points definition." json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"` Providers *Providers `description:"Providers configuration." json:"providers,omitempty" toml:"providers,omitempty" yaml:"providers,omitempty" export:"true"` - API *API `description:"Enable api/dashboard." json:"api,omitempty" toml:"api,omitempty" yaml:"api,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` - Metrics *types.Metrics `description:"Enable a metrics exporter." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` - Ping *ping.Handler `description:"Enable ping." json:"ping,omitempty" toml:"ping,omitempty" yaml:"ping,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + API *API `description:"Enable api/dashboard." json:"api,omitempty" toml:"api,omitempty" yaml:"api,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + Metrics *otypes.Metrics `description:"Enable a metrics exporter." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` + Ping *ping.Handler `description:"Enable ping." json:"ping,omitempty" toml:"ping,omitempty" yaml:"ping,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` - Log *types.TraefikLog `description:"Traefik log settings." json:"log,omitempty" toml:"log,omitempty" yaml:"log,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` - AccessLog *types.AccessLog `description:"Access log settings." json:"accessLog,omitempty" toml:"accessLog,omitempty" yaml:"accessLog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` - Tracing *Tracing `description:"Tracing configuration." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + Log *otypes.TraefikLog `description:"Traefik log settings." json:"log,omitempty" toml:"log,omitempty" yaml:"log,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + AccessLog *otypes.AccessLog `description:"Access log settings." json:"accessLog,omitempty" toml:"accessLog,omitempty" yaml:"accessLog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + Tracing *Tracing `description:"Tracing configuration." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` HostResolver *types.HostResolverConfig `description:"Enable CNAME Flattening." json:"hostResolver,omitempty" toml:"hostResolver,omitempty" yaml:"hostResolver,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` @@ -205,14 +206,14 @@ func (a *LifeCycle) SetDefaults() { // Tracing holds the tracing configuration. type Tracing struct { - ServiceName string `description:"Defines the service name resource attribute." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"` - ResourceAttributes map[string]string `description:"Defines additional resource attributes (key:value)." json:"resourceAttributes,omitempty" toml:"resourceAttributes,omitempty" yaml:"resourceAttributes,omitempty" export:"true"` - CapturedRequestHeaders []string `description:"Request headers to add as attributes for server and client spans." json:"capturedRequestHeaders,omitempty" toml:"capturedRequestHeaders,omitempty" yaml:"capturedRequestHeaders,omitempty" export:"true"` - CapturedResponseHeaders []string `description:"Response headers to add as attributes for server and client spans." json:"capturedResponseHeaders,omitempty" toml:"capturedResponseHeaders,omitempty" yaml:"capturedResponseHeaders,omitempty" export:"true"` - SafeQueryParams []string `description:"Query params to not redact." json:"safeQueryParams,omitempty" toml:"safeQueryParams,omitempty" yaml:"safeQueryParams,omitempty" export:"true"` - SampleRate float64 `description:"Sets the rate between 0.0 and 1.0 of requests to trace." json:"sampleRate,omitempty" toml:"sampleRate,omitempty" yaml:"sampleRate,omitempty" export:"true"` - AddInternals bool `description:"Enables tracing for internal services (ping, dashboard, etc...)." json:"addInternals,omitempty" toml:"addInternals,omitempty" yaml:"addInternals,omitempty" export:"true"` - OTLP *types.OTelTracing `description:"Settings for OpenTelemetry." json:"otlp,omitempty" toml:"otlp,omitempty" yaml:"otlp,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` + ServiceName string `description:"Defines the service name resource attribute." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"` + ResourceAttributes map[string]string `description:"Defines additional resource attributes (key:value)." json:"resourceAttributes,omitempty" toml:"resourceAttributes,omitempty" yaml:"resourceAttributes,omitempty" export:"true"` + CapturedRequestHeaders []string `description:"Request headers to add as attributes for server and client spans." json:"capturedRequestHeaders,omitempty" toml:"capturedRequestHeaders,omitempty" yaml:"capturedRequestHeaders,omitempty" export:"true"` + CapturedResponseHeaders []string `description:"Response headers to add as attributes for server and client spans." json:"capturedResponseHeaders,omitempty" toml:"capturedResponseHeaders,omitempty" yaml:"capturedResponseHeaders,omitempty" export:"true"` + SafeQueryParams []string `description:"Query params to not redact." json:"safeQueryParams,omitempty" toml:"safeQueryParams,omitempty" yaml:"safeQueryParams,omitempty" export:"true"` + SampleRate float64 `description:"Sets the rate between 0.0 and 1.0 of requests to trace." json:"sampleRate,omitempty" toml:"sampleRate,omitempty" yaml:"sampleRate,omitempty" export:"true"` + AddInternals bool `description:"Enables tracing for internal services (ping, dashboard, etc...)." json:"addInternals,omitempty" toml:"addInternals,omitempty" yaml:"addInternals,omitempty" export:"true"` + OTLP *otypes.OTelTracing `description:"Settings for OpenTelemetry." json:"otlp,omitempty" toml:"otlp,omitempty" yaml:"otlp,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` // Deprecated: please use ResourceAttributes instead. GlobalAttributes map[string]string `description:"(Deprecated) Defines additional resource attributes (key:value)." json:"globalAttributes,omitempty" toml:"globalAttributes,omitempty" yaml:"globalAttributes,omitempty" export:"true"` @@ -223,7 +224,7 @@ func (t *Tracing) SetDefaults() { t.ServiceName = "traefik" t.SampleRate = 1.0 - t.OTLP = &types.OTelTracing{} + t.OTLP = &otypes.OTelTracing{} t.OTLP.SetDefaults() } diff --git a/pkg/middlewares/accesslog/field_middleware.go b/pkg/middlewares/accesslog/field_middleware.go index d1b39438f..4d439bc25 100644 --- a/pkg/middlewares/accesslog/field_middleware.go +++ b/pkg/middlewares/accesslog/field_middleware.go @@ -5,8 +5,8 @@ import ( "time" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares/capture" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/vulcand/oxy/v2/utils" ) diff --git a/pkg/middlewares/accesslog/logger.go b/pkg/middlewares/accesslog/logger.go index 06d58cac4..5f21afc09 100644 --- a/pkg/middlewares/accesslog/logger.go +++ b/pkg/middlewares/accesslog/logger.go @@ -19,9 +19,10 @@ import ( "github.com/rs/zerolog/log" "github.com/sirupsen/logrus" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/observability" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" "go.opentelemetry.io/contrib/bridges/otellogrus" @@ -64,7 +65,7 @@ type handlerParams struct { // Handler will write each request and its response to the access log. type Handler struct { - config *types.AccessLog + config *otypes.AccessLog logger *logrus.Logger file io.WriteCloser mu sync.Mutex @@ -88,7 +89,7 @@ func (h *Handler) AliceConstructor() alice.Constructor { } // NewHandler creates a new Handler. -func NewHandler(ctx context.Context, config *types.AccessLog) (*Handler, error) { +func NewHandler(ctx context.Context, config *otypes.AccessLog) (*Handler, error) { var file io.WriteCloser = noopCloser{os.Stdout} if len(config.FilePath) > 0 { f, err := openAccessLogFile(config.FilePath) @@ -423,9 +424,9 @@ func (h *Handler) redactHeaders(headers http.Header, fields logrus.Fields, prefi for k := range headers { v := h.config.Fields.KeepHeader(k) switch v { - case types.AccessLogKeep: + case otypes.AccessLogKeep: fields[prefix+k] = strings.Join(headers.Values(k), ",") - case types.AccessLogRedact: + case otypes.AccessLogRedact: fields[prefix+k] = "REDACTED" } } diff --git a/pkg/middlewares/accesslog/logger_test.go b/pkg/middlewares/accesslog/logger_test.go index 341868c79..2da72991e 100644 --- a/pkg/middlewares/accesslog/logger_test.go +++ b/pkg/middlewares/accesslog/logger_test.go @@ -26,7 +26,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/observability" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/collector/pdata/plog/plogotlp" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" @@ -117,12 +117,12 @@ func TestOTelAccessLogWithBody(t *testing.T) { })) t.Cleanup(collector.Close) - config := &types.AccessLog{ + config := &otypes.AccessLog{ Format: test.format, - OTLP: &types.OTelLog{ + OTLP: &otypes.OTelLog{ ServiceName: "test", ResourceAttributes: map[string]string{"resource": "attribute"}, - HTTP: &types.OTelHTTP{ + HTTP: &otypes.OTelHTTP{ Endpoint: collector.URL, }, }, @@ -188,7 +188,7 @@ func TestLogRotation(t *testing.T) { fileName := filepath.Join(t.TempDir(), "traefik.log") rotatedFileName := fileName + ".rotated" - config := &types.AccessLog{FilePath: fileName, Format: CommonFormat} + config := &otypes.AccessLog{FilePath: fileName, Format: CommonFormat} logHandler, err := NewHandler(t.Context(), config) require.NoError(t, err) t.Cleanup(func() { @@ -276,18 +276,18 @@ func TestLoggerHeaderFields(t *testing.T) { testCases := []struct { desc string - accessLogFields types.AccessLogFields + accessLogFields otypes.AccessLogFields header string expected string }{ { desc: "with default mode", header: "User-Agent", - expected: types.AccessLogDrop, - accessLogFields: types.AccessLogFields{ - DefaultMode: types.AccessLogDrop, - Headers: &types.FieldHeaders{ - DefaultMode: types.AccessLogDrop, + expected: otypes.AccessLogDrop, + accessLogFields: otypes.AccessLogFields{ + DefaultMode: otypes.AccessLogDrop, + Headers: &otypes.FieldHeaders{ + DefaultMode: otypes.AccessLogDrop, Names: map[string]string{}, }, }, @@ -295,13 +295,13 @@ func TestLoggerHeaderFields(t *testing.T) { { desc: "with exact header name", header: "User-Agent", - expected: types.AccessLogKeep, - accessLogFields: types.AccessLogFields{ - DefaultMode: types.AccessLogDrop, - Headers: &types.FieldHeaders{ - DefaultMode: types.AccessLogDrop, + expected: otypes.AccessLogKeep, + accessLogFields: otypes.AccessLogFields{ + DefaultMode: otypes.AccessLogDrop, + Headers: &otypes.FieldHeaders{ + DefaultMode: otypes.AccessLogDrop, Names: map[string]string{ - "User-Agent": types.AccessLogKeep, + "User-Agent": otypes.AccessLogKeep, }, }, }, @@ -309,13 +309,13 @@ func TestLoggerHeaderFields(t *testing.T) { { desc: "with case-insensitive match on header name", header: "User-Agent", - expected: types.AccessLogKeep, - accessLogFields: types.AccessLogFields{ - DefaultMode: types.AccessLogDrop, - Headers: &types.FieldHeaders{ - DefaultMode: types.AccessLogDrop, + expected: otypes.AccessLogKeep, + accessLogFields: otypes.AccessLogFields{ + DefaultMode: otypes.AccessLogDrop, + Headers: &otypes.FieldHeaders{ + DefaultMode: otypes.AccessLogDrop, Names: map[string]string{ - "user-agent": types.AccessLogKeep, + "user-agent": otypes.AccessLogKeep, }, }, }, @@ -327,7 +327,7 @@ func TestLoggerHeaderFields(t *testing.T) { logFile, err := os.CreateTemp(t.TempDir(), "*.log") require.NoError(t, err) - config := &types.AccessLog{ + config := &otypes.AccessLog{ FilePath: logFile.Name(), Format: CommonFormat, Fields: &test.accessLogFields, @@ -376,7 +376,7 @@ func TestLoggerHeaderFields(t *testing.T) { logData, err := os.ReadFile(logFile.Name()) require.NoError(t, err) - if test.expected == types.AccessLogDrop { + if test.expected == otypes.AccessLogDrop { assert.NotContains(t, string(logData), strings.Join(expectedValues, ",")) } else { assert.Contains(t, string(logData), strings.Join(expectedValues, ",")) @@ -387,7 +387,7 @@ func TestLoggerHeaderFields(t *testing.T) { func TestCommonLogger(t *testing.T) { logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) - config := &types.AccessLog{FilePath: logFilePath, Format: CommonFormat} + config := &otypes.AccessLog{FilePath: logFilePath, Format: CommonFormat} doLogging(t, config, false) logData, err := os.ReadFile(logFilePath) @@ -399,7 +399,7 @@ func TestCommonLogger(t *testing.T) { func TestCommonLoggerWithBufferingSize(t *testing.T) { logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) - config := &types.AccessLog{FilePath: logFilePath, Format: CommonFormat, BufferingSize: 1024} + config := &otypes.AccessLog{FilePath: logFilePath, Format: CommonFormat, BufferingSize: 1024} doLogging(t, config, false) // wait a bit for the buffer to be written in the file. @@ -414,7 +414,7 @@ func TestCommonLoggerWithBufferingSize(t *testing.T) { func TestLoggerGenericCLF(t *testing.T) { logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) - config := &types.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat} + config := &otypes.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat} doLogging(t, config, false) logData, err := os.ReadFile(logFilePath) @@ -426,7 +426,7 @@ func TestLoggerGenericCLF(t *testing.T) { func TestLoggerGenericCLFWithBufferingSize(t *testing.T) { logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) - config := &types.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat, BufferingSize: 1024} + config := &otypes.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat, BufferingSize: 1024} doLogging(t, config, false) // wait a bit for the buffer to be written in the file. @@ -474,14 +474,14 @@ func assertFloat64NotZero() func(t *testing.T, actual interface{}) { func TestLoggerJSON(t *testing.T) { testCases := []struct { desc string - config *types.AccessLog + config *otypes.AccessLog tls bool tracing bool expected map[string]func(t *testing.T, value interface{}) }{ { desc: "default config without tracing", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, }, @@ -520,7 +520,7 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config with tracing", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, }, @@ -562,7 +562,7 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config, with TLS request", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, }, @@ -605,10 +605,10 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config drop all fields", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", }, }, @@ -623,12 +623,12 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config drop all fields and headers", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "drop", }, }, @@ -641,12 +641,12 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config drop all fields and redact headers", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "redact", }, }, @@ -662,15 +662,15 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "default config drop all fields and headers but kept someone", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ RequestHost: "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "drop", Names: map[string]string{ "Referer": "keep", @@ -688,15 +688,15 @@ func TestLoggerJSON(t *testing.T) { }, { desc: "fields and headers with unconventional letter case", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: JSONFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ "rEqUeStHoSt": "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "drop", Names: map[string]string{ "ReFeReR": "keep", @@ -778,7 +778,7 @@ func TestLogger_AbortedRequest(t *testing.T) { "downstream_Cache-Control": assertString("no-cache"), } - config := &types.AccessLog{ + config := &otypes.AccessLog{ FilePath: filepath.Join(t.TempDir(), logFileNameSuffix), Format: JSONFormat, } @@ -804,12 +804,12 @@ func TestLogger_AbortedRequest(t *testing.T) { func TestNewLogHandlerOutputStdout(t *testing.T) { testCases := []struct { desc string - config *types.AccessLog + config *otypes.AccessLog expectedLog string }{ { desc: "default config", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, }, @@ -817,19 +817,19 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "default config with empty filters", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{}, + Filters: &otypes.AccessLogFilters{}, }, expectedLog: `TestHost - TestUser [13/Apr/2016:07:14:19 -0700] "POST testpath HTTP/0.0" 123 12 "testReferer" "testUserAgent" 23 "testRouter" "http://127.0.0.1/testService" 1ms`, }, { desc: "Status code filter not matching", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ StatusCodes: []string{"200"}, }, }, @@ -837,10 +837,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Status code filter matching", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ StatusCodes: []string{"123"}, }, }, @@ -848,10 +848,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Duration filter not matching", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ MinDuration: ptypes.Duration(1 * time.Hour), }, }, @@ -859,10 +859,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Duration filter matching", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ MinDuration: ptypes.Duration(1 * time.Millisecond), }, }, @@ -870,10 +870,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Retry attempts filter matching", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ RetryAttempts: true, }, }, @@ -881,10 +881,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode keep", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "keep", }, }, @@ -892,10 +892,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode keep with override", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "keep", Names: map[string]string{ ClientHost: "drop", @@ -906,10 +906,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode drop", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", }, }, @@ -917,10 +917,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode drop with override", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ ClientHost: "drop", @@ -932,16 +932,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode drop with header dropped", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ ClientHost: "drop", ClientUsername: "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "drop", }, }, @@ -950,16 +950,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode drop with header redacted", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ ClientHost: "drop", ClientUsername: "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "redact", }, }, @@ -968,16 +968,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { }, { desc: "Default mode drop with header redacted", - config: &types.AccessLog{ + config: &otypes.AccessLog{ FilePath: "", Format: CommonFormat, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ ClientHost: "drop", ClientUsername: "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "keep", Names: map[string]string{ "Referer": "redact", @@ -1084,7 +1084,7 @@ func captureStdout(t *testing.T) (out *os.File, restoreStdout func()) { return file, restoreStdout } -func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS, tracing bool) { +func doLoggingTLSOpt(t *testing.T, config *otypes.AccessLog, enableTLS, tracing bool) { t.Helper() logger, err := NewHandler(t.Context(), config) require.NoError(t, err) @@ -1145,13 +1145,13 @@ func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS, tracing b handler.ServeHTTP(httptest.NewRecorder(), req) } -func doLoggingTLS(t *testing.T, config *types.AccessLog, tracing bool) { +func doLoggingTLS(t *testing.T, config *otypes.AccessLog, tracing bool) { t.Helper() doLoggingTLSOpt(t, config, true, tracing) } -func doLogging(t *testing.T, config *types.AccessLog, tracing bool) { +func doLogging(t *testing.T, config *otypes.AccessLog, tracing bool) { t.Helper() doLoggingTLSOpt(t, config, false, tracing) @@ -1180,7 +1180,7 @@ func logWriterTestHandlerFunc(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(testStatus) } -func doLoggingWithAbortedStream(t *testing.T, config *types.AccessLog) { +func doLoggingWithAbortedStream(t *testing.T, config *otypes.AccessLog) { t.Helper() logger, err := NewHandler(t.Context(), config) diff --git a/pkg/middlewares/auth/forward.go b/pkg/middlewares/auth/forward.go index d30d33e2a..4438a486e 100644 --- a/pkg/middlewares/auth/forward.go +++ b/pkg/middlewares/auth/forward.go @@ -17,8 +17,8 @@ import ( "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog" "github.com/traefik/traefik/v3/pkg/middlewares/observability" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "github.com/traefik/traefik/v3/pkg/proxy/httputil" - "github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/types" "github.com/vulcand/oxy/v2/forward" "github.com/vulcand/oxy/v2/utils" diff --git a/pkg/middlewares/auth/forward_test.go b/pkg/middlewares/auth/forward_test.go index d3cdebd36..95e3d7910 100644 --- a/pkg/middlewares/auth/forward_test.go +++ b/pkg/middlewares/auth/forward_test.go @@ -17,9 +17,9 @@ import ( "github.com/stretchr/testify/require" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/middlewares/observability" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "github.com/traefik/traefik/v3/pkg/proxy/httputil" "github.com/traefik/traefik/v3/pkg/testhelpers" - "github.com/traefik/traefik/v3/pkg/tracing" "github.com/vulcand/oxy/v2/forward" "go.opentelemetry.io/contrib/propagators/autoprop" "go.opentelemetry.io/otel" diff --git a/pkg/middlewares/buffering/buffering.go b/pkg/middlewares/buffering/buffering.go index cb0fa3414..753436add 100644 --- a/pkg/middlewares/buffering/buffering.go +++ b/pkg/middlewares/buffering/buffering.go @@ -6,8 +6,8 @@ import ( "github.com/rs/zerolog" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" + "github.com/traefik/traefik/v3/pkg/observability/logs" oxybuffer "github.com/vulcand/oxy/v2/buffer" ) diff --git a/pkg/middlewares/circuitbreaker/circuit_breaker.go b/pkg/middlewares/circuitbreaker/circuit_breaker.go index c9b3546e3..72eecd428 100644 --- a/pkg/middlewares/circuitbreaker/circuit_breaker.go +++ b/pkg/middlewares/circuitbreaker/circuit_breaker.go @@ -8,9 +8,9 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/observability" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/vulcand/oxy/v2/cbreaker" ) diff --git a/pkg/middlewares/denyrouterrecursion/deny_router_recursion.go b/pkg/middlewares/denyrouterrecursion/deny_router_recursion.go index 34c6cd12d..a33f8c04b 100644 --- a/pkg/middlewares/denyrouterrecursion/deny_router_recursion.go +++ b/pkg/middlewares/denyrouterrecursion/deny_router_recursion.go @@ -8,7 +8,7 @@ import ( "github.com/containous/alice" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) const xTraefikRouter = "X-Traefik-Router" diff --git a/pkg/middlewares/inflightreq/inflight_req.go b/pkg/middlewares/inflightreq/inflight_req.go index 65a7457d3..e2df0bcbb 100644 --- a/pkg/middlewares/inflightreq/inflight_req.go +++ b/pkg/middlewares/inflightreq/inflight_req.go @@ -7,8 +7,8 @@ import ( "github.com/rs/zerolog" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/vulcand/oxy/v2/connlimit" ) diff --git a/pkg/middlewares/metrics/metrics.go b/pkg/middlewares/metrics/metrics.go index f7eb3b8ff..646220a13 100644 --- a/pkg/middlewares/metrics/metrics.go +++ b/pkg/middlewares/metrics/metrics.go @@ -12,11 +12,11 @@ import ( "github.com/containous/alice" gokitmetrics "github.com/go-kit/kit/metrics" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/retry" + "github.com/traefik/traefik/v3/pkg/observability/metrics" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "google.golang.org/grpc/codes" ) diff --git a/pkg/middlewares/middleware.go b/pkg/middlewares/middleware.go index 928a9982e..5b7cd6d70 100644 --- a/pkg/middlewares/middleware.go +++ b/pkg/middlewares/middleware.go @@ -5,7 +5,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // GetLogger creates a logger with the middleware fields. diff --git a/pkg/middlewares/observability/entrypoint.go b/pkg/middlewares/observability/entrypoint.go index fead7ec43..e9cd3f10f 100644 --- a/pkg/middlewares/observability/entrypoint.go +++ b/pkg/middlewares/observability/entrypoint.go @@ -8,7 +8,7 @@ import ( "github.com/containous/alice" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/middlewares" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" diff --git a/pkg/middlewares/observability/entrypoint_test.go b/pkg/middlewares/observability/entrypoint_test.go index 384d11a4c..2e02e15ce 100644 --- a/pkg/middlewares/observability/entrypoint_test.go +++ b/pkg/middlewares/observability/entrypoint_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" ) diff --git a/pkg/middlewares/observability/middleware.go b/pkg/middlewares/observability/middleware.go index b44175d40..2d677ff82 100644 --- a/pkg/middlewares/observability/middleware.go +++ b/pkg/middlewares/observability/middleware.go @@ -6,8 +6,8 @@ import ( "github.com/containous/alice" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) diff --git a/pkg/middlewares/observability/router.go b/pkg/middlewares/observability/router.go index 8da59a948..e840a1aa4 100644 --- a/pkg/middlewares/observability/router.go +++ b/pkg/middlewares/observability/router.go @@ -5,9 +5,9 @@ import ( "net/http" "github.com/containous/alice" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.37.0" "go.opentelemetry.io/otel/trace" diff --git a/pkg/middlewares/observability/semconv.go b/pkg/middlewares/observability/semconv.go index 13cf763eb..41aa52696 100644 --- a/pkg/middlewares/observability/semconv.go +++ b/pkg/middlewares/observability/semconv.go @@ -10,10 +10,10 @@ import ( "github.com/containous/alice" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/capture" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/metrics" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.37.0" "go.opentelemetry.io/otel/semconv/v1.37.0/httpconv" diff --git a/pkg/middlewares/observability/semconv_test.go b/pkg/middlewares/observability/semconv_test.go index 06a39e70b..960d4b98a 100644 --- a/pkg/middlewares/observability/semconv_test.go +++ b/pkg/middlewares/observability/semconv_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/capture" - "github.com/traefik/traefik/v3/pkg/types" + "github.com/traefik/traefik/v3/pkg/observability/metrics" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/otel/attribute" sdkmetric "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" @@ -54,7 +54,7 @@ func TestSemConvServerMetrics(t *testing.T) { t.Run(test.desc, func(t *testing.T) { t.Parallel() - var cfg types.OTLP + var cfg otypes.OTLP (&cfg).SetDefaults() cfg.AddRoutersLabels = true cfg.PushInterval = ptypes.Duration(10 * time.Millisecond) diff --git a/pkg/middlewares/observability/service.go b/pkg/middlewares/observability/service.go index c914c09cc..ef580f9bf 100644 --- a/pkg/middlewares/observability/service.go +++ b/pkg/middlewares/observability/service.go @@ -4,9 +4,9 @@ import ( "context" "net/http" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) diff --git a/pkg/middlewares/retry/retry.go b/pkg/middlewares/retry/retry.go index 31d310084..de15a21b4 100644 --- a/pkg/middlewares/retry/retry.go +++ b/pkg/middlewares/retry/retry.go @@ -15,7 +15,7 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/observability" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.37.0" "go.opentelemetry.io/otel/trace" diff --git a/pkg/logs/aws.go b/pkg/observability/logs/aws.go similarity index 100% rename from pkg/logs/aws.go rename to pkg/observability/logs/aws.go diff --git a/pkg/logs/aws_test.go b/pkg/observability/logs/aws_test.go similarity index 100% rename from pkg/logs/aws_test.go rename to pkg/observability/logs/aws_test.go diff --git a/pkg/logs/datadog.go b/pkg/observability/logs/datadog.go similarity index 100% rename from pkg/logs/datadog.go rename to pkg/observability/logs/datadog.go diff --git a/pkg/logs/datadog_test.go b/pkg/observability/logs/datadog_test.go similarity index 100% rename from pkg/logs/datadog_test.go rename to pkg/observability/logs/datadog_test.go diff --git a/pkg/logs/elastic.go b/pkg/observability/logs/elastic.go similarity index 100% rename from pkg/logs/elastic.go rename to pkg/observability/logs/elastic.go diff --git a/pkg/logs/elastic_test.go b/pkg/observability/logs/elastic_test.go similarity index 100% rename from pkg/logs/elastic_test.go rename to pkg/observability/logs/elastic_test.go diff --git a/pkg/logs/fields.go b/pkg/observability/logs/fields.go similarity index 100% rename from pkg/logs/fields.go rename to pkg/observability/logs/fields.go diff --git a/pkg/logs/gokit.go b/pkg/observability/logs/gokit.go similarity index 100% rename from pkg/logs/gokit.go rename to pkg/observability/logs/gokit.go diff --git a/pkg/logs/gokit_test.go b/pkg/observability/logs/gokit_test.go similarity index 100% rename from pkg/logs/gokit_test.go rename to pkg/observability/logs/gokit_test.go diff --git a/pkg/logs/hclog.go b/pkg/observability/logs/hclog.go similarity index 100% rename from pkg/logs/hclog.go rename to pkg/observability/logs/hclog.go diff --git a/pkg/logs/hclog_test.go b/pkg/observability/logs/hclog_test.go similarity index 100% rename from pkg/logs/hclog_test.go rename to pkg/observability/logs/hclog_test.go diff --git a/pkg/logs/instana.go b/pkg/observability/logs/instana.go similarity index 100% rename from pkg/logs/instana.go rename to pkg/observability/logs/instana.go diff --git a/pkg/logs/instana_test.go b/pkg/observability/logs/instana_test.go similarity index 100% rename from pkg/logs/instana_test.go rename to pkg/observability/logs/instana_test.go diff --git a/pkg/logs/log.go b/pkg/observability/logs/log.go similarity index 100% rename from pkg/logs/log.go rename to pkg/observability/logs/log.go diff --git a/pkg/logs/log_test.go b/pkg/observability/logs/log_test.go similarity index 100% rename from pkg/logs/log_test.go rename to pkg/observability/logs/log_test.go diff --git a/pkg/logs/logrus.go b/pkg/observability/logs/logrus.go similarity index 100% rename from pkg/logs/logrus.go rename to pkg/observability/logs/logrus.go diff --git a/pkg/logs/logrus_test.go b/pkg/observability/logs/logrus_test.go similarity index 100% rename from pkg/logs/logrus_test.go rename to pkg/observability/logs/logrus_test.go diff --git a/pkg/logs/otel.go b/pkg/observability/logs/otel.go similarity index 94% rename from pkg/logs/otel.go rename to pkg/observability/logs/otel.go index f1e1711d5..6e7734f78 100644 --- a/pkg/logs/otel.go +++ b/pkg/observability/logs/otel.go @@ -8,7 +8,8 @@ import ( "time" "github.com/rs/zerolog" - "github.com/traefik/traefik/v3/pkg/types" + "github.com/traefik/traefik/v3/pkg/observability" + "github.com/traefik/traefik/v3/pkg/observability/types" otellog "go.opentelemetry.io/otel/log" ) @@ -18,6 +19,9 @@ func SetupOTelLogger(ctx context.Context, logger zerolog.Logger, config *types.O return logger, nil } + if err := observability.EnsureUserEnvVar(); err != nil { + return zerolog.Logger{}, err + } provider, err := config.NewLoggerProvider(ctx) if err != nil { return zerolog.Logger{}, fmt.Errorf("setting up OpenTelemetry logger provider: %w", err) diff --git a/pkg/logs/otel_test.go b/pkg/observability/logs/otel_test.go similarity index 98% rename from pkg/logs/otel_test.go rename to pkg/observability/logs/otel_test.go index 75f73be33..c51322cdd 100644 --- a/pkg/logs/otel_test.go +++ b/pkg/observability/logs/otel_test.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/collector/pdata/plog/plogotlp" "go.opentelemetry.io/otel/trace" ) @@ -160,10 +160,10 @@ func TestLog(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - config := &types.OTelLog{ + config := &otypes.OTelLog{ ServiceName: "test", ResourceAttributes: map[string]string{"resource": "attribute"}, - HTTP: &types.OTelHTTP{ + HTTP: &otypes.OTelHTTP{ Endpoint: collector.URL, }, } diff --git a/pkg/logs/oxy.go b/pkg/observability/logs/oxy.go similarity index 100% rename from pkg/logs/oxy.go rename to pkg/observability/logs/oxy.go diff --git a/pkg/logs/oxy_test.go b/pkg/observability/logs/oxy_test.go similarity index 100% rename from pkg/logs/oxy_test.go rename to pkg/observability/logs/oxy_test.go diff --git a/pkg/logs/wasm.go b/pkg/observability/logs/wasm.go similarity index 100% rename from pkg/logs/wasm.go rename to pkg/observability/logs/wasm.go diff --git a/pkg/metrics/datadog.go b/pkg/observability/metrics/datadog.go similarity index 95% rename from pkg/metrics/datadog.go rename to pkg/observability/metrics/datadog.go index 89e7992a1..6b97f650e 100644 --- a/pkg/metrics/datadog.go +++ b/pkg/observability/metrics/datadog.go @@ -10,9 +10,9 @@ import ( "github.com/go-kit/kit/util/conn" gokitlog "github.com/go-kit/log" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/safe" - "github.com/traefik/traefik/v3/pkg/types" ) const ( @@ -56,7 +56,7 @@ const ( ) // RegisterDatadog registers the metrics pusher if this didn't happen yet and creates a datadog Registry instance. -func RegisterDatadog(ctx context.Context, config *types.Datadog) Registry { +func RegisterDatadog(ctx context.Context, config *otypes.Datadog) Registry { // Ensures there is only one DataDog client sending metrics at any given time. StopDatadog() @@ -109,7 +109,7 @@ func RegisterDatadog(ctx context.Context, config *types.Datadog) Registry { return registry } -func initDatadogClient(ctx context.Context, config *types.Datadog, logger gokitlog.LoggerFunc) { +func initDatadogClient(ctx context.Context, config *otypes.Datadog, logger gokitlog.LoggerFunc) { network, address := parseDatadogAddress(config.Address) ctx, datadogLoopCancelFunc = context.WithCancel(ctx) diff --git a/pkg/metrics/datadog_test.go b/pkg/observability/metrics/datadog_test.go similarity index 93% rename from pkg/metrics/datadog_test.go rename to pkg/observability/metrics/datadog_test.go index b647505af..bf4a044e1 100644 --- a/pkg/metrics/datadog_test.go +++ b/pkg/observability/metrics/datadog_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stvp/go-udp-testing" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) func TestDatadog(t *testing.T) { @@ -19,7 +19,7 @@ func TestDatadog(t *testing.T) { // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond udp.Timeout = 5 * time.Second - datadogRegistry := RegisterDatadog(t.Context(), &types.Datadog{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) + datadogRegistry := RegisterDatadog(t.Context(), &otypes.Datadog{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) if !datadogRegistry.IsEpEnabled() || !datadogRegistry.IsRouterEnabled() || !datadogRegistry.IsSvcEnabled() { t.Errorf("DatadogRegistry should return true for IsEnabled(), IsRouterEnabled() and IsSvcEnabled()") @@ -34,7 +34,7 @@ func TestDatadogWithPrefix(t *testing.T) { // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond udp.Timeout = 5 * time.Second - datadogRegistry := RegisterDatadog(t.Context(), &types.Datadog{Prefix: "testPrefix", Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) + datadogRegistry := RegisterDatadog(t.Context(), &otypes.Datadog{Prefix: "testPrefix", Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) testDatadogRegistry(t, "testPrefix", datadogRegistry) } diff --git a/pkg/metrics/headers.go b/pkg/observability/metrics/headers.go similarity index 100% rename from pkg/metrics/headers.go rename to pkg/observability/metrics/headers.go diff --git a/pkg/metrics/influxdb2.go b/pkg/observability/metrics/influxdb2.go similarity index 95% rename from pkg/metrics/influxdb2.go rename to pkg/observability/metrics/influxdb2.go index 270ac03a9..aaa159391 100644 --- a/pkg/metrics/influxdb2.go +++ b/pkg/observability/metrics/influxdb2.go @@ -12,9 +12,9 @@ import ( influxdb2log "github.com/influxdata/influxdb-client-go/v2/log" influxdb "github.com/influxdata/influxdb1-client/v2" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/safe" - "github.com/traefik/traefik/v3/pkg/types" ) var ( @@ -52,7 +52,7 @@ const ( ) // RegisterInfluxDB2 creates metrics exporter for InfluxDB2. -func RegisterInfluxDB2(ctx context.Context, config *types.InfluxDB2) Registry { +func RegisterInfluxDB2(ctx context.Context, config *otypes.InfluxDB2) Registry { logger := log.Ctx(ctx) if influxDB2Client == nil { @@ -133,7 +133,7 @@ func StopInfluxDB2() { } // newInfluxDB2Client creates an influxdb2.Client. -func newInfluxDB2Client(config *types.InfluxDB2) (influxdb2.Client, error) { +func newInfluxDB2Client(config *otypes.InfluxDB2) (influxdb2.Client, error) { if config.Token == "" || config.Org == "" || config.Bucket == "" { return nil, errors.New("token, org or bucket property is missing") } diff --git a/pkg/metrics/influxdb2_test.go b/pkg/observability/metrics/influxdb2_test.go similarity index 98% rename from pkg/metrics/influxdb2_test.go rename to pkg/observability/metrics/influxdb2_test.go index 63c7e62b3..daf2d0f96 100644 --- a/pkg/metrics/influxdb2_test.go +++ b/pkg/observability/metrics/influxdb2_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) func TestInfluxDB2(t *testing.T) { @@ -26,7 +26,7 @@ func TestInfluxDB2(t *testing.T) { })) influxDB2Registry := RegisterInfluxDB2(t.Context(), - &types.InfluxDB2{ + &otypes.InfluxDB2{ Address: ts.URL, Token: "test-token", PushInterval: ptypes.Duration(10 * time.Millisecond), diff --git a/pkg/metrics/metrics.go b/pkg/observability/metrics/metrics.go similarity index 100% rename from pkg/metrics/metrics.go rename to pkg/observability/metrics/metrics.go diff --git a/pkg/metrics/metrics_test.go b/pkg/observability/metrics/metrics_test.go similarity index 100% rename from pkg/metrics/metrics_test.go rename to pkg/observability/metrics/metrics_test.go diff --git a/pkg/metrics/otel.go b/pkg/observability/metrics/otel.go similarity index 96% rename from pkg/metrics/otel.go rename to pkg/observability/metrics/otel.go index a7bc78668..cfb3f50ef 100644 --- a/pkg/metrics/otel.go +++ b/pkg/observability/metrics/otel.go @@ -11,6 +11,8 @@ import ( "github.com/go-kit/kit/metrics" "github.com/rs/zerolog/log" + "github.com/traefik/traefik/v3/pkg/observability" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/version" "go.opentelemetry.io/otel" @@ -46,7 +48,11 @@ type SemConvMetricsRegistry struct { } // NewSemConvMetricRegistry registers all stables semantic conventions metrics. -func NewSemConvMetricRegistry(ctx context.Context, config *types.OTLP) (*SemConvMetricsRegistry, error) { +func NewSemConvMetricRegistry(ctx context.Context, config *otypes.OTLP) (*SemConvMetricsRegistry, error) { + if err := observability.EnsureUserEnvVar(); err != nil { + return nil, err + } + if openTelemetryMeterProvider == nil { var err error if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil { @@ -96,7 +102,7 @@ func (s *SemConvMetricsRegistry) HTTPClientRequestDuration() httpconv.ClientRequ } // RegisterOpenTelemetry registers all OpenTelemetry metrics. -func RegisterOpenTelemetry(ctx context.Context, config *types.OTLP) Registry { +func RegisterOpenTelemetry(ctx context.Context, config *otypes.OTLP) Registry { if openTelemetryMeterProvider == nil { var err error if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil { @@ -189,7 +195,7 @@ func StopOpenTelemetry() { } // newOpenTelemetryMeterProvider creates a new controller.Controller. -func newOpenTelemetryMeterProvider(ctx context.Context, config *types.OTLP) (*sdkmetric.MeterProvider, error) { +func newOpenTelemetryMeterProvider(ctx context.Context, config *otypes.OTLP) (*sdkmetric.MeterProvider, error) { var ( exporter sdkmetric.Exporter err error @@ -250,7 +256,7 @@ func newOpenTelemetryMeterProvider(ctx context.Context, config *types.OTLP) (*sd return meterProvider, nil } -func newHTTPExporter(ctx context.Context, config *types.OTelHTTP) (sdkmetric.Exporter, error) { +func newHTTPExporter(ctx context.Context, config *otypes.OTelHTTP) (sdkmetric.Exporter, error) { endpoint, err := url.Parse(config.Endpoint) if err != nil { return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err) @@ -282,7 +288,7 @@ func newHTTPExporter(ctx context.Context, config *types.OTelHTTP) (sdkmetric.Exp return otlpmetrichttp.New(ctx, opts...) } -func newGRPCExporter(ctx context.Context, config *types.OTelGRPC) (sdkmetric.Exporter, error) { +func newGRPCExporter(ctx context.Context, config *otypes.OTelGRPC) (sdkmetric.Exporter, error) { host, port, err := net.SplitHostPort(config.Endpoint) if err != nil { return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err) diff --git a/pkg/metrics/otel_test.go b/pkg/observability/metrics/otel_test.go similarity index 99% rename from pkg/metrics/otel_test.go rename to pkg/observability/metrics/otel_test.go index b110a1f3f..756f98ae8 100644 --- a/pkg/metrics/otel_test.go +++ b/pkg/observability/metrics/otel_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/version" "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" "go.opentelemetry.io/otel/attribute" @@ -323,10 +323,10 @@ func TestOpenTelemetry(t *testing.T) { ts.Close() }) - var cfg types.OTLP + var cfg otypes.OTLP (&cfg).SetDefaults() cfg.AddRoutersLabels = true - cfg.HTTP = &types.OTelHTTP{ + cfg.HTTP = &otypes.OTelHTTP{ Endpoint: ts.URL, } cfg.PushInterval = ptypes.Duration(10 * time.Millisecond) diff --git a/pkg/metrics/prometheus.go b/pkg/observability/metrics/prometheus.go similarity index 99% rename from pkg/metrics/prometheus.go rename to pkg/observability/metrics/prometheus.go index 608acf16a..f5a0ff735 100644 --- a/pkg/metrics/prometheus.go +++ b/pkg/observability/metrics/prometheus.go @@ -13,7 +13,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) const ( @@ -80,7 +80,7 @@ func PrometheusHandler() http.Handler { // RegisterPrometheus registers all Prometheus metrics. // It must be called only once and failing to register the metrics will lead to a panic. -func RegisterPrometheus(ctx context.Context, config *types.Prometheus) Registry { +func RegisterPrometheus(ctx context.Context, config *otypes.Prometheus) Registry { standardRegistry := initStandardRegistry(config) if err := promRegistry.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})); err != nil { @@ -104,7 +104,7 @@ func RegisterPrometheus(ctx context.Context, config *types.Prometheus) Registry return standardRegistry } -func initStandardRegistry(config *types.Prometheus) Registry { +func initStandardRegistry(config *otypes.Prometheus) Registry { buckets := []float64{0.1, 0.3, 1.2, 5.0} if config.Buckets != nil { buckets = config.Buckets diff --git a/pkg/metrics/prometheus_test.go b/pkg/observability/metrics/prometheus_test.go similarity index 96% rename from pkg/metrics/prometheus_test.go rename to pkg/observability/metrics/prometheus_test.go index a93a14d7d..f3b8c9f49 100644 --- a/pkg/metrics/prometheus_test.go +++ b/pkg/observability/metrics/prometheus_test.go @@ -11,8 +11,8 @@ import ( dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" "github.com/traefik/traefik/v3/pkg/config/dynamic" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" th "github.com/traefik/traefik/v3/pkg/testhelpers" - "github.com/traefik/traefik/v3/pkg/types" ) func TestRegisterPromState(t *testing.T) { @@ -20,42 +20,42 @@ func TestRegisterPromState(t *testing.T) { testCases := []struct { desc string - prometheusSlice []*types.Prometheus + prometheusSlice []*otypes.Prometheus initPromState bool unregisterPromState bool expectedNbRegistries int }{ { desc: "Register once", - prometheusSlice: []*types.Prometheus{{}}, + prometheusSlice: []*otypes.Prometheus{{}}, initPromState: true, unregisterPromState: false, expectedNbRegistries: 1, }, { desc: "Register once with no promState init", - prometheusSlice: []*types.Prometheus{{}}, + prometheusSlice: []*otypes.Prometheus{{}}, initPromState: false, unregisterPromState: false, expectedNbRegistries: 1, }, { desc: "Register twice", - prometheusSlice: []*types.Prometheus{{}, {}}, + prometheusSlice: []*otypes.Prometheus{{}, {}}, initPromState: true, unregisterPromState: false, expectedNbRegistries: 2, }, { desc: "Register twice with no promstate init", - prometheusSlice: []*types.Prometheus{{}, {}}, + prometheusSlice: []*otypes.Prometheus{{}, {}}, initPromState: false, unregisterPromState: false, expectedNbRegistries: 2, }, { desc: "Register twice with unregister", - prometheusSlice: []*types.Prometheus{{}, {}}, + prometheusSlice: []*otypes.Prometheus{{}, {}}, initPromState: true, unregisterPromState: true, expectedNbRegistries: 2, @@ -90,7 +90,7 @@ func TestPrometheus(t *testing.T) { promRegistry = prometheus.NewRegistry() t.Cleanup(promState.reset) - prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{ + prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{ AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true, @@ -404,7 +404,7 @@ func TestPrometheusMetricRemoval(t *testing.T) { promRegistry = prometheus.NewRegistry() t.Cleanup(promState.reset) - prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true, AddRoutersLabels: true}) + prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true, AddRoutersLabels: true}) defer promRegistry.Unregister(promState) conf1 := dynamic.Configuration{ @@ -495,7 +495,7 @@ func TestPrometheusMetricRemoveEndpointForRecoveredService(t *testing.T) { promRegistry = prometheus.NewRegistry() t.Cleanup(promState.reset) - prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddServicesLabels: true}) + prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddServicesLabels: true}) defer promRegistry.Unregister(promState) conf1 := dynamic.Configuration{ @@ -534,7 +534,7 @@ func TestPrometheusMetricRemoveEndpointForRecoveredService(t *testing.T) { func TestPrometheusRemovedMetricsReset(t *testing.T) { t.Cleanup(promState.reset) - prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true}) + prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true}) defer promRegistry.Unregister(promState) conf1 := dynamic.Configuration{ diff --git a/pkg/metrics/statsd.go b/pkg/observability/metrics/statsd.go similarity index 94% rename from pkg/metrics/statsd.go rename to pkg/observability/metrics/statsd.go index 871300ef6..a3a3acbbe 100644 --- a/pkg/metrics/statsd.go +++ b/pkg/observability/metrics/statsd.go @@ -6,9 +6,9 @@ import ( "github.com/go-kit/kit/metrics/statsd" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/safe" - "github.com/traefik/traefik/v3/pkg/types" ) var ( @@ -45,7 +45,7 @@ const ( ) // RegisterStatsd registers the metrics pusher if this didn't happen yet and creates a statsd Registry instance. -func RegisterStatsd(ctx context.Context, config *types.Statsd) Registry { +func RegisterStatsd(ctx context.Context, config *otypes.Statsd) Registry { // just to be sure there is a prefix defined if config.Prefix == "" { config.Prefix = defaultMetricsPrefix @@ -97,7 +97,7 @@ func RegisterStatsd(ctx context.Context, config *types.Statsd) Registry { } // initStatsdTicker initializes metrics pusher and creates a statsdClient if not created already. -func initStatsdTicker(ctx context.Context, config *types.Statsd) *time.Ticker { +func initStatsdTicker(ctx context.Context, config *otypes.Statsd) *time.Ticker { address := config.Address if len(address) == 0 { address = "localhost:8125" diff --git a/pkg/metrics/statsd_test.go b/pkg/observability/metrics/statsd_test.go similarity index 91% rename from pkg/metrics/statsd_test.go rename to pkg/observability/metrics/statsd_test.go index b912a7a6a..ad37314a9 100644 --- a/pkg/metrics/statsd_test.go +++ b/pkg/observability/metrics/statsd_test.go @@ -8,7 +8,7 @@ import ( "github.com/stvp/go-udp-testing" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) func TestStatsD(t *testing.T) { @@ -20,7 +20,7 @@ func TestStatsD(t *testing.T) { // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond udp.Timeout = 5 * time.Second - statsdRegistry := RegisterStatsd(t.Context(), &types.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) + statsdRegistry := RegisterStatsd(t.Context(), &otypes.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) testRegistry(t, defaultMetricsPrefix, statsdRegistry) } @@ -34,7 +34,7 @@ func TestStatsDWithPrefix(t *testing.T) { // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond udp.Timeout = 5 * time.Second - statsdRegistry := RegisterStatsd(t.Context(), &types.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true, Prefix: "testPrefix"}) + statsdRegistry := RegisterStatsd(t.Context(), &otypes.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true, Prefix: "testPrefix"}) testRegistry(t, "testPrefix", statsdRegistry) } diff --git a/pkg/observability/observability.go b/pkg/observability/observability.go new file mode 100644 index 000000000..4c05f2cbf --- /dev/null +++ b/pkg/observability/observability.go @@ -0,0 +1,15 @@ +package observability + +import ( + "fmt" + "os" +) + +func EnsureUserEnvVar() error { + if os.Getenv("USER") == "" { + if err := os.Setenv("USER", "traefik"); err != nil { + return fmt.Errorf("could not set USER environment variable: %w", err) + } + } + return nil +} diff --git a/pkg/tracing/tracing.go b/pkg/observability/tracing/tracing.go similarity index 97% rename from pkg/tracing/tracing.go rename to pkg/observability/tracing/tracing.go index c4fbf254c..bb38bc654 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/observability/tracing/tracing.go @@ -13,7 +13,8 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/types" + "github.com/traefik/traefik/v3/pkg/observability" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/contrib/propagators/autoprop" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -38,10 +39,14 @@ func NewTracing(ctx context.Context, conf *static.Tracing) (*Tracer, io.Closer, if backend == nil { log.Debug().Msg("Could not initialize tracing, using OpenTelemetry by default") - defaultBackend := &types.OTelTracing{} + defaultBackend := &otypes.OTelTracing{} backend = defaultBackend } + if err := observability.EnsureUserEnvVar(); err != nil { + return nil, nil, err + } + otel.SetTextMapPropagator(autoprop.NewTextMapPropagator()) tr, closer, err := backend.Setup(ctx, conf.ServiceName, conf.SampleRate, conf.ResourceAttributes) diff --git a/pkg/tracing/tracing_test.go b/pkg/observability/tracing/tracing_test.go similarity index 98% rename from pkg/tracing/tracing_test.go rename to pkg/observability/tracing/tracing_test.go index 4c5d31f2a..91dc19e60 100644 --- a/pkg/tracing/tracing_test.go +++ b/pkg/observability/tracing/tracing_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" @@ -355,8 +355,8 @@ func TestTracing(t *testing.T) { ServiceName: "traefik", SampleRate: 1.0, ResourceAttributes: test.resourceAttributes, - OTLP: &types.OTelTracing{ - HTTP: &types.OTelHTTP{ + OTLP: &otypes.OTelTracing{ + HTTP: &otypes.OTelHTTP{ Endpoint: collector.URL, }, }, @@ -410,7 +410,7 @@ func TestTracing(t *testing.T) { func TestTracerProvider(t *testing.T) { t.Parallel() - otlpConfig := &types.OTelTracing{} + otlpConfig := &otypes.OTelTracing{} otlpConfig.SetDefaults() config := &static.Tracing{OTLP: otlpConfig} diff --git a/pkg/types/logs.go b/pkg/observability/types/logs.go similarity index 99% rename from pkg/types/logs.go rename to pkg/observability/types/logs.go index 903baea49..8bc108ddc 100644 --- a/pkg/types/logs.go +++ b/pkg/observability/types/logs.go @@ -7,6 +7,7 @@ import ( "net/url" "github.com/traefik/paerser/types" + ttypes "github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/version" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc" @@ -189,7 +190,7 @@ func (o *OTelLog) NewLoggerProvider(ctx context.Context) (*otelsdk.LoggerProvide resource.WithOS(), resource.WithProcess(), resource.WithTelemetrySDK(), - resource.WithDetectors(K8sAttributesDetector{}), + resource.WithDetectors(ttypes.K8sAttributesDetector{}), // The following order allows the user to override the service name and version, // as well as any other attributes set by the above detectors. resource.WithAttributes( diff --git a/pkg/types/metrics.go b/pkg/observability/types/metrics.go similarity index 100% rename from pkg/types/metrics.go rename to pkg/observability/types/metrics.go diff --git a/pkg/types/otel.go b/pkg/observability/types/otel.go similarity index 89% rename from pkg/types/otel.go rename to pkg/observability/types/otel.go index 281d83e1d..7e6f9cf28 100644 --- a/pkg/types/otel.go +++ b/pkg/observability/types/otel.go @@ -1,10 +1,12 @@ package types +import "github.com/traefik/traefik/v3/pkg/types" + // OTelGRPC provides configuration settings for the gRPC open-telemetry. type OTelGRPC struct { Endpoint string `description:"Sets the gRPC endpoint (host:port) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"` Insecure bool `description:"Disables client transport security for the exporter." json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty" export:"true"` - TLS *ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` + TLS *types.ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"` } @@ -16,7 +18,7 @@ func (o *OTelGRPC) SetDefaults() { // OTelHTTP provides configuration settings for the HTTP open-telemetry. type OTelHTTP struct { Endpoint string `description:"Sets the HTTP endpoint (scheme://host:port/path) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"` - TLS *ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` + TLS *types.ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"` } diff --git a/pkg/types/tracing.go b/pkg/observability/types/tracing.go similarity index 98% rename from pkg/types/tracing.go rename to pkg/observability/types/tracing.go index 23e79aa6f..9f525f9c2 100644 --- a/pkg/types/tracing.go +++ b/pkg/observability/types/tracing.go @@ -9,6 +9,7 @@ import ( "time" "github.com/rs/zerolog/log" + ttypes "github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/version" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -77,7 +78,7 @@ func (c *OTelTracing) Setup(ctx context.Context, serviceName string, sampleRate resource.WithOS(), resource.WithProcess(), resource.WithTelemetrySDK(), - resource.WithDetectors(K8sAttributesDetector{}), + resource.WithDetectors(ttypes.K8sAttributesDetector{}), // The following order allows the user to override the service name and version, // as well as any other attributes set by the above detectors. resource.WithAttributes( diff --git a/pkg/types/tracing_test.go b/pkg/observability/types/tracing_test.go similarity index 100% rename from pkg/types/tracing_test.go rename to pkg/observability/types/tracing_test.go diff --git a/pkg/plugins/middlewarewasm.go b/pkg/plugins/middlewarewasm.go index c33858a9d..48d179426 100644 --- a/pkg/plugins/middlewarewasm.go +++ b/pkg/plugins/middlewarewasm.go @@ -14,8 +14,8 @@ import ( "github.com/http-wasm/http-wasm-host-go/handler" wasm "github.com/http-wasm/http-wasm-host-go/handler/nethttp" "github.com/tetratelabs/wazero" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) type wasmMiddlewareBuilder struct { diff --git a/pkg/plugins/middlewareyaegi.go b/pkg/plugins/middlewareyaegi.go index a23db53e7..590938044 100644 --- a/pkg/plugins/middlewareyaegi.go +++ b/pkg/plugins/middlewareyaegi.go @@ -13,7 +13,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/yaegi/interp" "github.com/traefik/yaegi/stdlib" "github.com/traefik/yaegi/stdlib/unsafe" diff --git a/pkg/plugins/providers.go b/pkg/plugins/providers.go index 5fdaf03ac..46c6df8cc 100644 --- a/pkg/plugins/providers.go +++ b/pkg/plugins/providers.go @@ -11,7 +11,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/yaegi/interp" diff --git a/pkg/provider/acme/account.go b/pkg/provider/acme/account.go index c0a7458b3..434f58e3a 100644 --- a/pkg/provider/acme/account.go +++ b/pkg/provider/acme/account.go @@ -10,7 +10,7 @@ import ( "github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/registration" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // Account is used to store lets encrypt registration info. diff --git a/pkg/provider/acme/challenge_http.go b/pkg/provider/acme/challenge_http.go index 37dfd0bc8..81830afaf 100644 --- a/pkg/provider/acme/challenge_http.go +++ b/pkg/provider/acme/challenge_http.go @@ -13,7 +13,7 @@ import ( "github.com/go-acme/lego/v4/challenge/http01" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" ) // ChallengeHTTP HTTP challenge provider implements challenge.Provider. diff --git a/pkg/provider/acme/challenge_tls.go b/pkg/provider/acme/challenge_tls.go index 995f23d18..9201ba8c4 100644 --- a/pkg/provider/acme/challenge_tls.go +++ b/pkg/provider/acme/challenge_tls.go @@ -9,7 +9,7 @@ import ( "github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/safe" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" diff --git a/pkg/provider/acme/local_store.go b/pkg/provider/acme/local_store.go index 6e50fb153..dab258822 100644 --- a/pkg/provider/acme/local_store.go +++ b/pkg/provider/acme/local_store.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/safe" ) diff --git a/pkg/provider/acme/provider.go b/pkg/provider/acme/provider.go index 35ea148f8..cfbff7e22 100644 --- a/pkg/provider/acme/provider.go +++ b/pkg/provider/acme/provider.go @@ -27,9 +27,9 @@ import ( "github.com/rs/zerolog/log" ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" httpmuxer "github.com/traefik/traefik/v3/pkg/muxer/http" tcpmuxer "github.com/traefik/traefik/v3/pkg/muxer/tcp" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/safe" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" diff --git a/pkg/provider/configuration.go b/pkg/provider/configuration.go index bbb393425..2872ed7e3 100644 --- a/pkg/provider/configuration.go +++ b/pkg/provider/configuration.go @@ -13,7 +13,7 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/tls" ) diff --git a/pkg/provider/consulcatalog/config.go b/pkg/provider/consulcatalog/config.go index 513b85298..34c9a90dd 100644 --- a/pkg/provider/consulcatalog/config.go +++ b/pkg/provider/consulcatalog/config.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/label" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/constraints" ) diff --git a/pkg/provider/consulcatalog/consul_catalog.go b/pkg/provider/consulcatalog/consul_catalog.go index 55c24edb6..abdc8648e 100644 --- a/pkg/provider/consulcatalog/consul_catalog.go +++ b/pkg/provider/consulcatalog/consul_catalog.go @@ -17,7 +17,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/constraints" "github.com/traefik/traefik/v3/pkg/safe" diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index 7663511be..713586295 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/label" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/constraints" ) diff --git a/pkg/provider/docker/pdocker.go b/pkg/provider/docker/pdocker.go index bcd5ce96e..0720746a3 100644 --- a/pkg/provider/docker/pdocker.go +++ b/pkg/provider/docker/pdocker.go @@ -16,7 +16,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" ) diff --git a/pkg/provider/docker/pswarm.go b/pkg/provider/docker/pswarm.go index f665b3ef7..bcb7ded48 100644 --- a/pkg/provider/docker/pswarm.go +++ b/pkg/provider/docker/pswarm.go @@ -17,7 +17,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" ) diff --git a/pkg/provider/ecs/ecs.go b/pkg/provider/ecs/ecs.go index b6119e24e..084b9b9ca 100644 --- a/pkg/provider/ecs/ecs.go +++ b/pkg/provider/ecs/ecs.go @@ -24,7 +24,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" ) diff --git a/pkg/provider/file/file.go b/pkg/provider/file/file.go index 7b1b79e99..5f0b08223 100644 --- a/pkg/provider/file/file.go +++ b/pkg/provider/file/file.go @@ -18,7 +18,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/paerser/file" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/provider/http/http.go b/pkg/provider/http/http.go index 1068429b2..4712e1b0a 100644 --- a/pkg/provider/http/http.go +++ b/pkg/provider/http/http.go @@ -16,7 +16,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/provider/kubernetes/crd/kubernetes.go b/pkg/provider/kubernetes/crd/kubernetes.go index ab797e676..b9f5c0aa5 100644 --- a/pkg/provider/kubernetes/crd/kubernetes.go +++ b/pkg/provider/kubernetes/crd/kubernetes.go @@ -24,7 +24,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/gateway" diff --git a/pkg/provider/kubernetes/crd/kubernetes_http.go b/pkg/provider/kubernetes/crd/kubernetes_http.go index 59dfbd4a5..2e907d6c3 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_http.go +++ b/pkg/provider/kubernetes/crd/kubernetes_http.go @@ -11,7 +11,7 @@ import ( "github.com/rs/zerolog/log" ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" diff --git a/pkg/provider/kubernetes/crd/kubernetes_tcp.go b/pkg/provider/kubernetes/crd/kubernetes_tcp.go index 1eb3eed84..c4c3fa6d4 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_tcp.go +++ b/pkg/provider/kubernetes/crd/kubernetes_tcp.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/provider/kubernetes/gateway/kubernetes.go b/pkg/provider/kubernetes/gateway/kubernetes.go index 3edd9d799..3010f6bc0 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes.go +++ b/pkg/provider/kubernetes/gateway/kubernetes.go @@ -19,7 +19,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/safe" diff --git a/pkg/provider/kubernetes/ingress-nginx/kubernetes.go b/pkg/provider/kubernetes/ingress-nginx/kubernetes.go index d35837947..e8f583ba0 100644 --- a/pkg/provider/kubernetes/ingress-nginx/kubernetes.go +++ b/pkg/provider/kubernetes/ingress-nginx/kubernetes.go @@ -20,7 +20,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/safe" diff --git a/pkg/provider/kubernetes/ingress/annotations_test.go b/pkg/provider/kubernetes/ingress/annotations_test.go index 6879f2ae1..1f86f51c7 100644 --- a/pkg/provider/kubernetes/ingress/annotations_test.go +++ b/pkg/provider/kubernetes/ingress/annotations_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v3/pkg/config/dynamic" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/types" ) @@ -61,7 +62,7 @@ func Test_parseRouterConfig(t *testing.T) { AccessLogs: pointer(true), Tracing: pointer(true), Metrics: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 072e08da1..7a1919b3e 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -21,7 +21,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/safe" diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index acd7400a4..d965e68a2 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -17,6 +17,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" traefikhttp "github.com/traefik/traefik/v3/pkg/muxer/http" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/tls" @@ -127,7 +128,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) { AccessLogs: pointer(true), Tracing: pointer(true), Metrics: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, diff --git a/pkg/provider/kv/kv.go b/pkg/provider/kv/kv.go index 613320617..237a0d4b0 100644 --- a/pkg/provider/kv/kv.go +++ b/pkg/provider/kv/kv.go @@ -14,7 +14,7 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/kv" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/safe" ) diff --git a/pkg/provider/nomad/config.go b/pkg/provider/nomad/config.go index 4a2192ef0..a6fb4343b 100644 --- a/pkg/provider/nomad/config.go +++ b/pkg/provider/nomad/config.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/label" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/constraints" ) diff --git a/pkg/provider/nomad/nomad.go b/pkg/provider/nomad/nomad.go index 6f0b4774e..77876468e 100644 --- a/pkg/provider/nomad/nomad.go +++ b/pkg/provider/nomad/nomad.go @@ -15,7 +15,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/job" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider/constraints" "github.com/traefik/traefik/v3/pkg/safe" diff --git a/pkg/provider/tailscale/provider.go b/pkg/provider/tailscale/provider.go index 8e795e5be..5e84912e4 100644 --- a/pkg/provider/tailscale/provider.go +++ b/pkg/provider/tailscale/provider.go @@ -12,9 +12,9 @@ import ( "github.com/rs/zerolog/log" "github.com/tailscale/tscert" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/muxer/http" "github.com/traefik/traefik/v3/pkg/muxer/tcp" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/safe" traefiktls "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" diff --git a/pkg/provider/traefik/internal.go b/pkg/provider/traefik/internal.go index 544c1a2c5..73d17d63f 100644 --- a/pkg/provider/traefik/internal.go +++ b/pkg/provider/traefik/internal.go @@ -11,7 +11,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/provider/traefik/internal_test.go b/pkg/provider/traefik/internal_test.go index 8ec8a7668..e0697dd8d 100644 --- a/pkg/provider/traefik/internal_test.go +++ b/pkg/provider/traefik/internal_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v3/pkg/config/static" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/ping" "github.com/traefik/traefik/v3/pkg/provider/rest" "github.com/traefik/traefik/v3/pkg/types" @@ -41,8 +42,8 @@ func Test_createConfiguration(t *testing.T) { Insecure: true, }, }, - Metrics: &types.Metrics{ - Prometheus: &types.Prometheus{ + Metrics: &otypes.Metrics{ + Prometheus: &otypes.Prometheus{ EntryPoint: "test", ManualRouting: false, }, @@ -65,8 +66,8 @@ func Test_createConfiguration(t *testing.T) { Insecure: false, }, }, - Metrics: &types.Metrics{ - Prometheus: &types.Prometheus{ + Metrics: &otypes.Metrics{ + Prometheus: &otypes.Prometheus{ EntryPoint: "test", ManualRouting: true, }, @@ -150,8 +151,8 @@ func Test_createConfiguration(t *testing.T) { { desc: "prometheus_simple.json", staticCfg: static.Configuration{ - Metrics: &types.Metrics{ - Prometheus: &types.Prometheus{ + Metrics: &otypes.Metrics{ + Prometheus: &otypes.Prometheus{ EntryPoint: "test", ManualRouting: false, }, @@ -161,8 +162,8 @@ func Test_createConfiguration(t *testing.T) { { desc: "prometheus_custom.json", staticCfg: static.Configuration{ - Metrics: &types.Metrics{ - Prometheus: &types.Prometheus{ + Metrics: &otypes.Metrics{ + Prometheus: &otypes.Prometheus{ EntryPoint: "test", ManualRouting: true, }, diff --git a/pkg/proxy/httputil/builder.go b/pkg/proxy/httputil/builder.go index cb591c8db..1a4b04a0f 100644 --- a/pkg/proxy/httputil/builder.go +++ b/pkg/proxy/httputil/builder.go @@ -8,7 +8,7 @@ import ( "time" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/metrics" + "github.com/traefik/traefik/v3/pkg/observability/metrics" ) // TransportManager manages transport used for backend communications. diff --git a/pkg/proxy/httputil/observability.go b/pkg/proxy/httputil/observability.go index 4486d5c6d..23ff5acdf 100644 --- a/pkg/proxy/httputil/observability.go +++ b/pkg/proxy/httputil/observability.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/observability" - "github.com/traefik/traefik/v3/pkg/tracing" + "github.com/traefik/traefik/v3/pkg/observability/metrics" + "github.com/traefik/traefik/v3/pkg/observability/tracing" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.37.0" "go.opentelemetry.io/otel/semconv/v1.37.0/httpconv" diff --git a/pkg/proxy/httputil/observability_test.go b/pkg/proxy/httputil/observability_test.go index 02a4f084f..c0ef0e7a3 100644 --- a/pkg/proxy/httputil/observability_test.go +++ b/pkg/proxy/httputil/observability_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/require" ptypes "github.com/traefik/paerser/types" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/observability" - "github.com/traefik/traefik/v3/pkg/types" + "github.com/traefik/traefik/v3/pkg/observability/metrics" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "go.opentelemetry.io/otel/attribute" sdkmetric "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" @@ -59,7 +59,7 @@ func TestObservabilityRoundTripper_metrics(t *testing.T) { t.Run(test.desc, func(t *testing.T) { t.Parallel() - var cfg types.OTLP + var cfg otypes.OTLP (&cfg).SetDefaults() cfg.AddRoutersLabels = true cfg.PushInterval = ptypes.Duration(10 * time.Millisecond) diff --git a/pkg/proxy/httputil/proxy.go b/pkg/proxy/httputil/proxy.go index 7d4c52c9d..a6c93cade 100644 --- a/pkg/proxy/httputil/proxy.go +++ b/pkg/proxy/httputil/proxy.go @@ -15,7 +15,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "golang.org/x/net/http/httpguts" ) diff --git a/pkg/redactor/redactor_config_test.go b/pkg/redactor/redactor_config_test.go index b086ccd6a..9edf2363f 100644 --- a/pkg/redactor/redactor_config_test.go +++ b/pkg/redactor/redactor_config_test.go @@ -12,6 +12,7 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/static" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/ping" "github.com/traefik/traefik/v3/pkg/plugins" "github.com/traefik/traefik/v3/pkg/provider/acme" @@ -798,21 +799,21 @@ func TestDo_staticConfiguration(t *testing.T) { Debug: true, } - config.Metrics = &types.Metrics{ - Prometheus: &types.Prometheus{ + config.Metrics = &otypes.Metrics{ + Prometheus: &otypes.Prometheus{ Buckets: []float64{0.1, 0.3, 1.2, 5}, AddEntryPointsLabels: true, AddServicesLabels: true, EntryPoint: "MyEntryPoint", ManualRouting: true, }, - Datadog: &types.Datadog{ + Datadog: &otypes.Datadog{ Address: "localhost:8181", PushInterval: 42, AddEntryPointsLabels: true, AddServicesLabels: true, }, - StatsD: &types.Statsd{ + StatsD: &otypes.Statsd{ Address: "localhost:8182", PushInterval: 42, AddEntryPointsLabels: true, @@ -827,7 +828,7 @@ func TestDo_staticConfiguration(t *testing.T) { TerminatingStatusCode: 42, } - config.Log = &types.TraefikLog{ + config.Log = &otypes.TraefikLog{ Level: "Level", Format: "json", FilePath: "/foo/path", @@ -835,19 +836,19 @@ func TestDo_staticConfiguration(t *testing.T) { MaxAge: 3, MaxBackups: 4, Compress: true, - OTLP: &types.OTelLog{ + OTLP: &otypes.OTelLog{ ServiceName: "foobar", ResourceAttributes: map[string]string{ "foobar": "foobar", }, - GRPC: &types.OTelGRPC{ + GRPC: &otypes.OTelGRPC{ Endpoint: "foobar", Insecure: true, Headers: map[string]string{ "foobar": "foobar", }, }, - HTTP: &types.OTelHTTP{ + HTTP: &otypes.OTelHTTP{ Endpoint: "foobar", Headers: map[string]string{ "foobar": "foobar", @@ -856,20 +857,20 @@ func TestDo_staticConfiguration(t *testing.T) { }, } - config.AccessLog = &types.AccessLog{ + config.AccessLog = &otypes.AccessLog{ FilePath: "AccessLog FilePath", Format: "AccessLog Format", - Filters: &types.AccessLogFilters{ + Filters: &otypes.AccessLogFilters{ StatusCodes: []string{"200", "500"}, RetryAttempts: true, MinDuration: 42, }, - Fields: &types.AccessLogFields{ + Fields: &otypes.AccessLogFields{ DefaultMode: "drop", Names: map[string]string{ "RequestHost": "keep", }, - Headers: &types.FieldHeaders{ + Headers: &otypes.FieldHeaders{ DefaultMode: "drop", Names: map[string]string{ "Referer": "keep", @@ -877,19 +878,19 @@ func TestDo_staticConfiguration(t *testing.T) { }, }, BufferingSize: 42, - OTLP: &types.OTelLog{ + OTLP: &otypes.OTelLog{ ServiceName: "foobar", ResourceAttributes: map[string]string{ "foobar": "foobar", }, - GRPC: &types.OTelGRPC{ + GRPC: &otypes.OTelGRPC{ Endpoint: "foobar", Insecure: true, Headers: map[string]string{ "foobar": "foobar", }, }, - HTTP: &types.OTelHTTP{ + HTTP: &otypes.OTelHTTP{ Endpoint: "foobar", Headers: map[string]string{ "foobar": "foobar", @@ -907,14 +908,14 @@ func TestDo_staticConfiguration(t *testing.T) { "foobar": "foobar", }, SampleRate: 42, - OTLP: &types.OTelTracing{ - HTTP: &types.OTelHTTP{ + OTLP: &otypes.OTelTracing{ + HTTP: &otypes.OTelHTTP{ Endpoint: "foobar", Headers: map[string]string{ "foobar": "foobar", }, }, - GRPC: &types.OTelGRPC{ + GRPC: &otypes.OTelGRPC{ Endpoint: "foobar", Insecure: true, Headers: map[string]string{ diff --git a/pkg/server/aggregator.go b/pkg/server/aggregator.go index 9c35b00ac..8f22474fe 100644 --- a/pkg/server/aggregator.go +++ b/pkg/server/aggregator.go @@ -7,10 +7,10 @@ import ( "github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/server/provider" "github.com/traefik/traefik/v3/pkg/tls" - "github.com/traefik/traefik/v3/pkg/types" ) func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoints []string) dynamic.Configuration { @@ -270,7 +270,7 @@ func applyDefaultObservabilityModel(cfg dynamic.Configuration) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, } continue @@ -289,7 +289,7 @@ func applyDefaultObservabilityModel(cfg dynamic.Configuration) { } if router.Observability.TraceVerbosity == "" { - router.Observability.TraceVerbosity = types.MinimalVerbosity + router.Observability.TraceVerbosity = otypes.MinimalVerbosity } } } diff --git a/pkg/server/aggregator_test.go b/pkg/server/aggregator_test.go index 4c202fdf8..e33ef7ae1 100644 --- a/pkg/server/aggregator_test.go +++ b/pkg/server/aggregator_test.go @@ -6,8 +6,8 @@ import ( "github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/stretchr/testify/assert" "github.com/traefik/traefik/v3/pkg/config/dynamic" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" "github.com/traefik/traefik/v3/pkg/tls" - "github.com/traefik/traefik/v3/pkg/types" ) func Test_mergeConfiguration(t *testing.T) { @@ -525,7 +525,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -594,7 +594,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -628,7 +628,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Tracing: pointer(true), Metrics: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -645,7 +645,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Tracing: pointer(true), Metrics: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -659,7 +659,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Tracing: pointer(true), Metrics: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -697,7 +697,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, @@ -740,7 +740,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, "websecure-test": { @@ -751,7 +751,7 @@ func Test_applyModel(t *testing.T) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, }, }, }, diff --git a/pkg/server/configurationwatcher.go b/pkg/server/configurationwatcher.go index 5071f2498..8142f8359 100644 --- a/pkg/server/configurationwatcher.go +++ b/pkg/server/configurationwatcher.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/server/middleware/observability.go b/pkg/server/middleware/observability.go index 82152c7fc..0ffe34165 100644 --- a/pkg/server/middleware/observability.go +++ b/pkg/server/middleware/observability.go @@ -9,14 +9,14 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog" "github.com/traefik/traefik/v3/pkg/middlewares/capture" mmetrics "github.com/traefik/traefik/v3/pkg/middlewares/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/observability" - "github.com/traefik/traefik/v3/pkg/tracing" - "github.com/traefik/traefik/v3/pkg/types" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/metrics" + "github.com/traefik/traefik/v3/pkg/observability/tracing" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) // ObservabilityMgr is a manager for observability (AccessLogs, Metrics and Tracing) enablement. @@ -130,8 +130,8 @@ func (o *ObservabilityMgr) observabilityContextHandler(next http.Handler, intern AccessLogsEnabled: o.shouldAccessLog(internal, config), MetricsEnabled: o.shouldMeter(internal, config), SemConvMetricsEnabled: o.shouldMeterSemConv(internal, config), - TracingEnabled: o.shouldTrace(internal, config, types.MinimalVerbosity), - DetailedTracingEnabled: o.shouldTrace(internal, config, types.DetailedVerbosity), + TracingEnabled: o.shouldTrace(internal, config, otypes.MinimalVerbosity), + DetailedTracingEnabled: o.shouldTrace(internal, config, otypes.DetailedVerbosity), }) } @@ -191,7 +191,7 @@ func (o *ObservabilityMgr) shouldMeterSemConv(internal bool, observabilityConfig } // shouldTrace returns whether the tracing should be enabled for the given serviceName and the observability config. -func (o *ObservabilityMgr) shouldTrace(internal bool, observabilityConfig dynamic.RouterObservabilityConfig, verbosity types.TracingVerbosity) bool { +func (o *ObservabilityMgr) shouldTrace(internal bool, observabilityConfig dynamic.RouterObservabilityConfig, verbosity otypes.TracingVerbosity) bool { if o == nil { return false } diff --git a/pkg/server/router/router.go b/pkg/server/router/router.go index 44f6950d7..bac2d5c48 100644 --- a/pkg/server/router/router.go +++ b/pkg/server/router/router.go @@ -12,13 +12,13 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/runtime" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog" "github.com/traefik/traefik/v3/pkg/middlewares/denyrouterrecursion" metricsMiddle "github.com/traefik/traefik/v3/pkg/middlewares/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/recovery" httpmuxer "github.com/traefik/traefik/v3/pkg/muxer/http" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/server/middleware" "github.com/traefik/traefik/v3/pkg/server/provider" "github.com/traefik/traefik/v3/pkg/tls" diff --git a/pkg/server/router/tcp/manager.go b/pkg/server/router/tcp/manager.go index 5966462cc..788bf7cb0 100644 --- a/pkg/server/router/tcp/manager.go +++ b/pkg/server/router/tcp/manager.go @@ -11,10 +11,10 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/runtime" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares/snicheck" httpmuxer "github.com/traefik/traefik/v3/pkg/muxer/http" tcpmuxer "github.com/traefik/traefik/v3/pkg/muxer/tcp" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/server/provider" tcpservice "github.com/traefik/traefik/v3/pkg/server/service/tcp" "github.com/traefik/traefik/v3/pkg/tcp" diff --git a/pkg/server/router/udp/router.go b/pkg/server/router/udp/router.go index 8fb0f70d6..910efa499 100644 --- a/pkg/server/router/udp/router.go +++ b/pkg/server/router/udp/router.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/runtime" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/server/provider" udpservice "github.com/traefik/traefik/v3/pkg/server/service/udp" "github.com/traefik/traefik/v3/pkg/udp" diff --git a/pkg/server/server.go b/pkg/server/server.go index 9c96bdcc6..72af729e6 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -8,7 +8,7 @@ import ( "time" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/metrics" + "github.com/traefik/traefik/v3/pkg/observability/metrics" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/server/middleware" ) diff --git a/pkg/server/server_entrypoint_tcp.go b/pkg/server/server_entrypoint_tcp.go index eb68714d2..aef3954bf 100644 --- a/pkg/server/server_entrypoint_tcp.go +++ b/pkg/server/server_entrypoint_tcp.go @@ -23,12 +23,12 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/ip" - "github.com/traefik/traefik/v3/pkg/logs" - "github.com/traefik/traefik/v3/pkg/metrics" "github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares/contenttype" "github.com/traefik/traefik/v3/pkg/middlewares/forwardedheaders" "github.com/traefik/traefik/v3/pkg/middlewares/requestdecorator" + "github.com/traefik/traefik/v3/pkg/observability/logs" + "github.com/traefik/traefik/v3/pkg/observability/metrics" "github.com/traefik/traefik/v3/pkg/safe" tcprouter "github.com/traefik/traefik/v3/pkg/server/router/tcp" "github.com/traefik/traefik/v3/pkg/server/service" diff --git a/pkg/server/server_entrypoint_udp.go b/pkg/server/server_entrypoint_udp.go index 00a798f22..2d7250496 100644 --- a/pkg/server/server_entrypoint_udp.go +++ b/pkg/server/server_entrypoint_udp.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/udp" ) diff --git a/pkg/server/service/managerfactory.go b/pkg/server/service/managerfactory.go index 19da05d7b..a850ec745 100644 --- a/pkg/server/service/managerfactory.go +++ b/pkg/server/service/managerfactory.go @@ -9,7 +9,7 @@ import ( "github.com/traefik/traefik/v3/pkg/api/dashboard" "github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/config/static" - "github.com/traefik/traefik/v3/pkg/metrics" + "github.com/traefik/traefik/v3/pkg/observability/metrics" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/server/middleware" ) diff --git a/pkg/server/service/service.go b/pkg/server/service/service.go index b1bc6d8e9..a8e00cd1d 100644 --- a/pkg/server/service/service.go +++ b/pkg/server/service/service.go @@ -17,11 +17,11 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/healthcheck" - "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog" metricsMiddle "github.com/traefik/traefik/v3/pkg/middlewares/metrics" "github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/retry" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/proxy/httputil" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/server/cookie" diff --git a/pkg/server/service/tcp/service.go b/pkg/server/service/tcp/service.go index e3c0299bc..9ff454fad 100644 --- a/pkg/server/service/tcp/service.go +++ b/pkg/server/service/tcp/service.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/runtime" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/server/provider" "github.com/traefik/traefik/v3/pkg/tcp" ) diff --git a/pkg/server/service/udp/service.go b/pkg/server/service/udp/service.go index 1772c1954..d0d3028b4 100644 --- a/pkg/server/service/udp/service.go +++ b/pkg/server/service/udp/service.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/runtime" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/server/provider" "github.com/traefik/traefik/v3/pkg/udp" ) diff --git a/pkg/testhelpers/config.go b/pkg/testhelpers/config.go index 8ab73b6b6..afd298599 100644 --- a/pkg/testhelpers/config.go +++ b/pkg/testhelpers/config.go @@ -2,7 +2,7 @@ package testhelpers import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/types" + otypes "github.com/traefik/traefik/v3/pkg/observability/types" ) // BuildConfiguration is a helper to create a configuration. @@ -61,7 +61,7 @@ func WithObservability() func(*dynamic.Router) { AccessLogs: pointer(true), Metrics: pointer(true), Tracing: pointer(true), - TraceVerbosity: types.MinimalVerbosity, + TraceVerbosity: otypes.MinimalVerbosity, } } } diff --git a/pkg/tls/tlsmanager.go b/pkg/tls/tlsmanager.go index 2c4a9048c..54d2c4cbf 100644 --- a/pkg/tls/tlsmanager.go +++ b/pkg/tls/tlsmanager.go @@ -15,7 +15,7 @@ import ( "github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/logs" + "github.com/traefik/traefik/v3/pkg/observability/logs" "github.com/traefik/traefik/v3/pkg/tls/generate" "github.com/traefik/traefik/v3/pkg/types" ) diff --git a/pkg/udp/conn.go b/pkg/udp/conn.go index 69ba8ebe2..36778f648 100644 --- a/pkg/udp/conn.go +++ b/pkg/udp/conn.go @@ -34,7 +34,7 @@ type Listener struct { timeout time.Duration } -// Creates a new listener from PacketConn. +// ListenPacketConn creates a new listener from PacketConn. func ListenPacketConn(packetConn net.PacketConn, timeout time.Duration) (*Listener, error) { if timeout <= 0 { return nil, errors.New("timeout should be greater than zero")