1717import static org .assertj .core .api .Assertions .assertThat ;
1818import static org .assertj .core .api .Assertions .assertThatCode ;
1919
20- import com .fasterxml .jackson .core .JsonProcessingException ;
21- import com .fasterxml .jackson .databind .ObjectMapper ;
22- import io .opentelemetry .api .common .AttributeType ;
2320import io .opentelemetry .api .common .Attributes ;
2421import io .opentelemetry .api .common .KeyValue ;
2522import io .opentelemetry .api .common .Value ;
@@ -71,7 +68,6 @@ class Otel2PrometheusConverterTest {
7168 "(.|\\ n)*# HELP (?<help>.*)\n # TYPE (?<type>.*)\n (?<metricName>.*)\\ {"
7269 + "otel_scope_foo=\" bar\" ,otel_scope_name=\" scope\" ,"
7370 + "otel_scope_schema_url=\" schemaUrl\" ,otel_scope_version=\" version\" }(.|\\ n)*" );
74- private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
7571
7672 private final Otel2PrometheusConverter converter =
7773 new Otel2PrometheusConverter (
@@ -322,7 +318,7 @@ void prometheusNameCollisionTest_Issue6277() {
322318
323319 @ ParameterizedTest
324320 @ MethodSource ("labelValueSerializationArgs" )
325- void labelValueSerialization (Attributes attributes ) {
321+ void labelValueSerialization (Attributes attributes , String expectedValue ) {
326322 MetricData metricData =
327323 createSampleMetricData ("sample" , "1" , MetricDataType .LONG_SUM , attributes , null );
328324
@@ -333,46 +329,43 @@ void labelValueSerialization(Attributes attributes) {
333329 assertThat (metricSnapshot ).isPresent ();
334330
335331 Labels labels = metricSnapshot .get ().getDataPoints ().get (0 ).getLabels ();
336- attributes .forEach (
337- (key , value ) -> {
338- String labelValue = labels .get (key .getKey ());
339- try {
340- String expectedValue ;
341- if (key .getType () == AttributeType .STRING ) {
342- expectedValue = (String ) value ;
343- } else if (key .getType () == AttributeType .VALUE ) {
344- expectedValue = ((Value <?>) value ).asString ();
345- } else {
346- expectedValue = OBJECT_MAPPER .writeValueAsString (value );
347- }
348- assertThat (labelValue ).isEqualTo (expectedValue );
349- } catch (JsonProcessingException e ) {
350- throw new RuntimeException (e );
351- }
352- });
332+ String labelValue = labels .get ("key" );
333+ assertThat (labelValue ).isEqualTo (expectedValue );
353334 }
354335
355336 private static Stream <Arguments > labelValueSerializationArgs () {
356337 return Stream .of (
357- Arguments .of (Attributes .of (stringKey ("key" ), "stringValue" )),
358- Arguments .of (Attributes .of (booleanKey ("key" ), true )),
359- Arguments .of (Attributes .of (longKey ("key" ), Long .MAX_VALUE )),
360- Arguments .of (Attributes .of (doubleKey ("key" ), 0.12345 )),
338+ Arguments .of (Attributes .of (stringKey ("key" ), "stringValue" ), "stringValue" ),
339+ Arguments .of (Attributes .of (booleanKey ("key" ), true ), "true" ),
340+ Arguments .of (Attributes .of (longKey ("key" ), Long .MAX_VALUE ), "9223372036854775807" ),
341+ Arguments .of (Attributes .of (doubleKey ("key" ), 0.12345 ), "0.12345" ),
361342 Arguments .of (
362343 Attributes .of (
363344 stringArrayKey ("key" ),
364- Arrays .asList ("stringValue1" , "\" +\\ \\ \\ +\b +\f +\n +\r +\t +" + (char ) 0 ))) ,
365- Arguments . of ( Attributes . of ( booleanArrayKey ( "key" ), Arrays . asList ( true , false )) ),
345+ Arrays .asList ("stringValue1" , "\" +\\ \\ \\ +\b +\f +\n +\r +\t +" + (char ) 0 )),
346+ "[ \" stringValue1 \" , \" \\ \" + \\ \\ \\ \\ \\ \\ + \\ b+ \\ f+ \\ n+ \\ r+ \\ t+ \\ u0000 \" ]" ),
366347 Arguments .of (
367- Attributes .of (longArrayKey ("key" ), Arrays .asList (Long .MIN_VALUE , Long .MAX_VALUE ))),
348+ Attributes .of (booleanArrayKey ("key" ), Arrays .asList (true , false )),
349+ "[true,false]" ),
350+ Arguments .of (
351+ Attributes .of (longArrayKey ("key" ), Arrays .asList (Long .MIN_VALUE , Long .MAX_VALUE )),
352+ "[-9223372036854775808,9223372036854775807]" ),
368353 Arguments .of (
369354 Attributes .of (
370- doubleArrayKey ("key" ), Arrays .asList (Double .MIN_VALUE , Double .MAX_VALUE ))),
371- Arguments .of (Attributes .of (valueKey ("key" ), Value .of (new byte [] {1 , 2 , 3 }))),
355+ doubleArrayKey ("key" ), Arrays .asList (Double .MIN_VALUE , Double .MAX_VALUE )),
356+ "[4.9E-324,1.7976931348623157E308]" ),
357+ Arguments .of (
358+ Attributes .of (valueKey ("key" ), Value .of (new byte [] {1 , 2 , 3 })),
359+ "AQID" ),
360+ Arguments .of (
361+ Attributes .of (valueKey ("key" ), Value .of (KeyValue .of ("nested" , Value .of ("value" )))),
362+ "[nested=value]" ),
363+ Arguments .of (
364+ Attributes .of (valueKey ("key" ), Value .of (Value .of ("string" ), Value .of (123L ))),
365+ "[string, 123]" ),
372366 Arguments .of (
373- Attributes .of (valueKey ("key" ), Value .of (KeyValue .of ("nested" , Value .of ("value" ))))),
374- Arguments .of (Attributes .of (valueKey ("key" ), Value .of (Value .of ("string" ), Value .of (123L )))),
375- Arguments .of (Attributes .of (valueKey ("key" ), Value .empty ())));
367+ Attributes .of (valueKey ("key" ), Value .empty ()),
368+ "" ));
376369 }
377370
378371 static MetricData createSampleMetricData (
0 commit comments