@@ -18,6 +18,7 @@ import (
18
18
"github.com/prometheus/prometheus/storage/remote"
19
19
"github.com/stretchr/testify/assert"
20
20
"go.opentelemetry.io/collector/consumer/consumertest"
21
+ "go.opentelemetry.io/collector/pdata/pcommon"
21
22
"go.opentelemetry.io/collector/pdata/pmetric"
22
23
"go.opentelemetry.io/collector/receiver/receivertest"
23
24
@@ -149,17 +150,17 @@ func TestTranslateV2(t *testing.T) {
149
150
Timeseries : []writev2.TimeSeries {
150
151
{
151
152
Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
152
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 }, // Same scope: scope_name: scope1. scope_version v1
153
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
153
154
Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
154
155
},
155
156
{
156
157
Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
157
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 }, // Same scope: scope_name: scope1. scope_version v1
158
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 },
158
159
Samples : []writev2.Sample {{Value : 2 , Timestamp : 2 }},
159
160
},
160
161
{
161
162
Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
162
- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 11 , 12 , 13 , 14 , 17 , 18 }, // Different scope: scope_name: scope2. scope_version v2
163
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 11 , 12 , 13 , 14 , 17 , 18 },
163
164
Samples : []writev2.Sample {{Value : 3 , Timestamp : 3 }},
164
165
},
165
166
},
@@ -171,19 +172,30 @@ func TestTranslateV2(t *testing.T) {
171
172
rmAttributes1 .PutStr ("service.namespace" , "service-x" )
172
173
rmAttributes1 .PutStr ("service.name" , "test" )
173
174
rmAttributes1 .PutStr ("service.instance.id" , "107cn001" )
175
+
174
176
sm1 := rm1 .ScopeMetrics ().AppendEmpty ()
175
177
sm1 .Scope ().SetName ("scope1" )
176
178
sm1 .Scope ().SetVersion ("v1" )
177
- sm1Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
178
- sm1Attributes .PutStr ("d" , "e" )
179
- sm2Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
180
- sm2Attributes .PutStr ("d" , "e" )
179
+
180
+ dp1 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
181
+ dp1 .SetTimestamp (pcommon .Timestamp (1 * 1e6 ))
182
+ dp1 .SetDoubleValue (1.0 )
183
+ dp1 .Attributes ().PutStr ("d" , "e" )
184
+
185
+ dp2 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
186
+ dp2 .SetTimestamp (pcommon .Timestamp (2 * 1e6 ))
187
+ dp2 .SetDoubleValue (2.0 )
188
+ dp2 .Attributes ().PutStr ("d" , "e" )
181
189
182
190
sm2 := rm1 .ScopeMetrics ().AppendEmpty ()
183
191
sm2 .Scope ().SetName ("scope2" )
184
192
sm2 .Scope ().SetVersion ("v2" )
185
- sm3Attributes := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
186
- sm3Attributes .PutStr ("foo" , "bar" )
193
+
194
+ dp3 := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
195
+ dp3 .SetTimestamp (pcommon .Timestamp (3 * 1e6 ))
196
+ dp3 .SetDoubleValue (3.0 )
197
+ dp3 .Attributes ().PutStr ("foo" , "bar" )
198
+
187
199
return expected
188
200
}(),
189
201
expectedStats : remote.WriteResponseStats {},
@@ -224,23 +236,30 @@ func TestTranslateV2(t *testing.T) {
224
236
rmAttributes1 .PutStr ("service.namespace" , "service-x" )
225
237
rmAttributes1 .PutStr ("service.name" , "test" )
226
238
rmAttributes1 .PutStr ("service.instance.id" , "107cn001" )
239
+
227
240
sm1 := rm1 .ScopeMetrics ().AppendEmpty ()
228
- sm1Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
229
- sm1Attributes .PutStr ("d" , "e" )
230
- sm1Attributes .PutStr ("foo" , "bar" )
231
- // Since we don't check "scope_name" and "scope_version", we end up with duplicated scope metrics for repeated series.
232
- // TODO: Properly handle scope metrics.
233
- sm2Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
234
- sm2Attributes .PutStr ("d" , "e" )
235
- sm2Attributes .PutStr ("foo" , "bar" )
241
+ dp1 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
242
+ dp1 .SetTimestamp (pcommon .Timestamp (1 * 1e6 ))
243
+ dp1 .SetDoubleValue (1.0 )
244
+ dp1 .Attributes ().PutStr ("d" , "e" )
245
+ dp1 .Attributes ().PutStr ("foo" , "bar" )
246
+
247
+ dp2 := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
248
+ dp2 .SetTimestamp (pcommon .Timestamp (2 * 1e6 ))
249
+ dp2 .SetDoubleValue (2.0 )
250
+ dp2 .Attributes ().PutStr ("d" , "e" )
251
+ dp2 .Attributes ().PutStr ("foo" , "bar" )
236
252
237
253
rm2 := expected .ResourceMetrics ().AppendEmpty ()
238
254
rmAttributes2 := rm2 .Resource ().Attributes ()
239
255
rmAttributes2 .PutStr ("service.name" , "foo" )
240
256
rmAttributes2 .PutStr ("service.instance.id" , "bar" )
241
- mAttributes2 := rm2 .ScopeMetrics ().AppendEmpty ().Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
242
- mAttributes2 .PutStr ("d" , "e" )
243
- mAttributes2 .PutStr ("foo" , "bar" )
257
+
258
+ dp3 := rm2 .ScopeMetrics ().AppendEmpty ().Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ()
259
+ dp3 .SetTimestamp (pcommon .Timestamp (2 * 1e6 ))
260
+ dp3 .SetDoubleValue (2.0 )
261
+ dp3 .Attributes ().PutStr ("d" , "e" )
262
+ dp3 .Attributes ().PutStr ("foo" , "bar" )
244
263
245
264
return expected
246
265
}(),
0 commit comments