@Test void testMessagesWithPayloadTypeAsCustomTag() { MockClock testClock = new MockClock(); SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, testClock); EventMessage<Object> foo = asEventMessage(1); EventMessage<Object> bar = asEventMessage("bar"); EventMessage<Object> baz = asEventMessage("baz"); MessageTimerMonitor testSubject = MessageTimerMonitor.buildMonitor(PROCESSOR_NAME, meterRegistry, testClock, message -> Tags.of(TagsUtil.PAYLOAD_TYPE_TAG, message.getPayloadType() .getSimpleName())); Map<? super Message<?>, MessageMonitor.MonitorCallback> callbacks = testSubject .onMessagesIngested(Arrays.asList(foo, bar, baz)); testClock.addSeconds(1); callbacks.get(foo).reportSuccess(); callbacks.get(bar).reportFailure(null); callbacks.get(baz).reportIgnored(); Collection<Timer> all = meterRegistry.find(PROCESSOR_NAME + ".allTimer").timers(); Collection<Timer> successTimer = meterRegistry.find(PROCESSOR_NAME + ".successTimer").timers(); Collection<Timer> failureTimer = meterRegistry.find(PROCESSOR_NAME + ".failureTimer").timers(); Collection<Timer> ignoredTimer = meterRegistry.find(PROCESSOR_NAME + ".ignoredTimer").timers(); assertEquals(2, all.size(), 0); assertEquals(2, successTimer.size(), 0); assertEquals(2, failureTimer.size(), 0); assertEquals(2, ignoredTimer.size(), 0); assertTrue(all.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "Integer")) .allMatch(timer -> timer.totalTime(TimeUnit.SECONDS) == 1)); assertTrue(all.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "String")) .allMatch(timer -> (timer.totalTime(TimeUnit.SECONDS) == 2 && timer.max(TimeUnit.SECONDS) == 1))); assertTrue(successTimer.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "Integer")) .allMatch(timer -> timer.totalTime(TimeUnit.SECONDS) == 1)); assertTrue(successTimer.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "String")) .allMatch(timer -> timer.totalTime(TimeUnit.SECONDS) == 0)); assertTrue(failureTimer.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "Integer")) .allMatch(timer -> timer.totalTime(TimeUnit.SECONDS) == 0)); assertTrue(failureTimer.stream() .filter(timer -> Objects.equals(timer.getId().getTag("payloadType"), "String")) .allMatch(timer -> timer.totalTime(TimeUnit.SECONDS) == 1)); }
public static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, Clock.SYSTEM); }
MessageTimerMonitor implements MessageMonitor<Message<?>> { public static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, Clock.SYSTEM); } }
MessageTimerMonitor implements MessageMonitor<Message<?>> { public static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, Clock.SYSTEM); } private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Function<Message<?>, Iterable<Tag>> tagsBuilder,
                                Clock clock); private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Clock clock); }
MessageTimerMonitor implements MessageMonitor<Message<?>> { public static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, Clock.SYSTEM); } private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Function<Message<?>, Iterable<Tag>> tagsBuilder,
                                Clock clock); private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Clock clock); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry,
                                                   Function<Message<?>, Iterable<Tag>> tagsBuilder); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, Clock clock); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, Clock clock,
                                                   Function<Message<?>, Iterable<Tag>> tagsBuilder); @Override MonitorCallback onMessageIngested(Message<?> message); }
MessageTimerMonitor implements MessageMonitor<Message<?>> { public static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry) { return buildMonitor(meterNamePrefix, meterRegistry, Clock.SYSTEM); } private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Function<Message<?>, Iterable<Tag>> tagsBuilder,
                                Clock clock); private  MessageTimerMonitor(String meterNamePrefix,
                                MeterRegistry meterRegistry,
                                Clock clock); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry,
                                                   Function<Message<?>, Iterable<Tag>> tagsBuilder); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, Clock clock); static MessageTimerMonitor buildMonitor(String meterNamePrefix, MeterRegistry meterRegistry, Clock clock,
                                                   Function<Message<?>, Iterable<Tag>> tagsBuilder); @Override MonitorCallback onMessageIngested(Message<?> message);  }