@@ -382,6 +382,87 @@ void build_throws_for_non_metric_event() {
382382 assertThrows (IllegalArgumentException .class , () -> builder .buildDocuments (event ));
383383 }
384384
385+ @ Test
386+ void build_summary_skips_quantiles_with_NaN_values () throws Exception {
387+ final Map <String , Object > attributes = Map .of ("service" , "api" );
388+ final List <Quantile > quantiles = Arrays .asList (
389+ new DefaultQuantile (0.5 , Double .NaN ),
390+ new DefaultQuantile (0.99 , 0.8 )
391+ );
392+ final JacksonSummary summary = JacksonSummary .builder ()
393+ .withName ("rpc_latency" )
394+ .withQuantiles (quantiles )
395+ .withQuantilesValueCount (2 )
396+ .withCount (1000L )
397+ .withSum (300.5 )
398+ .withTime (TEST_TIME )
399+ .withAttributes (attributes )
400+ .withEventKind ("SUMMARY" )
401+ .build ();
402+
403+ final List <String > docs = builder .buildDocuments (summary );
404+
405+ assertEquals (3 , docs .size ());
406+
407+ final Map <String , Object > q1 = parseJson (docs .get (0 ));
408+ assertEquals ("__name__ rpc_latency quantile 0.99 service api" , q1 .get ("labels" ));
409+ assertEquals (0.8 , ((Number ) q1 .get ("value" )).doubleValue (), 0.001 );
410+
411+ final Map <String , Object > countDoc = parseJson (docs .get (1 ));
412+ assertEquals ("__name__ rpc_latency_count service api" , countDoc .get ("labels" ));
413+
414+ final Map <String , Object > sumDoc = parseJson (docs .get (2 ));
415+ assertEquals ("__name__ rpc_latency_sum service api" , sumDoc .get ("labels" ));
416+ }
417+
418+ @ Test
419+ void build_summary_skips_all_quantiles_when_all_NaN () throws Exception {
420+ final List <Quantile > quantiles = Arrays .asList (
421+ new DefaultQuantile (0.5 , Double .NaN ),
422+ new DefaultQuantile (0.99 , Double .NaN )
423+ );
424+ final JacksonSummary summary = JacksonSummary .builder ()
425+ .withName ("rpc_latency" )
426+ .withQuantiles (quantiles )
427+ .withQuantilesValueCount (2 )
428+ .withCount (0L )
429+ .withSum (0.0 )
430+ .withTime (TEST_TIME )
431+ .withAttributes (Map .of ())
432+ .withEventKind ("SUMMARY" )
433+ .build ();
434+
435+ final List <String > docs = builder .buildDocuments (summary );
436+
437+ assertEquals (2 , docs .size ());
438+ assertTrue (parseJson (docs .get (0 )).get ("labels" ).toString ().contains ("_count" ));
439+ assertTrue (parseJson (docs .get (1 )).get ("labels" ).toString ().contains ("_sum" ));
440+ }
441+
442+ @ Test
443+ void build_summary_skips_quantiles_with_infinite_values () throws Exception {
444+ final List <Quantile > quantiles = Arrays .asList (
445+ new DefaultQuantile (0.5 , Double .POSITIVE_INFINITY ),
446+ new DefaultQuantile (0.99 , 0.5 )
447+ );
448+ final JacksonSummary summary = JacksonSummary .builder ()
449+ .withName ("latency" )
450+ .withQuantiles (quantiles )
451+ .withQuantilesValueCount (2 )
452+ .withCount (100L )
453+ .withSum (50.0 )
454+ .withTime (TEST_TIME )
455+ .withAttributes (Map .of ())
456+ .withEventKind ("SUMMARY" )
457+ .build ();
458+
459+ final List <String > docs = builder .buildDocuments (summary );
460+
461+ assertEquals (3 , docs .size ());
462+ final Map <String , Object > q1 = parseJson (docs .get (0 ));
463+ assertEquals (0.5 , ((Number ) q1 .get ("value" )).doubleValue (), 0.001 );
464+ }
465+
385466 private Map <String , Object > parseJson (final String json ) throws Exception {
386467 return OBJECT_MAPPER .readValue (json , new TypeReference <Map <String , Object >>() {});
387468 }
0 commit comments