@Test void testCapacityWithMetadataAsCustomTag() { MockClock testClock = new MockClock(); SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry(); CapacityMonitor testSubject = CapacityMonitor.buildMonitor("1", meterRegistry, 1, TimeUnit.SECONDS, testClock, message -> Tags.of("myPayloadType", message.getPayloadType() .getSimpleName(), "myMetaData", message.getMetaData() .get("myMetadataKey") .toString())); EventMessage<Object> foo = asEventMessage(1).withMetaData(Collections.singletonMap("myMetadataKey", "myMetadataValue1")); EventMessage<Object> bar = asEventMessage("bar").withMetaData(Collections.singletonMap("myMetadataKey", "myMetadataValue2")); Map<? super Message<?>, MessageMonitor.MonitorCallback> callbacks = testSubject .onMessagesIngested(Arrays.asList(foo, bar)); testClock.addSeconds(1); callbacks.get(foo).reportSuccess(); callbacks.get(bar).reportFailure(null); Collection<Gauge> capacityGauges = meterRegistry.find("1.capacity").gauges(); assertEquals(2, capacityGauges.size(), 0); assertTrue(capacityGauges.stream() .anyMatch(gauge -> Objects.equals(gauge.getId().getTag("myPayloadType"), "Integer"))); assertTrue(capacityGauges.stream() .anyMatch(gauge -> Objects.equals(gauge.getId().getTag("myPayloadType"), "String"))); assertTrue(capacityGauges.stream() .anyMatch(gauge -> Objects .equals(gauge.getId().getTag("myMetaData"), "myMetadataValue1"))); assertTrue(capacityGauges.stream() .anyMatch(gauge -> Objects .equals(gauge.getId().getTag("myMetaData"), "myMetadataValue2"))); }
public static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, 10, TimeUnit.MINUTES); }
CapacityMonitor implements MessageMonitor<Message<?>> { public static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, 10, TimeUnit.MINUTES); } }
CapacityMonitor implements MessageMonitor<Message<?>> { public static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, 10, TimeUnit.MINUTES); } private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry); private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry,
                            Function<Message<?>, Iterable<Tag>> tagsBuilder); }
CapacityMonitor implements MessageMonitor<Message<?>> { public static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, 10, TimeUnit.MINUTES); } private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry); private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry,
                            Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry,
                                               Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Clock clock); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Clock clock,
                                               Function<Message<?>, Iterable<Tag>> tagsBuilder); @Override MonitorCallback onMessageIngested(Message<?> message); }
CapacityMonitor implements MessageMonitor<Message<?>> { public static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, 10, TimeUnit.MINUTES); } private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry); private  CapacityMonitor(long window, TimeUnit timeUnit, Clock clock, String meterNamePrefix,
                            MeterRegistry meterRegistry,
                            Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry,
                                               Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Function<Message<?>, Iterable<Tag>> tagsBuilder); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Clock clock); static CapacityMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, long window,
                                               TimeUnit timeUnit, Clock clock,
                                               Function<Message<?>, Iterable<Tag>> tagsBuilder); @Override MonitorCallback onMessageIngested(Message<?> message);  }