Skip to content

Commit

Permalink
[service] add service.disableOpenCensusBridge gate (#10542)
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 #10406 and will be taken out of
draft once
open-telemetry/opentelemetry-collector-contrib#29867
is completed.

Related to
#10414

---------

Signed-off-by: Alex Boten <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
codeboten and mx-psi authored Jul 9, 2024
1 parent d37fe6c commit 650ac0b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 11 deletions.
25 changes: 25 additions & 0 deletions .chloggen/codeboten_census-feature-gate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# 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 `service.disableOpenCensusBridge` feature gate which is enabled by default to remove the dependency on OpenCensus"

# One or more tracking issues or pull requests related to the change
issues: [10414]

# (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:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
5 changes: 5 additions & 0 deletions internal/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ var StrictlyTypedInputGate = featuregate.GlobalRegistry().MustRegister(StrictlyT
featuregate.WithRegisterFromVersion("v0.103.0"),
featuregate.WithRegisterDescription("Makes type casting rules during configuration unmarshaling stricter. See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/env-vars.md for more details."),
)

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."))
2 changes: 1 addition & 1 deletion service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
go.opentelemetry.io/collector/extension v0.104.0
go.opentelemetry.io/collector/extension/zpagesextension v0.104.0
go.opentelemetry.io/collector/featuregate v1.11.0
go.opentelemetry.io/collector/internal/featuregates v0.0.0-20240705161705-b127da089038
go.opentelemetry.io/collector/pdata v1.11.0
go.opentelemetry.io/collector/pdata/testdata v0.104.0
go.opentelemetry.io/collector/processor v0.104.0
Expand Down Expand Up @@ -85,7 +86,6 @@ require (
go.opentelemetry.io/collector/config/configtls v0.104.0 // indirect
go.opentelemetry.io/collector/config/internal v0.104.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.104.0 // indirect
go.opentelemetry.io/collector/internal/featuregates v0.0.0-20240705161705-b127da089038 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.104.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/contrib/zpages v0.53.0 // indirect
Expand Down
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
5 changes: 5 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/internal/featuregates"
"go.opentelemetry.io/collector/internal/localhostgate"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -113,6 +114,10 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {
}

logger.Info("Setting up own telemetry...")

if featuregates.DisableOpenCensusBridge.IsEnabled() {
logger.Info("OpenCensus bridge is disabled for Collector telemetry and will be removed in a future version, use --feature-gates=-service.disableOpenCensusBridge to re-enable")
}
mp, err := newMeterProvider(
meterProviderSettings{
res: res,
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 650ac0b

Please sign in to comment.