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