@@ -80,6 +80,11 @@ void serializeDistributionSummary() {
8080 serializeOneMeter (new TestSummary ());
8181 }
8282
83+ @ Test
84+ void serializeDistributionSummaryWithNoValues () {
85+ serializeOneMeter (new TestSummary (false ));
86+ }
87+
8388 @ Test
8489 void serializeGauge () {
8590 serializeOneMeter (new TestGauge ());
@@ -201,9 +206,18 @@ protected static void checkPathHasValue(JsonNode jsonNode, String[] path, int va
201206 }
202207
203208 protected static JsonNode getPathNode (JsonNode jsonNode , String [] path ) {
209+ return getPathNode (jsonNode , path , false );
210+ }
211+ protected static JsonNode getPathNode (JsonNode jsonNode , String [] path , boolean isNull ) {
204212 assertThat (jsonNode ).isNotNull ();
205- for (String element : path ) {
206- jsonNode = jsonNode .get (element );
213+ for (int i = 0 ; i < path .length -1 ; i ++) {
214+ jsonNode = jsonNode .get (path [i ]);
215+ assertThat (jsonNode ).isNotNull ();
216+ }
217+ jsonNode = jsonNode .get (path [path .length -1 ]);
218+ if (isNull ) {
219+ assertThat (jsonNode ).isNull ();
220+ } else {
207221 assertThat (jsonNode ).isNotNull ();
208222 }
209223 return jsonNode ;
@@ -261,26 +275,42 @@ public void checkSerialization(JsonNode jsonNode) {
261275 }
262276
263277 static class TestSummary extends TestMeter {
278+ private final boolean setSLOs ;
264279 int sum = 0 ;
265280 int count = 0 ;
266281 int under5Count = 0 ;
267282 int from5To50Count = 0 ;
268283 int from50to95Count = 0 ;
269284 int [] values = new int []{22 , 55 , 66 , 98 };
270285
286+ public TestSummary () {
287+ this (true );
288+ }
289+ public TestSummary (boolean setSLOs ) {
290+ super ();
291+ this .setSLOs = setSLOs ;
292+ }
271293 @ Override
272294 String meternameExtension () {
273295 return ".count" ;
274296 }
275297
276298 @ Override
277299 public void addToMeterRegistry (MeterRegistry registry ) {
278- meter = DistributionSummary
279- .builder (metername ())
280- .distributionStatisticBufferLength (20 )
281- .serviceLevelObjectives (5 , 50 , 95 )
282- .publishPercentileHistogram ()
283- .register (registry );
300+ if (setSLOs ) {
301+ meter = DistributionSummary
302+ .builder (metername ())
303+ .distributionStatisticBufferLength (20 )
304+ .serviceLevelObjectives (5 , 50 , 95 )
305+ .publishPercentileHistogram ()
306+ .register (registry );
307+ } else {
308+ meter = DistributionSummary
309+ .builder (metername ())
310+ .distributionStatisticBufferLength (20 )
311+ .publishPercentileHistogram ()
312+ .register (registry );
313+ }
284314 }
285315
286316 @ Override
@@ -303,9 +333,20 @@ public void populateValues() {
303333 public void checkSerialization (JsonNode jsonNode ) {
304334 checkPathHasValue (jsonNode , path (), count );
305335 checkPathHasValue (jsonNode , path (".sum" ), sum );
306- String [] path = path (".histogram" );
307- path [3 ] = "values" ;
308- JsonNode histoNode1 = getPathNode (jsonNode , path );
336+ String [] temppath = path (".histogram" );
337+ String [] path ;
338+ if (!setSLOs ) {
339+ path = new String [temppath .length -1 ];
340+ System .arraycopy (temppath , 0 , path , 0 , path .length );
341+ } else {
342+ path = temppath ;
343+ path [3 ] = "values" ;
344+ }
345+ JsonNode histoNode1 = getPathNode (jsonNode , path , !setSLOs );
346+ if (!setSLOs ) {
347+ assertThat (histoNode1 ).isNull ();
348+ return ;
349+ }
309350 assertThat (histoNode1 .isArray ()).isTrue ();
310351 assertThat (histoNode1 .size ()).isEqualTo (3 ); //the 3 bucket boundaries of the SLOs 5,50,95
311352 assertThat (histoNode1 .get (0 ).asDouble ()).isEqualTo (5.0 );
0 commit comments