Search in sources :

Example 1 with SendMessageSampler

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();
        }
    };
}
Also used : Timer(io.micrometer.core.instrument.Timer) Sample(io.micrometer.core.instrument.Timer.Sample) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) Sample(io.micrometer.core.instrument.Timer.Sample) Tags(io.micrometer.core.instrument.Tags)

Example 2 with SendMessageSampler

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());
}
Also used : ProtonQoS(io.vertx.proton.ProtonQoS) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) Tracer(io.opentracing.Tracer) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SendMessageSampler (org.eclipse.hono.client.SendMessageSampler)2 Tags (io.micrometer.core.instrument.Tags)1 Timer (io.micrometer.core.instrument.Timer)1 Sample (io.micrometer.core.instrument.Timer.Sample)1 Tracer (io.opentracing.Tracer)1 Vertx (io.vertx.core.Vertx)1 EventBus (io.vertx.core.eventbus.EventBus)1 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)1 ProtonQoS (io.vertx.proton.ProtonQoS)1 RequestResponseClientConfigProperties (org.eclipse.hono.client.RequestResponseClientConfigProperties)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1