@@ -230,6 +230,22 @@ void toTimerLine() {
230
230
assertThat (lines .get (0 )).isEqualTo ("my.timer,dt.metrics.source=micrometer gauge,min=0.0,max=60.0,sum=90.0,count=3 " + clock .wallTime ());
231
231
}
232
232
233
+ @ Test
234
+ void toTimerLine_DropIfCountIsZero () {
235
+ Timer timer = meterRegistry .timer ("my.timer" );
236
+ timer .record (Duration .ofMillis (60 ));
237
+ clock .add (config .step ());
238
+
239
+ List <String > lines = exporter .toTimerLine (timer ).collect (Collectors .toList ());
240
+ assertThat (lines ).hasSize (1 );
241
+ assertThat (lines .get (0 )).isEqualTo ("my.timer,dt.metrics.source=micrometer gauge,min=60.0,max=60.0,sum=60.0,count=1 " + clock .wallTime ());
242
+
243
+ clock .add (config .step ());
244
+ // Before the update to drop zero count lines, this would contain 1 line (with count=0), which is not desired.
245
+ List <String > zeroCountLines = exporter .toTimerLine (timer ).collect (Collectors .toList ());
246
+ assertThat (zeroCountLines ).isEmpty ();
247
+ }
248
+
233
249
@ Test
234
250
void toFunctionTimerLineShouldDropNanMean () {
235
251
FunctionTimer functionTimer = new FunctionTimer () {
@@ -329,6 +345,22 @@ void testToDistributionSummaryLine() {
329
345
assertThat (lines .get (0 )).isEqualTo ("my.summary,dt.metrics.source=micrometer gauge,min=0.0,max=5.4,sum=10.9,count=4 " + clock .wallTime ());
330
346
}
331
347
348
+ @ Test
349
+ void testToDistributionSummaryLine_DropsLineIfCountIsZero () {
350
+ DistributionSummary summary = DistributionSummary .builder ("my.summary" ).register (meterRegistry );
351
+ summary .record (3.1 );
352
+ clock .add (config .step ());
353
+
354
+ List <String > nonEmptyLines = exporter .toDistributionSummaryLine (summary ).collect (Collectors .toList ());
355
+ assertThat (nonEmptyLines ).hasSize (1 );
356
+ assertThat (nonEmptyLines .get (0 )).isEqualTo ("my.summary,dt.metrics.source=micrometer gauge,min=3.1,max=3.1,sum=3.1,count=1 " + clock .wallTime ());
357
+
358
+ clock .add (config .step ());
359
+ // Before the update to drop zero count lines, this would contain 1 line (with count=0), which is not desired.
360
+ List <String > zeroCountLines = exporter .toDistributionSummaryLine (summary ).collect (Collectors .toList ());
361
+ assertThat (zeroCountLines ).isEmpty ();
362
+ }
363
+
332
364
@ Test
333
365
void toMeterLine () {
334
366
Measurement m1 = new Measurement (() -> 23d , Statistic .VALUE );
0 commit comments