@@ -135,38 +135,34 @@ func TestTranslateV2(t *testing.T) {
135
135
expectedStats remote.WriteResponseStats
136
136
}{
137
137
{
138
- name : "duplicated scope name and version " ,
138
+ name : "missing metric name" ,
139
139
request : & writev2.Request {
140
- Symbols : []string {
141
- "" ,
142
- "__name__" , "test_metric" ,
143
- "job" , "service-x/test" ,
144
- "instance" , "107cn001" ,
145
- "otel_scope_name" , "scope1" ,
146
- "otel_scope_version" , "v1" ,
147
- "otel_scope_name" , "scope2" ,
148
- "otel_scope_version" , "v2" ,
149
- "d" , "e" ,
150
- "foo" , "bar" ,
151
- },
140
+ Symbols : []string {"" , "foo" , "bar" },
152
141
Timeseries : []writev2.TimeSeries {
153
142
{
154
- Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
155
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
143
+ LabelsRefs : []uint32 {1 , 2 },
156
144
Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
157
145
},
146
+ },
147
+ },
148
+ expectError : "missing metric name in labels" ,
149
+ },
150
+ {
151
+ name : "duplicate label" ,
152
+ request : & writev2.Request {
153
+ Symbols : []string {"" , "__name__" , "test" },
154
+ Timeseries : []writev2.TimeSeries {
158
155
{
159
- Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
160
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
161
- Samples : []writev2.Sample {{Value : 2 , Timestamp : 2 }},
162
- },
163
- {
164
- Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
165
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 11 , 12 , 13 , 14 , 17 , 18 },
166
- Samples : []writev2.Sample {{Value : 3 , Timestamp : 3 }},
156
+ LabelsRefs : []uint32 {1 , 2 , 1 , 2 },
157
+ Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
167
158
},
168
159
},
169
160
},
161
+ expectError : `duplicate label "__name__" in labels` ,
162
+ },
163
+ {
164
+ name : "valid request" ,
165
+ request : writeV2RequestFixture ,
170
166
expectedMetrics : func () pmetric.Metrics {
171
167
expected := pmetric .NewMetrics ()
172
168
rm1 := expected .ResourceMetrics ().AppendEmpty ()
@@ -176,61 +172,72 @@ func TestTranslateV2(t *testing.T) {
176
172
rmAttributes1 .PutStr ("service.instance.id" , "107cn001" )
177
173
178
174
sm1 := rm1 .ScopeMetrics ().AppendEmpty ()
179
- sm1 . Scope (). SetName ( "scope1" )
180
- sm1 .Scope ().SetVersion ( "v1 " )
181
-
175
+ // Since we don't define the labels otel_scope_name and otel_scope_version, the default values coming from the receiver settings will be used.
176
+ sm1 .Scope ().SetName ( "OpenTelemetry Collector " )
177
+ sm1 . Scope (). SetVersion ( "latest" )
182
178
dp1 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
183
179
dp1 .SetTimestamp (pcommon .Timestamp (1 * int64 (time .Millisecond )))
184
180
dp1 .SetDoubleValue (1.0 )
185
181
dp1 .Attributes ().PutStr ("d" , "e" )
182
+ dp1 .Attributes ().PutStr ("foo" , "bar" )
186
183
187
184
dp2 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
188
185
dp2 .SetTimestamp (pcommon .Timestamp (2 * int64 (time .Millisecond )))
189
186
dp2 .SetDoubleValue (2.0 )
190
187
dp2 .Attributes ().PutStr ("d" , "e" )
188
+ dp2 .Attributes ().PutStr ("foo" , "bar" )
191
189
192
- sm2 := rm1 .ScopeMetrics ().AppendEmpty ()
193
- sm2 .Scope ().SetName ("scope2" )
194
- sm2 .Scope ().SetVersion ("v2" )
190
+ rm2 := expected .ResourceMetrics ().AppendEmpty ()
191
+ rmAttributes2 := rm2 .Resource ().Attributes ()
192
+ rmAttributes2 .PutStr ("service.name" , "foo" )
193
+ rmAttributes2 .PutStr ("service.instance.id" , "bar" )
195
194
195
+ sm2 := rm2 .ScopeMetrics ().AppendEmpty ()
196
+ sm2 .Scope ().SetName ("OpenTelemetry Collector" )
197
+ sm2 .Scope ().SetVersion ("latest" )
196
198
dp3 := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
197
- dp3 .SetTimestamp (pcommon .Timestamp (3 * int64 (time .Millisecond )))
198
- dp3 .SetDoubleValue (3.0 )
199
+ dp3 .SetTimestamp (pcommon .Timestamp (2 * int64 (time .Millisecond )))
200
+ dp3 .SetDoubleValue (2.0 )
201
+ dp3 .Attributes ().PutStr ("d" , "e" )
199
202
dp3 .Attributes ().PutStr ("foo" , "bar" )
200
203
201
204
return expected
202
205
}(),
203
206
expectedStats : remote.WriteResponseStats {},
204
207
},
205
208
{
206
- name : "missing metric name " ,
209
+ name : "timeseries with different scopes " ,
207
210
request : & writev2.Request {
208
- Symbols : []string {"" , "foo" , "bar" },
211
+ Symbols : []string {
212
+ "" ,
213
+ "__name__" , "test_metric" , // 1, 2
214
+ "job" , "service-x/test" , // 3, 4
215
+ "instance" , "107cn001" , // 5, 6
216
+ "otel_scope_name" , "scope1" , // 7, 8
217
+ "otel_scope_version" , "v1" , // 9, 10
218
+ "otel_scope_name" , "scope2" , // 11, 12
219
+ "otel_scope_version" , "v2" , // 13, 14
220
+ "d" , "e" , // 15, 16
221
+ "foo" , "bar" , // 17, 18
222
+ },
209
223
Timeseries : []writev2.TimeSeries {
210
224
{
211
- LabelsRefs : []uint32 {1 , 2 },
225
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
226
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
212
227
Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
213
228
},
214
- },
215
- },
216
- expectError : "missing metric name in labels" ,
217
- },
218
- {
219
- name : "duplicate label" ,
220
- request : & writev2.Request {
221
- Symbols : []string {"" , "__name__" , "test" },
222
- Timeseries : []writev2.TimeSeries {
223
229
{
224
- LabelsRefs : []uint32 {1 , 2 , 1 , 2 },
225
- Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
230
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
231
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
232
+ Samples : []writev2.Sample {{Value : 2 , Timestamp : 2 }},
233
+ },
234
+ {
235
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
236
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 11 , 12 , 13 , 14 , 17 , 18 },
237
+ Samples : []writev2.Sample {{Value : 3 , Timestamp : 3 }},
226
238
},
227
239
},
228
240
},
229
- expectError : `duplicate label "__name__" in labels` ,
230
- },
231
- {
232
- name : "valid request" ,
233
- request : writeV2RequestFixture ,
234
241
expectedMetrics : func () pmetric.Metrics {
235
242
expected := pmetric .NewMetrics ()
236
243
rm1 := expected .ResourceMetrics ().AppendEmpty ()
@@ -240,27 +247,26 @@ func TestTranslateV2(t *testing.T) {
240
247
rmAttributes1 .PutStr ("service.instance.id" , "107cn001" )
241
248
242
249
sm1 := rm1 .ScopeMetrics ().AppendEmpty ()
250
+ sm1 .Scope ().SetName ("scope1" )
251
+ sm1 .Scope ().SetVersion ("v1" )
252
+
243
253
dp1 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
244
254
dp1 .SetTimestamp (pcommon .Timestamp (1 * int64 (time .Millisecond )))
245
255
dp1 .SetDoubleValue (1.0 )
246
256
dp1 .Attributes ().PutStr ("d" , "e" )
247
- dp1 .Attributes ().PutStr ("foo" , "bar" )
248
257
249
258
dp2 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
250
259
dp2 .SetTimestamp (pcommon .Timestamp (2 * int64 (time .Millisecond )))
251
260
dp2 .SetDoubleValue (2.0 )
252
261
dp2 .Attributes ().PutStr ("d" , "e" )
253
- dp2 .Attributes ().PutStr ("foo" , "bar" )
254
262
255
- rm2 := expected .ResourceMetrics ().AppendEmpty ()
256
- rmAttributes2 := rm2 .Resource ().Attributes ()
257
- rmAttributes2 .PutStr ("service.name" , "foo" )
258
- rmAttributes2 .PutStr ("service.instance.id" , "bar" )
263
+ sm2 := rm1 .ScopeMetrics ().AppendEmpty ()
264
+ sm2 .Scope ().SetName ("scope2" )
265
+ sm2 .Scope ().SetVersion ("v2" )
259
266
260
- dp3 := rm2 .ScopeMetrics ().AppendEmpty ().Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
261
- dp3 .SetTimestamp (pcommon .Timestamp (2 * int64 (time .Millisecond )))
262
- dp3 .SetDoubleValue (2.0 )
263
- dp3 .Attributes ().PutStr ("d" , "e" )
267
+ dp3 := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
268
+ dp3 .SetTimestamp (pcommon .Timestamp (3 * int64 (time .Millisecond )))
269
+ dp3 .SetDoubleValue (3.0 )
264
270
dp3 .Attributes ().PutStr ("foo" , "bar" )
265
271
266
272
return expected
0 commit comments