io.micrometer.core.instrument.simple.SimpleConfig Java Examples

The following examples show how to use io.micrometer.core.instrument.simple.SimpleConfig. 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: DistributionSummaryTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Test
void histogramsInStepMode() {
    MockClock clock = new MockClock();
    MeterRegistry registry = new SimpleMeterRegistry(new SimpleConfig() {
        @Override
        public String get(String key) {
            return null;
        }

        @Override
        public CountingMode mode() {
            return CountingMode.STEP;
        }
    }, clock);

    DistributionSummary summary = DistributionSummary.builder("my.summary")
            .serviceLevelObjectives(1.0)
            .register(registry);

    summary.record(1);

    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1.0, 1));
    clock.add(SimpleConfig.DEFAULT.step());
    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1.0, 0));
}
 
Example #2
Source File: UptimeMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void uptimeMetricsMock() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    RuntimeMXBean runtimeMXBean = mock(RuntimeMXBean.class);
    when(runtimeMXBean.getUptime()).thenReturn(1337L);
    when(runtimeMXBean.getStartTime()).thenReturn(4711L);
    new UptimeMetrics(runtimeMXBean, emptyList()).bindTo(registry);

    assertThat(registry.get("process.uptime").timeGauge().value()).isEqualTo(1.337);
    assertThat(registry.get("process.start.time").timeGauge().value()).isEqualTo(4.711);
}
 
Example #3
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollTracksOnNext() {
	//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);
	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).isNotNull();
	assertThat(nextTimer.max(TimeUnit.MILLISECONDS)).as("onNext max delay").isEqualTo(200);
}
 
Example #4
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 #5
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollError() {
	//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());

	FluxPeekFuseableTest.AssertQueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.setCompleteWithError(true);
	testQueue.offer(1);

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

	clock.add(Duration.ofMillis(200));
	Integer val1 = fuseableSubscriber.poll();
	assertThat(val1).isEqualTo(1);

	clock.add(Duration.ofMillis(123));
	assertThatIllegalStateException().isThrownBy(fuseableSubscriber::poll)
	                                 .withMessage("AssertQueueSubscriber poll error");

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

	assertThat(terminationTimer).isNotNull();
	assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323);
}
 
Example #6
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 #7
Source File: MonoMetricsFuseableTest.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();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, clock, 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(200);
}
 
Example #8
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void queuePollError() {
	//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());

	FluxPeekFuseableTest.AssertQueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.setCompleteWithError(true);
	testQueue.offer(1);

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

	clock.add(Duration.ofMillis(200));
	Integer val1 = fuseableSubscriber.poll();
	assertThat(val1).isEqualTo(1);

	clock.add(Duration.ofMillis(123));
	assertThatIllegalStateException().isThrownBy(fuseableSubscriber::poll)
	                                 .withMessage("AssertQueueSubscriber poll error");

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

	assertThat(terminationTimer).isNotNull();
	assertThat(terminationTimer.max(TimeUnit.MILLISECONDS)).as("terminate max delay").isEqualTo(323);
}
 
Example #9
Source File: DefaultLongTaskTimerTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("supports sending histograms of active task duration")
void histogram() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

    LongTaskTimer t = LongTaskTimer.builder("my.timer")
            .serviceLevelObjectives(Duration.ofSeconds(10), Duration.ofSeconds(40), Duration.ofMinutes(1))
            .register(registry);

    List<Integer> samples = Arrays.asList(48, 42, 40, 35, 22, 16, 13, 8, 6, 4, 2);
    int prior = samples.get(0);
    for (Integer value : samples) {
        clock(registry).add(prior - value, TimeUnit.SECONDS);
        t.start();
        prior = value;
    }
    clock(registry).add(samples.get(samples.size() - 1), TimeUnit.SECONDS);

    CountAtBucket[] countAtBuckets = t.takeSnapshot().histogramCounts();

    assertThat(countAtBuckets[0].bucket(TimeUnit.SECONDS)).isEqualTo(10);
    assertThat(countAtBuckets[0].count()).isEqualTo(4);

    assertThat(countAtBuckets[1].bucket(TimeUnit.SECONDS)).isEqualTo(40);
    assertThat(countAtBuckets[1].count()).isEqualTo(9);

    assertThat(countAtBuckets[2].bucket(TimeUnit.MINUTES)).isEqualTo(1);
    assertThat(countAtBuckets[2].count()).isEqualTo(11);
}
 
Example #10
Source File: CompositeCounterTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
@Issue("#119")
void increment() {
    SimpleMeterRegistry simple = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    CompositeMeterRegistry registry = new CompositeMeterRegistry();
    registry.add(simple);

    registry.counter("counter").increment(2.0);

    assertThat(simple.get("counter").counter().count()).isEqualTo(2.0);
}
 
Example #11
Source File: CompositeMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void histogramConfigDefaultIsNotAffectedByComposite() {
    composite.add(simple);

    // the expiry on this timer is determined by the simple registry's default histogram config
    Timer t = Timer.builder("my.timer")
            .distributionStatisticBufferLength(1)
            .register(composite);

    t.record(1, TimeUnit.SECONDS);
    assertThat(t.max(TimeUnit.SECONDS)).isEqualTo(1.0);

    clock.add(SimpleConfig.DEFAULT.step());
    assertThat(t.max(TimeUnit.SECONDS)).isEqualTo(0.0);
}
 
Example #12
Source File: MetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void metricCanBeCreatedBeforeStaticRegistryIsConfigured() {
    // doesn't blow up
    Counter counter = Metrics.counter("counter");
    counter.increment();

    SimpleMeterRegistry simple = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    Metrics.addRegistry(simple);
    counter.increment();

    assertThat(Metrics.globalRegistry.get("counter").counter().count()).isEqualTo(1.0);
}
 
Example #13
Source File: UptimeMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void uptimeMetricsRuntime() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    new UptimeMetrics().bindTo(registry);

    registry.get("process.uptime").timeGauge();
    registry.get("process.start.time").timeGauge();
}
 
Example #14
Source File: JettySslHandshakeMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
    MockitoAnnotations.initMocks(this);
    when(engine.getSession()).thenReturn(session);

    registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

    Iterable<Tag> tags = Tags.of("id", "0");
    sslHandshakeMetrics = new JettySslHandshakeMetrics(registry, tags);
}
 
Example #15
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 #16
Source File: JettyServerThreadPoolMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() throws Exception {
    registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

    Iterable<Tag> tags = Collections.singletonList(Tag.of("id", "0"));
    QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(registry, tags);
    threadPool.setMinThreads(32);
    threadPool.setMaxThreads(100);
    server = new Server(threadPool);
    ServerConnector connector = new ServerConnector(server);
    server.setConnectors(new Connector[] { connector });
    server.start();
}
 
Example #17
Source File: DistributionSummaryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void histogramsInCumulativeMode() {
    MockClock clock = new MockClock();
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
    DistributionSummary summary = DistributionSummary.builder("my.summary")
            .serviceLevelObjectives(1.0)
            .register(registry);

    summary.record(1);

    // Histogram bucket counts DO roll over at the step interval, so decay.
    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1.0, 1));
    clock.add(SimpleConfig.DEFAULT.step());
    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1.0, 0));
}
 
Example #18
Source File: MicrometerCapabilityTest.java    From feign with Apache License 2.0 5 votes vote down vote up
@Test
public void addMetricsCapability() {
  SimpleMeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

  final SimpleSource source = Feign.builder()
      .client(new MockClient()
          .ok(HttpMethod.GET, "/get", "1234567890abcde"))
      .addCapability(new MicrometerCapability(registry))
      .target(new MockTarget<>(MicrometerCapabilityTest.SimpleSource.class));

  source.get("0x3456789");

  List<Meter> metrics = new ArrayList<>();
  registry.forEachMeter(metrics::add);
  metrics.removeIf(meter -> !meter.getId().getName().startsWith("feign."));

  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include client name:" + meter.getId(),
      meter.getId().getTag("client"),
      equalTo("feign.micrometer.MicrometerCapabilityTest$SimpleSource")));
  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include method name:" + meter.getId(),
      meter.getId().getTag("method"),
      equalTo("get")));
  metrics.forEach(meter -> assertThat(
      "Expect all metric names to include host name:" + meter.getId(),
      meter.getId().getTag("host"),
      // hostname is blank due to feign-mock shortfalls
      equalTo("")));
}
 
Example #19
Source File: CompositeMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public MeterRegistry registry() {
    return new CompositeMeterRegistry(new MockClock()) {{
        add(new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock));
    }};
}
 
Example #20
Source File: AbstractMicrometerTest.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SimpleMeterRegistry simpleMeterRegistry(SimpleConfig config, Clock clock) {
	return new SimpleMeterRegistry(config, clock);
}
 
Example #21
Source File: AbstractMicrometerTest.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SimpleConfig simpleConfig() {
	return key -> null;
}
 
Example #22
Source File: MicrometerRegistryTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void before() {
  clock = new MockClock();
  meterRegistry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
  registry = new MicrometerRegistry(meterRegistry);
}
 
Example #23
Source File: MolgenisTimedAspectTest.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@BeforeEach
void beforeMethod() {
  meterRegistry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
  timedAspect = new MolgenisTimedAspect(meterRegistry);
}
 
Example #24
Source File: MicrometerCapability.java    From feign with Apache License 2.0 4 votes vote down vote up
public MicrometerCapability() {
  this(new SimpleMeterRegistry(SimpleConfig.DEFAULT, Clock.SYSTEM));
  Metrics.addRegistry(meterRegistry);
}
 
Example #25
Source File: TimedCronExecutorServiceTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeMethod
public void setup() {
  registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
}
 
Example #26
Source File: CountedRejectedExecutionHandlerTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeMethod
public void setup() {
  registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
}
 
Example #27
Source File: CountedThreadFactoryTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeMethod
public void setup() {
  registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
}
 
Example #28
Source File: MeteredExecutorServiceWrapperTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeMethod
public void setup() {
  registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
  executorServiceWrapper = new MeteredExecutorServiceWrapper(registry);
}
 
Example #29
Source File: CompositeMeterRegistryCompatibilityTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public Duration step() {
    return SimpleConfig.DEFAULT.step();
}
 
Example #30
Source File: SimplePropertiesConfigAdapter.java    From foremast with Apache License 2.0 4 votes vote down vote up
@Override
public Duration step() {
    return get(SimpleProperties::getStep, SimpleConfig.super::step);
}