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

Remove obsreport.ProcessorMetricViews, use BuildProcessorCustomMetricName where needed #3316

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions obsreport/obsreport_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import (
"context"

"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
)

Expand All @@ -34,32 +32,6 @@ func BuildProcessorCustomMetricName(configType, metric string) string {
return buildComponentPrefix(obsmetrics.ProcessorPrefix, configType) + metric
}

// ProcessorMetricViews builds the metric views for custom metrics of processors.
func ProcessorMetricViews(configType string, legacyViews *obsreportconfig.ObsMetrics) *obsreportconfig.ObsMetrics {
var allViews []*view.View
if obsreportconfig.Level != configtelemetry.LevelNone {
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.
if legacyView == nil || legacyView.Measure == nil || legacyView.Aggregation == nil {
continue
}
newView := *legacyView
viewName := legacyView.Name
if viewName == "" {
viewName = legacyView.Measure.Name()
}
newView.Name = BuildProcessorCustomMetricName(configType, viewName)
allViews = append(allViews, &newView)
}
}

return &obsreportconfig.ObsMetrics{
Views: allViews,
}
}

// Processor is a helper to add observability to a component.Processor.
type Processor struct {
level configtelemetry.Level
Expand Down
53 changes: 9 additions & 44 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
"go.opentelemetry.io/collector/receiver/scrapererror"
Expand Down Expand Up @@ -541,56 +538,24 @@ func TestProcessorMetricsData(t *testing.T) {
obsreporttest.CheckProcessorMetrics(t, processor, acceptedPoints, refusedPoints, droppedPoints)
}

func TestProcessorMetricViews(t *testing.T) {
measures := []stats.Measure{
stats.Int64("firstMeasure", "test firstMeasure", stats.UnitDimensionless),
stats.Int64("secondMeasure", "test secondMeasure", stats.UnitBytes),
}
legacyViews := []*view.View{
{
Name: measures[0].Name(),
Description: measures[0].Description(),
Measure: measures[0],
Aggregation: view.Sum(),
},
{
Measure: measures[1],
Aggregation: view.Count(),
},
}

func TestBuildProcessorCustomMetricName(t *testing.T) {
tests := []struct {
name string
level configtelemetry.Level
want []*view.View
name string
want string
}{
{
name: "none",
level: configtelemetry.LevelNone,
name: "firstMeasure",
want: "processor/test_type/firstMeasure",
},
{
name: "basic",
level: configtelemetry.LevelBasic,
want: []*view.View{
{
Name: "processor/test_type/" + measures[0].Name(),
Description: measures[0].Description(),
Measure: measures[0],
Aggregation: view.Sum(),
},
{
Name: "processor/test_type/" + measures[1].Name(),
Measure: measures[1],
Aggregation: view.Count(),
},
},
name: "secondMeasure",
want: "processor/test_type/secondMeasure",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
obsreportconfig.Configure(tt.level)
got := ProcessorMetricViews("test_type", &obsreportconfig.ObsMetrics{Views: legacyViews})
assert.Equal(t, tt.want, got.Views)
got := BuildProcessorCustomMetricName("test_type", tt.name)
assert.Equal(t, tt.want, got)
})
}
}
Expand Down
23 changes: 9 additions & 14 deletions processor/batchprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"

"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
"go.opentelemetry.io/collector/obsreport"
)
Expand All @@ -37,31 +36,31 @@ func MetricViews() []*view.View {
processorTagKeys := []tag.Key{processorTagKey}

countBatchSizeTriggerSendView := &view.View{
Name: statBatchSizeTriggerSend.Name(),
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statBatchSizeTriggerSend.Name()),
Measure: statBatchSizeTriggerSend,
Description: statBatchSizeTriggerSend.Description(),
TagKeys: processorTagKeys,
Aggregation: view.Sum(),
}

countTimeoutTriggerSendView := &view.View{
Name: statTimeoutTriggerSend.Name(),
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statTimeoutTriggerSend.Name()),
Measure: statTimeoutTriggerSend,
Description: statTimeoutTriggerSend.Description(),
TagKeys: processorTagKeys,
Aggregation: view.Sum(),
}

distributionBatchSendSizeView := &view.View{
Name: statBatchSendSize.Name(),
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statBatchSendSize.Name()),
Measure: statBatchSendSize,
Description: statBatchSendSize.Description(),
TagKeys: processorTagKeys,
Aggregation: view.Distribution(10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000, 100000),
}

distributionBatchSendSizeBytesView := &view.View{
Name: statBatchSendSizeBytes.Name(),
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statBatchSendSizeBytes.Name()),
Measure: statBatchSendSizeBytes,
Description: statBatchSendSizeBytes.Description(),
TagKeys: processorTagKeys,
Expand All @@ -70,14 +69,10 @@ func MetricViews() []*view.View {
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000),
}

legacyViews := &obsreportconfig.ObsMetrics{
Views: []*view.View{
countBatchSizeTriggerSendView,
countTimeoutTriggerSendView,
distributionBatchSendSizeView,
distributionBatchSendSizeBytesView,
},
return []*view.View{
countBatchSizeTriggerSendView,
countTimeoutTriggerSendView,
distributionBatchSendSizeView,
distributionBatchSendSizeBytesView,
}

return obsreport.ProcessorMetricViews(typeStr, legacyViews).Views
}