77 "testing"
88
99 "github.com/stretchr/testify/assert"
10+ "github.com/stretchr/testify/require"
1011
1112 "go.opentelemetry.io/collector/config/configtelemetry"
1213)
@@ -21,17 +22,17 @@ func TestDefaultViews(t *testing.T) {
2122 {
2223 name : "None" ,
2324 level : configtelemetry .LevelNone ,
24- wantViewsCount : 16 ,
25+ wantViewsCount : 17 ,
2526 },
2627 {
2728 name : "Basic" ,
2829 level : configtelemetry .LevelBasic ,
29- wantViewsCount : 16 ,
30+ wantViewsCount : 17 ,
3031 },
3132 {
3233 name : "Normal" ,
3334 level : configtelemetry .LevelNormal ,
34- wantViewsCount : 13 ,
35+ wantViewsCount : 14 ,
3536 },
3637 {
3738 name : "Detailed" ,
@@ -45,3 +46,70 @@ func TestDefaultViews(t *testing.T) {
4546 })
4647 }
4748}
49+
50+ func TestDefaultViews_BatchExporterMetrics (t * testing.T ) {
51+ tests := []struct {
52+ name string
53+ level configtelemetry.Level
54+ shouldDropBucket bool
55+ shouldDropBytes bool
56+ }{
57+ {
58+ name : "basic level drops bucket and bytes" ,
59+ level : configtelemetry .LevelBasic ,
60+ shouldDropBucket : true ,
61+ shouldDropBytes : true ,
62+ },
63+ {
64+ name : "normal level drops bucket and bytes" ,
65+ level : configtelemetry .LevelNormal ,
66+ shouldDropBucket : true ,
67+ shouldDropBytes : true ,
68+ },
69+ {
70+ name : "detailed level does not drop bucket or bytes" ,
71+ level : configtelemetry .LevelDetailed ,
72+ shouldDropBucket : false ,
73+ shouldDropBytes : false ,
74+ },
75+ }
76+
77+ for _ , tt := range tests {
78+ t .Run (tt .name , func (t * testing.T ) {
79+ views := DefaultViews (tt .level )
80+
81+ exporterHelperScope := "go.opentelemetry.io/collector/exporter/exporterhelper"
82+ bucketMetricName := "otelcol_exporter_queue_batch_send_size"
83+ bytesMetricName := "otelcol_exporter_queue_batch_send_size_bytes"
84+
85+ var foundBucketDrop , foundBytesDrop bool
86+ for _ , view := range views {
87+ if view .Selector != nil {
88+ if view .Selector .MeterName != nil && * view .Selector .MeterName == exporterHelperScope {
89+ if view .Selector .InstrumentName != nil {
90+ if * view .Selector .InstrumentName == bucketMetricName {
91+ foundBucketDrop = true
92+ // Verify it's a drop view
93+ require .NotNil (t , view .Stream )
94+ require .NotNil (t , view .Stream .Aggregation )
95+ require .NotNil (t , view .Stream .Aggregation .Drop )
96+ }
97+ if * view .Selector .InstrumentName == bytesMetricName {
98+ foundBytesDrop = true
99+ // Verify it's a drop view
100+ require .NotNil (t , view .Stream )
101+ require .NotNil (t , view .Stream .Aggregation )
102+ require .NotNil (t , view .Stream .Aggregation .Drop )
103+ }
104+ }
105+ }
106+ }
107+ }
108+
109+ assert .Equal (t , tt .shouldDropBucket , foundBucketDrop ,
110+ "bucket metric drop view should be %v for level %v" , tt .shouldDropBucket , tt .level )
111+ assert .Equal (t , tt .shouldDropBytes , foundBytesDrop ,
112+ "bytes metric drop view should be %v for level %v" , tt .shouldDropBytes , tt .level )
113+ })
114+ }
115+ }
0 commit comments