Skip to content

Commit

Permalink
Add feature flag to allow enabling otel for internal metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
splunkericl committed Feb 23, 2022
1 parent c9c2531 commit 22acfa2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 0 additions & 2 deletions config/configtelemetry/configtelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const (
levelDetailedStr = "detailed"
)

const UseOpenTelemetryForInternalMetrics = false

// Level is the level of internal telemetry (metrics, logs, traces about the component itself)
// that every component should generate.
type Level int32
Expand Down
16 changes: 15 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,19 @@ 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) {
featuregate.Register(featuregate.Gate{
ID: UseOtelForInternalMetricsfeatureGateID,
Description: "controls whether the collector to uses open telemetry for internal metrics",
Enabled: 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
7 changes: 6 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,6 +51,10 @@ 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"
)

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

var pe http.Handler
if configtelemetry.UseOpenTelemetryForInternalMetrics {
if featuregate.IsEnabled(UseOtelForInternalMetricsfeatureGateID) {
otelHandler, err := tel.initOpenTelemetry()
if err != nil {
return err
Expand Down

0 comments on commit 22acfa2

Please sign in to comment.