use of org.eclipse.hono.client.SendMessageSampler in project hono by eclipse.
the class MicrometerBasedMetrics method create.
@Override
public SendMessageSampler create(final String messageType) {
Objects.requireNonNull(messageType);
return new SendMessageSampler() {
@Override
public Sample start(final String tenantId) {
final Timer.Sample sample = Timer.start(registry);
return new Sample() {
@Override
public void completed(final String outcome) {
final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId), Tag.of("outcome", outcome));
sample.stop(registry.timer(METER_DOWNSTREAM_SENT, tags));
}
@Override
public void timeout() {
/*
* We report timeouts with a different meter, since the message might still be
* accepted by the remote peer, at a time after the timeout expired. And so we
* can still track those times.
*/
final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId));
registry.counter(METER_DOWNSTREAM_TIMEOUT, tags).increment();
}
};
}
@Override
public void queueFull(final String tenantId) {
final Tags tags = Tags.of(Tag.of(MetricsTags.TAG_TYPE, messageType), MetricsTags.getTenantTag(tenantId));
registry.counter(METER_DOWNSTREAM_FULL, tags).increment();
}
};
}
use of org.eclipse.hono.client.SendMessageSampler in project hono by eclipse.
the class RequestResponseClientTest method setUp.
/**
* Sets up the fixture.
*/
@BeforeEach
public void setUp() {
span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
final EventBus eventBus = mock(EventBus.class);
vertx = mock(Vertx.class);
when(vertx.eventBus()).thenReturn(eventBus);
receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
sender = AmqpClientUnitTestHelper.mockProtonSender();
final SendMessageSampler sampler = mock(SendMessageSampler.class);
sample = mock(SendMessageSampler.Sample.class);
when(sampler.start(anyString())).thenReturn(sample);
clientConfig = new RequestResponseClientConfigProperties();
connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, clientConfig, tracer);
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
when(connection.createSender(anyString(), any(ProtonQoS.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(sender));
client = RequestResponseClient.forEndpoint(connection, "ep", "tenant", sampler, VertxMockSupport.mockHandler(), VertxMockSupport.mockHandler());
}
Aggregations