From c2449001ad818945e223e07246f344acceb69145 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 15 May 2023 13:30:09 -0700 Subject: [PATCH 1/2] add feature gate for supporting additional exporters This adds the feature-gate `telemetry.useOtelWithExtendedConfigurationForInternalTelemetry` to start adding support for additional exporters for the collector's internal telemetry. Signed-off-by: Alex Boten --- .../codeboten_add-featuregate-telemetry.yaml | 16 ++++++++++++++++ internal/obsreportconfig/obsreportconfig.go | 8 ++++++++ service/service.go | 3 ++- service/telemetry.go | 4 +++- service/telemetry/config.go | 16 ++++++++++++++++ service/telemetry_test.go | 3 ++- 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 .chloggen/codeboten_add-featuregate-telemetry.yaml diff --git a/.chloggen/codeboten_add-featuregate-telemetry.yaml b/.chloggen/codeboten_add-featuregate-telemetry.yaml new file mode 100755 index 00000000000..6c78e93719d --- /dev/null +++ b/.chloggen/codeboten_add-featuregate-telemetry.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add feature gate `telemetry.useOtelWithExtendedConfigurationForInternalTelemetry` to start adding support for exporting internal telemetry" + +# One or more tracking issues or pull requests related to the change +issues: [7641] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/internal/obsreportconfig/obsreportconfig.go b/internal/obsreportconfig/obsreportconfig.go index 21501d6e8d3..3dbbe0ddb8c 100644 --- a/internal/obsreportconfig/obsreportconfig.go +++ b/internal/obsreportconfig/obsreportconfig.go @@ -39,6 +39,14 @@ var DisableHighCardinalityMetricsfeatureGate = featuregate.GlobalRegistry().Must featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+ "cardinality metrics. The gate will be removed when the collector allows for view configuration.")) +// UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate is the feature gate that controls whether the collector +// supports configuring the OpenTelemetry SDK via configuration +var UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate = featuregate.GlobalRegistry().MustRegister( + "telemetry.useOtelWithExtendedConfigurationForInternalTelemetry", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("controls whether the collector supports extended OpenTelemetry"+ + "configuration for internal telemetry")) + // AllViews returns all the OpenCensus views requires by obsreport package. func AllViews(level configtelemetry.Level) []*view.View { if level == configtelemetry.LevelNone { diff --git a/service/service.go b/service/service.go index d28bba03a06..11cffb52d01 100644 --- a/service/service.go +++ b/service/service.go @@ -87,6 +87,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) { useOtel = *set.useOtel } disableHighCard := obsreportconfig.DisableHighCardinalityMetricsfeatureGate.IsEnabled() + extendedConfig := obsreportconfig.UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate.IsEnabled() srv := &Service{ buildInfo: set.BuildInfo, host: &serviceHost{ @@ -98,7 +99,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) { buildInfo: set.BuildInfo, asyncErrorChannel: set.AsyncErrorChannel, }, - telemetryInitializer: newColTelemetry(useOtel, disableHighCard), + telemetryInitializer: newColTelemetry(useOtel, disableHighCard, extendedConfig), } var err error srv.telemetry, err = telemetry.New(ctx, telemetry.Settings{ZapOptions: set.LoggingOptions}, cfg.Telemetry) diff --git a/service/telemetry.go b/service/telemetry.go index 98149ea0ff1..587e1d6341b 100644 --- a/service/telemetry.go +++ b/service/telemetry.go @@ -90,13 +90,15 @@ type telemetryInitializer struct { useOtel bool disableHighCardinality bool + extendedConfig bool } -func newColTelemetry(useOtel bool, disableHighCardinality bool) *telemetryInitializer { +func newColTelemetry(useOtel bool, disableHighCardinality bool, extendedConfig bool) *telemetryInitializer { return &telemetryInitializer{ mp: noop.NewMeterProvider(), useOtel: useOtel, disableHighCardinality: disableHighCardinality, + extendedConfig: extendedConfig, } } diff --git a/service/telemetry/config.go b/service/telemetry/config.go index b508e4727fc..15f07c3f45e 100644 --- a/service/telemetry/config.go +++ b/service/telemetry/config.go @@ -104,6 +104,18 @@ type LogsSamplingConfig struct { Thereafter int `mapstructure:"thereafter"` } +// MetricReader exposes configuration of metric readers to end users. +// TODO: replace this temporary struct w/ auto-generated struct from jsonschema +// +// Experimental: *NOTE* this structure is subject to change or removal in the future. +type MetricReader struct { + // Args corresponds to the JSON schema field "args". + Args any `mapstructure:"args"` + + // Type corresponds to the JSON schema field "type". + Type string `mapstructure:"type"` +} + // MetricsConfig exposes the common Telemetry configuration for one component. // Experimental: *NOTE* this structure is subject to change or removal in the future. type MetricsConfig struct { @@ -116,6 +128,10 @@ type MetricsConfig struct { // Address is the [address]:port that metrics exposition should be bound to. Address string `mapstructure:"address"` + + // Readers allow configuration of metric readers to emit metrics to + // any number of supported backends. + Readers []MetricReader `mapstructure:"metric_readers"` } // TracesConfig exposes the common Telemetry configuration for collector's internal spans. diff --git a/service/telemetry_test.go b/service/telemetry_test.go index e84313993df..12126b28217 100644 --- a/service/telemetry_test.go +++ b/service/telemetry_test.go @@ -113,6 +113,7 @@ func TestTelemetryInit(t *testing.T) { useOtel bool disableHighCard bool expectedMetrics map[string]metricValue + extendedConfig bool }{ { name: "UseOpenCensusForInternalMetrics", @@ -198,7 +199,7 @@ func TestTelemetryInit(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - tel := newColTelemetry(tc.useOtel, tc.disableHighCard) + tel := newColTelemetry(tc.useOtel, tc.disableHighCard, tc.extendedConfig) buildInfo := component.NewDefaultBuildInfo() cfg := telemetry.Config{ Resource: map[string]*string{ From a1ae42b91b65afd746e5e7146b3ac06a85a631e1 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 15 May 2023 14:39:14 -0700 Subject: [PATCH 2/2] review feedback Signed-off-by: Alex Boten --- .chloggen/codeboten_add-featuregate-telemetry.yaml | 2 +- internal/obsreportconfig/obsreportconfig.go | 6 +++--- service/service.go | 2 +- service/telemetry/config.go | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.chloggen/codeboten_add-featuregate-telemetry.yaml b/.chloggen/codeboten_add-featuregate-telemetry.yaml index 6c78e93719d..fb8696f2c91 100755 --- a/.chloggen/codeboten_add-featuregate-telemetry.yaml +++ b/.chloggen/codeboten_add-featuregate-telemetry.yaml @@ -5,7 +5,7 @@ change_type: enhancement component: service # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: "Add feature gate `telemetry.useOtelWithExtendedConfigurationForInternalTelemetry` to start adding support for exporting internal telemetry" +note: "Add feature gate `telemetry.useOtelWithSDKConfigurationForInternalTelemetry` that will add support for configuring the export of internal telemetry to additional destinations in future releases" # One or more tracking issues or pull requests related to the change issues: [7641] diff --git a/internal/obsreportconfig/obsreportconfig.go b/internal/obsreportconfig/obsreportconfig.go index 3dbbe0ddb8c..ab0d101a7ce 100644 --- a/internal/obsreportconfig/obsreportconfig.go +++ b/internal/obsreportconfig/obsreportconfig.go @@ -39,10 +39,10 @@ var DisableHighCardinalityMetricsfeatureGate = featuregate.GlobalRegistry().Must featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+ "cardinality metrics. The gate will be removed when the collector allows for view configuration.")) -// UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate is the feature gate that controls whether the collector +// UseOtelWithSDKConfigurationForInternalTelemetryFeatureGate is the feature gate that controls whether the collector // supports configuring the OpenTelemetry SDK via configuration -var UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate = featuregate.GlobalRegistry().MustRegister( - "telemetry.useOtelWithExtendedConfigurationForInternalTelemetry", +var UseOtelWithSDKConfigurationForInternalTelemetryFeatureGate = featuregate.GlobalRegistry().MustRegister( + "telemetry.useOtelWithSDKConfigurationForInternalTelemetry", featuregate.StageAlpha, featuregate.WithRegisterDescription("controls whether the collector supports extended OpenTelemetry"+ "configuration for internal telemetry")) diff --git a/service/service.go b/service/service.go index 11cffb52d01..c3a2e6b4e60 100644 --- a/service/service.go +++ b/service/service.go @@ -87,7 +87,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) { useOtel = *set.useOtel } disableHighCard := obsreportconfig.DisableHighCardinalityMetricsfeatureGate.IsEnabled() - extendedConfig := obsreportconfig.UseOtelWithExtendedConfigurationForInternalTelemetryFeatureGate.IsEnabled() + extendedConfig := obsreportconfig.UseOtelWithSDKConfigurationForInternalTelemetryFeatureGate.IsEnabled() srv := &Service{ buildInfo: set.BuildInfo, host: &serviceHost{ diff --git a/service/telemetry/config.go b/service/telemetry/config.go index 15f07c3f45e..1a8d2eacca4 100644 --- a/service/telemetry/config.go +++ b/service/telemetry/config.go @@ -106,6 +106,7 @@ type LogsSamplingConfig struct { // MetricReader exposes configuration of metric readers to end users. // TODO: replace this temporary struct w/ auto-generated struct from jsonschema +// https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema // // Experimental: *NOTE* this structure is subject to change or removal in the future. type MetricReader struct {