diff --git a/CHANGELOG.md b/CHANGELOG.md index ae6f21ce44d..d94b77a5108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ ## 🛑 Breaking changes 🛑 - Remove unused logstest package (#3222) +- Remove the OpenCensus references for the following public APIs in `obsreport` package (#3253) + - `obsreport.Config` + - `obsreport.AllViews` + - `obsreport.ProcessorMetricViews` + ## v0.27.0 Beta diff --git a/obsreport/obsreport.go b/obsreport/obsreport.go index 8bab9ca1c55..79b33164afe 100644 --- a/obsreport/obsreport.go +++ b/obsreport/obsreport.go @@ -36,6 +36,11 @@ var ( okStatus = trace.Status{Code: trace.StatusCodeOK} ) +// ObsMetrics wraps OpenCensus View for Collector observability metrics +type ObsMetrics struct { + Views []*view.View +} + // setParentLink tries to retrieve a span from parentCtx and if one exists // sets its SpanID, TraceID as a link to the given child Span. // It returns true only if it retrieved a parent span from the context. @@ -62,15 +67,19 @@ func setParentLink(parentCtx context.Context, childSpan *trace.Span) bool { // Configure is used to control the settings that will be used by the obsreport // package. -func Configure(level configtelemetry.Level) (views []*view.View) { +func Configure(level configtelemetry.Level) *ObsMetrics { gLevel = level + var views []*view.View if gLevel != configtelemetry.LevelNone { gProcessor.level = level - views = append(views, AllViews()...) + obsMetricViews := AllViews() + views = append(views, obsMetricViews.Views...) } - return views + return &ObsMetrics{ + Views: views, + } } func buildComponentPrefix(componentPrefix, configType string) string { @@ -84,7 +93,8 @@ func buildComponentPrefix(componentPrefix, configType string) string { } // AllViews return the list of all views that needs to be configured. -func AllViews() (views []*view.View) { +func AllViews() *ObsMetrics { + var views []*view.View // Receiver views. measures := []*stats.Int64Measure{ mReceiverAcceptedSpans, @@ -134,7 +144,9 @@ func AllViews() (views []*view.View) { tagKeys = []tag.Key{tagKeyProcessor} views = append(views, genViews(measures, tagKeys, view.Sum())...) - return views + return &ObsMetrics{ + Views: views, + } } func genViews( diff --git a/obsreport/obsreport_processor.go b/obsreport/obsreport_processor.go index e048f329bec..c12a2b27699 100644 --- a/obsreport/obsreport_processor.go +++ b/obsreport/obsreport_processor.go @@ -92,10 +92,10 @@ func BuildProcessorCustomMetricName(configType, metric string) string { } // ProcessorMetricViews builds the metric views for custom metrics of processors. -func ProcessorMetricViews(configType string, legacyViews []*view.View) []*view.View { +func ProcessorMetricViews(configType string, legacyViews *ObsMetrics) *ObsMetrics { var allViews []*view.View if gLevel != configtelemetry.LevelNone { - for _, legacyView := range legacyViews { + for _, legacyView := range legacyViews.Views { // Ignore any nil entry and views without measure or aggregation. // These can't be registered but some code registering legacy views may // ignore the errors. @@ -112,7 +112,9 @@ func ProcessorMetricViews(configType string, legacyViews []*view.View) []*view.V } } - return allViews + return &ObsMetrics{ + Views: allViews, + } } var gProcessor = &Processor{level: configtelemetry.LevelNone} diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 6a28f7599f0..bfdd5eda208 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -68,23 +68,23 @@ func TestConfigure(t *testing.T) { { name: "basic", level: configtelemetry.LevelBasic, - wantViews: obsreport.AllViews(), + wantViews: obsreport.AllViews().Views, }, { name: "normal", level: configtelemetry.LevelNormal, - wantViews: obsreport.AllViews(), + wantViews: obsreport.AllViews().Views, }, { name: "detailed", level: configtelemetry.LevelDetailed, - wantViews: obsreport.AllViews(), + wantViews: obsreport.AllViews().Views, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { gotViews := obsreport.Configure(tt.level) - assert.Equal(t, tt.wantViews, gotViews) + assert.Equal(t, tt.wantViews, gotViews.Views) }) } } @@ -624,8 +624,8 @@ func TestProcessorMetricViews(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { obsreport.Configure(tt.level) - got := obsreport.ProcessorMetricViews("test_type", legacyViews) - assert.Equal(t, tt.want, got) + got := obsreport.ProcessorMetricViews("test_type", &obsreport.ObsMetrics{Views: legacyViews}) + assert.Equal(t, tt.want, got.Views) }) } } diff --git a/obsreport/obsreporttest/obsreporttest.go b/obsreport/obsreporttest/obsreporttest.go index d7b5d701077..69885f4c6a9 100644 --- a/obsreport/obsreporttest/obsreporttest.go +++ b/obsreport/obsreporttest/obsreporttest.go @@ -45,7 +45,8 @@ var ( // SetupRecordedMetricsTest does setup the testing environment to check the metrics recorded by receivers, producers or exporters. // The returned function should be deferred. func SetupRecordedMetricsTest() (func(), error) { - views := obsreport.Configure(configtelemetry.LevelNormal) + obsMetrics := obsreport.Configure(configtelemetry.LevelNormal) + views := obsMetrics.Views err := view.Register(views...) if err != nil { return nil, err diff --git a/processor/batchprocessor/metrics.go b/processor/batchprocessor/metrics.go index 6dbeee02569..1985d240c36 100644 --- a/processor/batchprocessor/metrics.go +++ b/processor/batchprocessor/metrics.go @@ -68,12 +68,14 @@ func MetricViews() []*view.View { 1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000), } - legacyViews := []*view.View{ - countBatchSizeTriggerSendView, - countTimeoutTriggerSendView, - distributionBatchSendSizeView, - distributionBatchSendSizeBytesView, + legacyViews := &obsreport.ObsMetrics{ + Views: []*view.View{ + countBatchSizeTriggerSendView, + countTimeoutTriggerSendView, + distributionBatchSendSizeView, + distributionBatchSendSizeBytesView, + }, } - return obsreport.ProcessorMetricViews(typeStr, legacyViews) + return obsreport.ProcessorMetricViews(typeStr, legacyViews).Views } diff --git a/service/telemetry.go b/service/telemetry.go index 8ac6c91913b..a11cca7bc93 100644 --- a/service/telemetry.go +++ b/service/telemetry.go @@ -61,10 +61,11 @@ func (tel *appTelemetry) init(asyncErrorChannel chan<- error, ballastSizeBytes u } var views []*view.View + obsMetrics := obsreport.Configure(level) views = append(views, batchprocessor.MetricViews()...) views = append(views, jaegerexporter.MetricViews()...) views = append(views, kafkareceiver.MetricViews()...) - views = append(views, obsreport.Configure(level)...) + views = append(views, obsMetrics.Views...) views = append(views, processMetricsViews.Views()...) tel.views = views