@@ -24,7 +24,8 @@ import (
24
24
"path/filepath"
25
25
"testing"
26
26
27
- "github.com/elastic/opentelemetry-collector-components/connector/elasticapmconnector/internal/metadata"
27
+ "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
28
+ "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
28
29
"github.com/stretchr/testify/assert"
29
30
"github.com/stretchr/testify/require"
30
31
"go.opentelemetry.io/collector/client"
@@ -36,25 +37,43 @@ import (
36
37
"go.opentelemetry.io/collector/pdata/plog"
37
38
"go.opentelemetry.io/collector/pdata/pmetric"
38
39
39
- "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
40
- "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
40
+ "github.com/elastic/opentelemetry-collector-components/connector/elasticapmconnector/internal/metadata"
41
41
)
42
42
43
43
var update = flag .Bool ("update" , false , "Update golden files" )
44
44
45
45
func TestConnector_LogsToMetrics (t * testing.T ) {
46
+ oneCardinalityLimitConfig := LimitConfig {
47
+ MaxCardinality : 1 ,
48
+ }
49
+ oneCardinalityAggregationConfig := Config {
50
+ Aggregation : & AggregationConfig {
51
+ Limit : AggregationLimitConfig {
52
+ ResourceLimit : oneCardinalityLimitConfig ,
53
+ ScopeLimit : oneCardinalityLimitConfig ,
54
+ MetricLimit : oneCardinalityLimitConfig ,
55
+ DatapointLimit : oneCardinalityLimitConfig ,
56
+ },
57
+ },
58
+ }
59
+
46
60
testCases := []struct {
47
61
name string
62
+ cfg * Config
48
63
}{
49
- {name : "logs/service_summary" },
64
+ // output should remain the same for all provided configs
65
+ {name : "logs/service_summary" , cfg : & Config {}},
66
+ {name : "logs/service_summary" , cfg : & oneCardinalityAggregationConfig },
67
+
68
+ // output should show overflow behavior
69
+ {name : "logs/service_summary_overflow" , cfg : & oneCardinalityAggregationConfig },
50
70
}
51
71
52
72
for _ , tc := range testCases {
53
73
t .Run (tc .name , func (t * testing.T ) {
54
74
nextMetrics := & consumertest.MetricsSink {}
55
75
56
- cfg := & Config {}
57
- l2m := newLogsToMetrics (t , connectortest .NewNopSettings (metadata .Type ), cfg , nextMetrics )
76
+ l2m := newLogsToMetrics (t , connectortest .NewNopSettings (metadata .Type ), tc .cfg , nextMetrics )
58
77
59
78
dir := filepath .Join ("testdata" , tc .name )
60
79
input , err := golden .ReadLogs (filepath .Join (dir , "input.yaml" ))
@@ -76,18 +95,37 @@ func TestConnector_LogsToMetrics(t *testing.T) {
76
95
}
77
96
78
97
func TestConnector_MetricsToMetrics (t * testing.T ) {
98
+ oneCardinalityLimitConfig := LimitConfig {
99
+ MaxCardinality : 1 ,
100
+ }
101
+ oneCardinalityAggregationConfig := Config {
102
+ Aggregation : & AggregationConfig {
103
+ Limit : AggregationLimitConfig {
104
+ ResourceLimit : oneCardinalityLimitConfig ,
105
+ ScopeLimit : oneCardinalityLimitConfig ,
106
+ MetricLimit : oneCardinalityLimitConfig ,
107
+ DatapointLimit : oneCardinalityLimitConfig ,
108
+ },
109
+ },
110
+ }
111
+
79
112
testCases := []struct {
80
113
name string
114
+ cfg * Config
81
115
}{
82
- {name : "metrics/service_summary" },
116
+ // output should remain the same for all provided configs
117
+ {name : "metrics/service_summary" , cfg : & Config {}},
118
+ {name : "metrics/service_summary" , cfg : & oneCardinalityAggregationConfig },
119
+
120
+ // output should show overflow
121
+ {name : "metrics/service_summary_overflow" , cfg : & oneCardinalityAggregationConfig },
83
122
}
84
123
85
124
for _ , tc := range testCases {
86
125
t .Run (tc .name , func (t * testing.T ) {
87
126
nextMetrics := & consumertest.MetricsSink {}
88
127
89
- cfg := & Config {}
90
- m2m := newMetricsConnector (t , connectortest .NewNopSettings (metadata .Type ), cfg , nextMetrics )
128
+ m2m := newMetricsConnector (t , connectortest .NewNopSettings (metadata .Type ), tc .cfg , nextMetrics )
91
129
92
130
dir := filepath .Join ("testdata" , tc .name )
93
131
input , err := golden .ReadMetrics (filepath .Join (dir , "input.yaml" ))
@@ -109,19 +147,53 @@ func TestConnector_MetricsToMetrics(t *testing.T) {
109
147
}
110
148
111
149
func TestConnector_TracesToMetrics (t * testing.T ) {
150
+ fourCardinalityLimitConfig := LimitConfig {
151
+ MaxCardinality : 4 , // min limit to prevent overflow behavior
152
+ }
153
+ fourCardinalityAggregationConfig := Config {
154
+ Aggregation : & AggregationConfig {
155
+ Limit : AggregationLimitConfig {
156
+ ResourceLimit : fourCardinalityLimitConfig ,
157
+ ScopeLimit : fourCardinalityLimitConfig ,
158
+ MetricLimit : fourCardinalityLimitConfig ,
159
+ DatapointLimit : fourCardinalityLimitConfig ,
160
+ },
161
+ },
162
+ }
163
+
164
+ oneCardinalityLimitConfig := LimitConfig {
165
+ MaxCardinality : 1 ,
166
+ }
167
+ oneCardinalityAggregationConfig := Config {
168
+ Aggregation : & AggregationConfig {
169
+ Limit : AggregationLimitConfig {
170
+ ResourceLimit : oneCardinalityLimitConfig ,
171
+ ScopeLimit : oneCardinalityLimitConfig ,
172
+ MetricLimit : oneCardinalityLimitConfig ,
173
+ DatapointLimit : oneCardinalityLimitConfig ,
174
+ },
175
+ },
176
+ }
177
+
112
178
testCases := []struct {
113
179
name string
180
+ cfg * Config
114
181
}{
115
- {name : "traces/transaction_metrics" },
116
- {name : "traces/span_metrics" },
182
+ // output should remain the same for all provided configs
183
+ {name : "traces/transaction_metrics" , cfg : & Config {}},
184
+ {name : "traces/transaction_metrics" , cfg : & fourCardinalityAggregationConfig },
185
+ {name : "traces/span_metrics" , cfg : & Config {}},
186
+ {name : "traces/span_metrics" , cfg : & fourCardinalityAggregationConfig },
187
+
188
+ // output should show overflow
189
+ {name : "traces/span_metrics_overflow" , cfg : & oneCardinalityAggregationConfig },
117
190
}
118
191
119
192
for _ , tc := range testCases {
120
193
t .Run (tc .name , func (t * testing.T ) {
121
194
nextMetrics := & consumertest.MetricsSink {}
122
195
123
- cfg := & Config {}
124
- t2m := newTracesConnector (t , connectortest .NewNopSettings (metadata .Type ), cfg , nextMetrics )
196
+ t2m := newTracesConnector (t , connectortest .NewNopSettings (metadata .Type ), tc .cfg , nextMetrics )
125
197
126
198
dir := filepath .Join ("testdata" , tc .name )
127
199
input , err := golden .ReadTraces (filepath .Join (dir , "input.yaml" ))
@@ -159,6 +231,7 @@ func TestConnector_AggregationDirectory(t *testing.T) {
159
231
require .NoError (t , err )
160
232
require .NotEmpty (t , entries )
161
233
}
234
+
162
235
func TestConnector_AggregationMetadataKeys (t * testing.T ) {
163
236
cfg := & Config {Aggregation : & AggregationConfig {MetadataKeys : []string {"k" }}}
164
237
0 commit comments