@@ -143,6 +143,63 @@ func TestTranslateV2(t *testing.T) {
143
143
expectedMetrics pmetric.Metrics
144
144
expectedStats remote.WriteResponseStats
145
145
}{
146
+ {
147
+ name : "duplicated scope name and version" ,
148
+ request : & writev2.Request {
149
+ Symbols : []string {
150
+ "" ,
151
+ "__name__" , "test_metric" ,
152
+ "job" , "service-x/test" ,
153
+ "instance" , "107cn001" ,
154
+ "otel_scope_name" , "scope1" ,
155
+ "otel_scope_version" , "v1" ,
156
+ "otel_scope_name" , "scope2" ,
157
+ "otel_scope_version" , "v2" ,
158
+ "d" , "e" ,
159
+ "foo" , "bar" ,
160
+ },
161
+ Timeseries : []writev2.TimeSeries {
162
+ {
163
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
164
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 }, // Same scope: scope_name: scope1. scope_version v1
165
+ Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
166
+ },
167
+ {
168
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
169
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 15 , 16 }, // Same scope: scope_name: scope1. scope_version v1
170
+ Samples : []writev2.Sample {{Value : 2 , Timestamp : 2 }},
171
+ },
172
+ {
173
+ Metadata : writev2.Metadata {Type : writev2 .Metadata_METRIC_TYPE_GAUGE },
174
+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 11 , 12 , 13 , 14 , 17 , 18 }, // Different scope: scope_name: scope2. scope_version v2
175
+ Samples : []writev2.Sample {{Value : 3 , Timestamp : 3 }},
176
+ },
177
+ },
178
+ },
179
+ expectedMetrics : func () pmetric.Metrics {
180
+ expected := pmetric .NewMetrics ()
181
+ rm1 := expected .ResourceMetrics ().AppendEmpty ()
182
+ rmAttributes1 := rm1 .Resource ().Attributes ()
183
+ rmAttributes1 .PutStr ("service.namespace" , "service-x" )
184
+ rmAttributes1 .PutStr ("service.name" , "test" )
185
+ rmAttributes1 .PutStr ("service.instance.id" , "107cn001" )
186
+ sm1 := rm1 .ScopeMetrics ().AppendEmpty ()
187
+ sm1 .Scope ().SetName ("scope1" )
188
+ sm1 .Scope ().SetVersion ("v1" )
189
+ sm1Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
190
+ sm1Attributes .PutStr ("d" , "e" )
191
+ sm2Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
192
+ sm2Attributes .PutStr ("d" , "e" )
193
+
194
+ sm2 := rm1 .ScopeMetrics ().AppendEmpty ()
195
+ sm2 .Scope ().SetName ("scope2" )
196
+ sm2 .Scope ().SetVersion ("v2" )
197
+ sm3Attributes := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
198
+ sm3Attributes .PutStr ("foo" , "bar" )
199
+ return expected
200
+ }(),
201
+ expectedStats : remote.WriteResponseStats {},
202
+ },
146
203
{
147
204
name : "missing metric name" ,
148
205
request : & writev2.Request {
@@ -185,8 +242,7 @@ func TestTranslateV2(t *testing.T) {
185
242
sm1Attributes .PutStr ("foo" , "bar" )
186
243
// Since we don't check "scope_name" and "scope_version", we end up with duplicated scope metrics for repeated series.
187
244
// TODO: Properly handle scope metrics.
188
- sm2 := rm1 .ScopeMetrics ().AppendEmpty ()
189
- sm2Attributes := sm2 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
245
+ sm2Attributes := sm1 .Metrics ().AppendEmpty ().SetEmptyGauge ().DataPoints ().AppendEmpty ().Attributes ()
190
246
sm2Attributes .PutStr ("d" , "e" )
191
247
sm2Attributes .PutStr ("foo" , "bar" )
192
248
0 commit comments