Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag to allow enabling otel for internal metrics #4912

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Deprecated `receiverhelper.WithMetrics` in favour of `component.WithMetricsReceiver`
- Deprecated `receiverhelper.WithLogs` in favour of `component.WithLogsReceiver`
- Deprecated `receiverhelper.NewFactory` in favour of `component.NewReceiverFactory`
- Change otel collector to enable open telemetry metrics through feature gate instead of a constant

### 💡 Enhancements 💡

Expand Down
2 changes: 2 additions & 0 deletions config/configtelemetry/configtelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
levelDetailedStr = "detailed"
)

// Deprecated: UseOpenTelemetryForInternalMetrics has been deprecated. Uses feature flag in
// telemetry.useOtelForInternalMetrics to handle this feature
const UseOpenTelemetryForInternalMetrics = false
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

// Level is the level of internal telemetry (metrics, logs, traces about the component itself)
Expand Down
20 changes: 19 additions & 1 deletion service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/prometheus/common/expfmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/service/featuregate"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -80,7 +81,7 @@ func TestCollector_StartAsGoRoutine(t *testing.T) {
}, time.Second*2, time.Millisecond*200)
}

func TestCollector_Start(t *testing.T) {
func testCollectorStartHelper(t *testing.T) {
factories, err := testcomponents.NewDefaultFactories()
require.NoError(t, err)
var once sync.Once
Expand Down Expand Up @@ -135,6 +136,23 @@ func TestCollector_Start(t *testing.T) {
}, time.Second*2, time.Millisecond*200)
}

func TestCollector_Start(t *testing.T) {
testCollectorStartHelper(t)
}

func TestCollector_StartWithOtelInternalMetrics(t *testing.T) {
originalFlag := featuregate.IsEnabled(useOtelForInternalMetricsfeatureGateID)
defer func() {
featuregate.Apply(map[string]bool{
useOtelForInternalMetricsfeatureGateID: originalFlag,
})
}()
featuregate.Apply(map[string]bool{
useOtelForInternalMetricsfeatureGateID: true,
})
testCollectorStartHelper(t)
}

// TestCollector_ShutdownNoop verifies that shutdown can be called even if a collector
// has yet to be started and it will execute without error.
func TestCollector_ShutdownNoop(t *testing.T) {
Expand Down
15 changes: 14 additions & 1 deletion service/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"contrib.go.opencensus.io/exporter/prometheus"
"github.com/google/uuid"
"go.opencensus.io/stats/view"
"go.opentelemetry.io/collector/service/featuregate"
otelprometheus "go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
Expand All @@ -50,8 +51,20 @@ const AddCollectorVersionTag = true
const (
zapKeyTelemetryAddress = "address"
zapKeyTelemetryLevel = "level"

// useOtelForInternalMetricsfeatureGateID is the feature gate ID that controls whether the collector uses open
// telemetry for internal metrics.
useOtelForInternalMetricsfeatureGateID = "telemetry.useOtelForInternalMetrics"
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
)

func init() {
featuregate.Register(featuregate.Gate{
ID: useOtelForInternalMetricsfeatureGateID,
Description: "controls whether the collector to uses open telemetry for internal metrics",
splunkericl marked this conversation as resolved.
Show resolved Hide resolved
Enabled: configtelemetry.UseOpenTelemetryForInternalMetrics,
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
})
}

type collectorTelemetryExporter interface {
init(col *Collector) error
shutdown() error
Expand Down Expand Up @@ -98,7 +111,7 @@ func (tel *colTelemetry) initOnce(col *Collector) error {
instanceID := instanceUUID.String()

var pe http.Handler
if configtelemetry.UseOpenTelemetryForInternalMetrics {
if featuregate.IsEnabled(useOtelForInternalMetricsfeatureGateID) {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
otelHandler, err := tel.initOpenTelemetry()
if err != nil {
return err
Expand Down