Skip to content

Commit

Permalink
[service] add service.disableOpenCensusBridge gate
Browse files Browse the repository at this point in the history
This feature gate allows end users to re-enable the opencensus bridge if there's a need for it. This preceeds open-telemetry#10406 and will be taken out of draft once open-telemetry/opentelemetry-collector-contrib#29867 is completed.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten committed Jul 4, 2024
1 parent 18e78af commit 47ad327
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
5 changes: 5 additions & 0 deletions internal/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ var UseUnifiedEnvVarExpansionRules = featuregate.GlobalRegistry().MustRegister("
featuregate.StageBeta,
featuregate.WithRegisterFromVersion("v0.103.0"),
featuregate.WithRegisterDescription("`${FOO}` will now be expanded as if it was `${env:FOO}` and no longer expands $ENV syntax. See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details. When this feature gate is stable, expandconverter will be removed."))

var DisableOpenCensusBridge = featuregate.GlobalRegistry().MustRegister("service.disableOpenCensusBridge",
featuregate.StageBeta,
featuregate.WithRegisterFromVersion("v0.104.0"),
featuregate.WithRegisterDescription("`Disables the OpenCensus bridge meaning any component still using the OpenCensus SDK will no longer be able to produce telemetry."))
17 changes: 12 additions & 5 deletions service/internal/proctelemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"

"go.opentelemetry.io/collector/internal/featuregates"
"go.opentelemetry.io/collector/processor/processorhelper"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
)
Expand Down Expand Up @@ -67,8 +68,10 @@ func InitMetricReader(ctx context.Context, reader config.MetricReader, asyncErro
return initPullExporter(reader.Pull.Exporter, asyncErrorChannel)
}
if reader.Periodic != nil {
opts := []sdkmetric.PeriodicReaderOption{
sdkmetric.WithProducer(opencensus.NewMetricProducer()),
var opts []sdkmetric.PeriodicReaderOption

if !featuregates.DisableOpenCensusBridge.IsEnabled() {
opts = append(opts, sdkmetric.WithProducer(opencensus.NewMetricProducer()))
}
if reader.Periodic.Interval != nil {
opts = append(opts, sdkmetric.WithInterval(time.Duration(*reader.Periodic.Interval)*time.Millisecond))
Expand Down Expand Up @@ -160,18 +163,22 @@ func initPrometheusExporter(prometheusConfig *config.Prometheus, asyncErrorChann
if prometheusConfig.Port == nil {
return nil, nil, fmt.Errorf("port must be specified")
}
exporter, err := otelprom.New(

opts := []otelprom.Option{
otelprom.WithRegisterer(promRegistry),
// https://github.com/open-telemetry/opentelemetry-collector/issues/8043
otelprom.WithoutUnits(),
// Disabled for the moment until this becomes stable, and we are ready to break backwards compatibility.
otelprom.WithoutScopeInfo(),
otelprom.WithProducer(opencensus.NewMetricProducer()),
// This allows us to produce metrics that are backwards compatible w/ opencensus
otelprom.WithoutCounterSuffixes(),
otelprom.WithNamespace("otelcol"),
otelprom.WithResourceAsConstantLabels(attribute.NewDenyKeysFilter()),
)
}
if !featuregates.DisableOpenCensusBridge.IsEnabled() {
opts = append(opts, otelprom.WithProducer(opencensus.NewMetricProducer()))
}
exporter, err := otelprom.New(opts...)
if err != nil {
return nil, nil, fmt.Errorf("error creating otel prometheus exporter: %w", err)
}
Expand Down
60 changes: 55 additions & 5 deletions service/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/featuregates"
"go.opentelemetry.io/collector/internal/testutil"
semconv "go.opentelemetry.io/collector/semconv/v1.18.0"
"go.opentelemetry.io/collector/service/internal/proctelemetry"
Expand All @@ -42,11 +44,12 @@ func TestTelemetryInit(t *testing.T) {
}

for _, tc := range []struct {
name string
disableHighCard bool
expectedMetrics map[string]metricValue
extendedConfig bool
cfg *telemetry.Config
name string
disableHighCard bool
disableCensusBridge bool
expectedMetrics map[string]metricValue
extendedConfig bool
cfg *telemetry.Config
}{
{
name: "UseOpenTelemetryForInternalMetrics",
Expand Down Expand Up @@ -214,8 +217,55 @@ func TestTelemetryInit(t *testing.T) {
},
},
},
{
name: "DisableOpenCensusBridge",
expectedMetrics: map[string]metricValue{
metricPrefix + otelPrefix + counterName: {
value: 13,
labels: map[string]string{
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
},
},
metricPrefix + grpcPrefix + counterName: {
value: 11,
labels: map[string]string{
"net_sock_peer_addr": "",
"net_sock_peer_name": "",
"net_sock_peer_port": "",
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
},
},
metricPrefix + httpPrefix + counterName: {
value: 10,
labels: map[string]string{
"net_host_name": "",
"net_host_port": "",
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
},
},
"target_info": {
value: 0,
labels: map[string]string{
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
},
},
},
disableCensusBridge: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
require.NoError(t, featuregate.GlobalRegistry().Set(featuregates.DisableOpenCensusBridge.ID(), tc.disableCensusBridge))
t.Cleanup(func() {
require.NoError(t, featuregate.GlobalRegistry().Set(featuregates.DisableOpenCensusBridge.ID(), true))
})
if tc.extendedConfig {
tc.cfg.Metrics.Readers = []config.MetricReader{
{
Expand Down

0 comments on commit 47ad327

Please sign in to comment.