Java Code Examples for io.micrometer.core.instrument.Tags#empty()

The following examples show how to use io.micrometer.core.instrument.Tags#empty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void queueClearEmptySizeDelegates() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, "foo", Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);
	assertThat(testQueue.size()).isEqualTo(1);

	fuseableSubscriber.onSubscribe(testQueue);

	assertThat(fuseableSubscriber.isEmpty()).as("isEmpty").isFalse();
	assertThat(fuseableSubscriber.size()).as("size").isEqualTo(1);

	fuseableSubscriber.clear();

	assertThat(testQueue.size()).as("original queue impacted").isZero();
	assertThat(fuseableSubscriber.size()).as("size after clear").isEqualTo(0);
}
 
Example 2
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void queueClearEmptySizeDelegates() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);
	assertThat(testQueue.size()).isEqualTo(1);

	fuseableSubscriber.onSubscribe(testQueue);

	assertThat(fuseableSubscriber.isEmpty()).as("isEmpty").isFalse();
	assertThat(fuseableSubscriber.size()).as("size").isEqualTo(1);

	fuseableSubscriber.clear();

	assertThat(testQueue.size()).as("original queue impacted").isZero();
	assertThat(fuseableSubscriber.size()).as("size after clear").isEqualTo(0);
}
 
Example 3
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void requestFusionDelegates() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	fuseableSubscriber.onSubscribe(testQueue);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.SYNC))
			.as("fusion mode SYNC").isEqualTo(Fuseable.SYNC);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.ASYNC))
			.as("fusion mode ASYNC").isEqualTo(Fuseable.ASYNC);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.NONE))
			.as("fusion mode NONE").isEqualTo(Fuseable.NONE);
}
 
Example 4
Source File: DatadogMeterRegistryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void postMetricDescriptionMetadataWhenDescriptionIsEnabledButNull() {
    DatadogConfig config = new DatadogConfig() {

        @Override
        public String get(String key) {
            return null;
        }

        @Override
        public String apiKey() {
            return "fake";
        }
    };

    HttpSender httpSender = mock(HttpSender.class);
    DatadogMeterRegistry registry = DatadogMeterRegistry.builder(config).httpClient(httpSender).build();
    Meter.Id id = new Meter.Id("my.meter", Tags.empty(), null, null, Meter.Type.COUNTER);
    registry.postMetricDescriptionMetadata("my.meter", new DatadogMetricMetadata(id, true));
    verifyNoInteractions(httpSender);
}
 
Example 5
Source File: KafkaProducerMetricsBinder.java    From summerframework with Apache License 2.0 6 votes vote down vote up
private Iterable<Tag> nameTag(ObjectName name) {
    Tags tags = Tags.empty();
    String clientId = name.getKeyProperty("client-id");
    if (clientId != null) {
        tags = Tags.concat(tags, "client.id", clientId);
    }

    String topic = name.getKeyProperty("topic");
    if (topic != null) {
        tags = Tags.concat(tags, "topic", topic);
    }

    String nodeId = name.getKeyProperty("node-id");
    if (nodeId != null) {
        tags = Tags.concat(tags, "node-id", nodeId);
    }
    return tags;
}
 
Example 6
Source File: SimpleMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void newFunctionCounterWhenCountingModeIsCumulativeShouldReturnCumulativeFunctionCounter() {
    SimpleMeterRegistry registry = createRegistry(CountingMode.CUMULATIVE);
    Meter.Id id = new Meter.Id("some.timer", Tags.empty(), null, null, Meter.Type.COUNTER);
    FunctionCounter functionCounter = registry.newFunctionCounter(id, null, (o) -> 0d);
    assertThat(functionCounter).isInstanceOf(CumulativeFunctionCounter.class);
}
 
Example 7
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queueClearEmptySizeWhenQueueSubscriptionNull() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, Tags.empty());

	assertThat(fuseableSubscriber.size()).as("size").isEqualTo(0);
	assertThat(fuseableSubscriber.isEmpty()).as("isEmpty").isTrue();
	assertThatCode(fuseableSubscriber::clear).doesNotThrowAnyException();
}
 
Example 8
Source File: GatewayRouteTagsProvider.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Override
public Tags apply(ServerWebExchange exchange) {
	Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);

	if (route != null) {
		return Tags.of("routeId", route.getId(), "routeUri",
				route.getUri().toString());
	}

	return Tags.empty();
}
 
Example 9
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollSyncTracksOnComplete() {
	//prepare registry with mock clock
	MockClock clock = new MockClock();
	removeRegistry();
	registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
	Metrics.globalRegistry.add(registry);

	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, "foo", Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);

	fuseableSubscriber.onSubscribe(testQueue);
	fuseableSubscriber.requestFusion(Fuseable.SYNC);

	clock.add(Duration.ofMillis(200));
	Integer val1 = fuseableSubscriber.poll();
	clock.add(Duration.ofMillis(123));
	Integer val2 = fuseableSubscriber.poll();

	assertThat(val1).isEqualTo(1);
	assertThat(val2).isNull();

	//test meters
	Timer terminationTimer = registry.find(METER_FLOW_DURATION)
	                          .tags(Tags.of(TAG_ON_COMPLETE))
	                          .timer();

	assertThat(terminationTimer).isNotNull();
	assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323);
}
 
Example 10
Source File: SimpleMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void newFunctionCounterWhenCountingModeIsStepShouldReturnStepFunctionCounter() {
    SimpleMeterRegistry registry = createRegistry(CountingMode.STEP);
    Meter.Id id = new Meter.Id("some.timer", Tags.empty(), null, null, Meter.Type.COUNTER);
    FunctionCounter functionCounter = registry.newFunctionCounter(id, null, (o) -> 0d);
    assertThat(functionCounter).isInstanceOf(StepFunctionCounter.class);
}
 
Example 11
Source File: SimpleMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void newFunctionTimerWhenCountingModeIsStepShouldReturnStepFunctionTimer() {
    SimpleMeterRegistry registry = createRegistry(CountingMode.STEP);
    Meter.Id id = new Meter.Id("some.timer", Tags.empty(), null, null, Meter.Type.TIMER);
    FunctionTimer functionTimer = registry.newFunctionTimer(id, null, (o) -> 0L, (o) -> 0d, TimeUnit.SECONDS);
    assertThat(functionTimer).isInstanceOf(StepFunctionTimer.class);
}
 
Example 12
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollDoesntTrackOnNext() {
	//prepare registry with mock clock
	MockClock clock = new MockClock();
	removeRegistry();
	registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
	Metrics.globalRegistry.add(registry);

	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);

	fuseableSubscriber.onSubscribe(testQueue);
	clock.add(Duration.ofMillis(200));

	Integer val1 = fuseableSubscriber.poll();
	Integer val2 = fuseableSubscriber.poll();

	assertThat(val1).isEqualTo(1);
	assertThat(val2).isNull();

	//test meters
	Timer nextTimer = registry.find(METER_ON_NEXT_DELAY)
			.timer();

	assertThat(nextTimer).as("no onNext delay meter for Mono").isNull();
}
 
Example 13
Source File: TimedHandlerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
    this.registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    this.timedHandler = new TimedHandler(registry, Tags.empty());

    this.server = new Server();
    this.connector = new LocalConnector(server);
    server.addConnector(connector);

    latchHandler = new LatchHandler();

    server.setHandler(latchHandler);
    latchHandler.setHandler(timedHandler);
}
 
Example 14
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queueClearEmptySizeWhenQueueSubscriptionNull() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, "foo", Tags.empty());

	assertThat(fuseableSubscriber.size()).as("size").isEqualTo(0);
	assertThat(fuseableSubscriber.isEmpty()).as("isEmpty").isTrue();
	assertThatCode(fuseableSubscriber::clear).doesNotThrowAnyException();
}
 
Example 15
Source File: MicrometerHttpRequestExecutor.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public HttpResponse execute(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpException {
    Timer.Sample timerSample = Timer.start(registry);

    Tag method = Tag.of("method", request.getRequestLine().getMethod());
    Tag uri = Tag.of("uri", uriMapper.apply(request));
    Tag status = STATUS_UNKNOWN;

    Tags routeTags = exportTagsForRoute ? HttpContextUtils.generateTagsForRoute(context) : Tags.empty();

    try {
        HttpResponse response = super.execute(request, conn, context);
        status = response != null ? Tag.of("status", Integer.toString(response.getStatusLine().getStatusCode())) : STATUS_CLIENT_ERROR;
        return response;
    } catch (IOException | HttpException | RuntimeException e) {
        status = STATUS_IO_ERROR;
        throw e;
    } finally {
        Iterable<Tag> tags = Tags.of(extraTags)
                .and(routeTags)
                .and(uri, method, status);

        timerSample.stop(Timer.builder(METER_NAME)
                .description("Duration of Apache HttpClient request execution")
                .tags(tags)
                .register(registry));
    }
}
 
Example 16
Source File: KafkaConsumerMetrics.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private Iterable<Tag> nameTag(ObjectName name) {
    Tags tags = Tags.empty();

    String clientId = name.getKeyProperty("client-id");
    if (clientId != null) {
        tags = Tags.concat(tags, "client.id", clientId);
    }

    String topic = name.getKeyProperty("topic");
    if (topic != null) {
        tags = Tags.concat(tags, "topic", topic);
    }

    return tags;
}
 
Example 17
Source File: OkHttpConnectionPoolMetricsTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Test
void instanceUsesGivenNamePrefix() {
    OkHttpConnectionPoolMetrics instance = new OkHttpConnectionPoolMetrics(connectionPool, "some.meter", Tags.empty());
    instance.bindTo(registry);
    registry.get("some.meter.connection.count"); // does not throw MeterNotFoundException
}
 
Example 18
Source File: MetricsContext.java    From java-dcp-client with Apache License 2.0 4 votes vote down vote up
public MetricsContext(String prefix) {
  this(prefix, Tags.empty());
}
 
Example 19
Source File: JettySslHandshakeMetrics.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JettySslHandshakeMetrics(MeterRegistry registry) {
    this(registry, Tags.empty());
}
 
Example 20
Source File: JettyConnectionMetrics.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public JettyConnectionMetrics(MeterRegistry registry) {
    this(registry, Tags.empty());
}