Gauge extends BaseMeter { @Override public MeterData.Builder transform() { double count; try { count = get(); } catch (Exception e) { LOGGER.warn(e, "Cannot get the count in meter:{}", meterId.getName()); return null; } final MeterData.Builder builder = MeterData.newBuilder(); builder.setSingleValue(MeterSingleValue.newBuilder() .setName(getName()) .addAllLabels(transformTags()) .setValue(count).build()); return builder; } Gauge(MeterId meterId, Supplier<Double> getter); double get(); @Override MeterData.Builder transform();  }
@Test public void testTransform() { final List<Label> labels = Arrays.asList(Label.newBuilder().setName("k1").setValue("v1").build()); final Gauge gauge1 = MeterFactory.gauge("test1", () -> 2d).tag("k1", "v1").build(); validateMeterData("test1", labels, 2d, gauge1.transform()); final Gauge gauge2 = MeterFactory.gauge("test2", () -> Double.valueOf(2 / 0)).tag("k1", "v1").build(); Assert.assertNull(gauge2.transform()); final Gauge gauge3 = MeterFactory.gauge("test3", () -> null).tag("k1", "v1").build(); validateMeterData("test3", labels, 0d, gauge3.transform()); }