Java Code Examples for org.eclipse.microprofile.metrics.Metadata

The following examples show how to use org.eclipse.microprofile.metrics.Metadata. These examples are extracted from open source projects. 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 Project: smallrye-metrics   Source File: MetricTypeMismatchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void wrongTypeInMetadata() {
    Metadata metadata1 = Metadata.builder()
            .withName("metric1")
            .withType(MetricType.COUNTER)
            .build();
    try {
        registry.meter(metadata1);
        fail("Must not be able to register a metric if the type in its metadata is different than the what we specified by using a particular registration method.");
    } catch (Exception e) {
        assertThat(e, instanceOf(IllegalArgumentException.class));
        assertThat(e.getMessage(),
                containsString("Attempting to register a meter, but the passed metadata contains type=counter"));
        assertEquals(0, registry.getMetrics().size());
    }
}
 
Example 2
Source Project: microprofile-metrics   Source File: MetricAppBean.java    License: Apache License 2.0 6 votes vote down vote up
public void histogramMe() {

        Metadata metadata = Metadata.builder().withName("metricTest.test1.histogram")
                .withType(MetricType.HISTOGRAM).withUnit(MetricUnits.BYTES).build();
        Histogram histogram = metrics.histogram(metadata);

        // Go both ways to minimize error due to decay
        for (int i = 0; i < 500; i++) {
            histogram.update(i);
            histogram.update(999 - i);
        }

        Metadata metadata2 = Metadata.builder().withName("metricTest.test1.histogram2")
                .withType(MetricType.HISTOGRAM).withUnit(MetricUnits.NONE).build();
        Histogram histogram2 = metrics.histogram(metadata2);
        histogram2.update(1);
    }
 
Example 3
Source Project: microprofile-metrics   Source File: MetricRegistryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(4)
public void useExistingMetaDataTest() {
    String displayName = "displayCounterFoo";
    String metricName = "counterFoo";

    //first to register a "complex" metadata
    metrics.counter(Metadata.builder().withName(metricName).withDisplayName(displayName).withType(MetricType.COUNTER).build());

    Tag purpleTag = new Tag("colour","purple");
    //creates with a simple/template metadata or uses an existing one.
    metrics.counter(metricName, purpleTag);

    //check both counters have been registered
    assertExists(Counter.class, new MetricID(metricName));
    assertExists(Counter.class, new MetricID(metricName, purpleTag));

    //check that the "original" metadata wasn't replaced by the empty default metadata
    Assert.assertEquals(metrics.getMetadata(metricName).getDisplayName(), displayName);
}
 
Example 4
Source Project: quarkus   Source File: SmallRyeMetricsRecorder.java    License: Apache License 2.0 6 votes vote down vote up
private void runtimeMetrics(MetricRegistry registry) {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

    Metadata meta = Metadata.builder()
            .withName(JVM_UPTIME)
            .withType(MetricType.GAUGE)
            .withUnit(MetricUnits.MILLISECONDS)
            .withDisplayName("JVM Uptime")
            .withDescription("Displays the time from the start of the Java virtual machine in milliseconds.")
            .build();
    registry.register(meta, new Gauge() {
        @Override
        public Number getValue() {
            return runtimeMXBean.getUptime();
        }
    });
}
 
Example 5
Source Project: smallrye-metrics   Source File: OpenMetricsExporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNameOverride() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Metadata metadata = new ExtendedMetadata("voltage1",
            "Voltage",
            "Measures your electric potential",
            MetricType.GAUGE,
            "volts",
            null,
            false,
            Optional.of(true),
            false,
            "baz");
    Tag tag = new Tag("a", "b");
    registry.register(metadata, (Gauge<Long>) () -> 3L, tag);

    String result = exporter.exportOneScope(MetricRegistry.Type.APPLICATION).toString();
    System.out.println(result);
    assertHasHelpLineExactlyOnce(result, "application_baz", "Measures your electric potential");
    assertHasTypeLineExactlyOnce(result, "application_baz", "gauge");
    assertHasValueLineExactlyOnce(result, "application_baz", "3.0", tag);
}
 
Example 6
Source Project: smallrye-metrics   Source File: OpenMetricsExporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSkippingOfScope() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Metadata metadata = new ExtendedMetadata("foo",
            "foo",
            "FooDescription",
            MetricType.COUNTER,
            "volts",
            null,
            false,
            Optional.of(true),
            true,
            null);
    Tag tag = new Tag("a", "b");
    registry.counter(metadata, tag);

    String result = exporter.exportOneScope(MetricRegistry.Type.APPLICATION).toString();
    System.out.println(result);
    assertHasHelpLineExactlyOnce(result, "foo_total", "FooDescription");
    assertHasTypeLineExactlyOnce(result, "foo_total", "counter");
    assertHasValueLineExactlyOnce(result, "foo_total_volts", "0.0", tag);
}
 
Example 7
/**
 * Given a Meter,
 * check that the statistics from OpenMetrics will be presented as per_second.
 */
@Test
public void meter_openMetrics() throws InterruptedException {
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    Metadata metadata = Metadata.builder()
            .withName("meter1")
            .withType(MetricType.METERED)
            .build();
    Meter metric = registry.meter(metadata);
    metric.mark(10);
    TimeUnit.SECONDS.sleep(1);

    OpenMetricsExporter exporter = new OpenMetricsExporter();
    String exported = exporter.exportOneMetric(MetricRegistry.Type.APPLICATION, new MetricID("meter1")).toString();

    Assert.assertThat(exported, containsString("application_meter1_total 10.0"));
    double ratePerSecond = Double.parseDouble(Arrays.stream(exported.split("\\n"))
            .filter(line -> line.contains("application_meter1_rate_per_second"))
            .filter(line -> !line.contains("TYPE") && !line.contains("HELP"))
            .findFirst()
            .get()
            .split(" ")[1]);
    Assert.assertTrue("Rate per second should be between 1 and 10 but is " + ratePerSecond,
            ratePerSecond > 1 && ratePerSecond < 10);
}
 
Example 8
/**
 * Given a Histogram with unit=MINUTES,
 * check that the statistics from OpenMetricsExporter will be presented in SECONDS.
 */
@Test
public void histogram_openMetrics() {
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    Metadata metadata = Metadata.builder()
            .withName("histogram1")
            .withType(MetricType.HISTOGRAM)
            .withUnit(MetricUnits.MINUTES)
            .build();
    Histogram metric = registry.histogram(metadata);
    metric.update(30);
    metric.update(40);
    metric.update(50);

    OpenMetricsExporter exporter = new OpenMetricsExporter();
    String exported = exporter.exportOneMetric(MetricRegistry.Type.APPLICATION, new MetricID("histogram1")).toString();

    Assert.assertThat(exported, containsString("application_histogram1_min_seconds 1800.0"));
    Assert.assertThat(exported, containsString("application_histogram1_max_seconds 3000.0"));
    Assert.assertThat(exported, containsString("application_histogram1_mean_seconds 2400.0"));
    Assert.assertThat(exported, containsString("application_histogram1_seconds{quantile=\"0.5\"} 2400.0"));
}
 
Example 9
Source Project: smallrye-metrics   Source File: OpenMetricsExporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void exportGauges() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Metadata metadata = Metadata
            .builder()
            .withType(MetricType.GAUGE)
            .withName("mygauge")
            .withDescription("awesome")
            .build();
    Tag blueTag = new Tag("color", "blue");
    registry.register(metadata, (Gauge<Long>) () -> 42L, blueTag);
    Tag greenTag = new Tag("color", "green");
    registry.register(metadata, (Gauge<Long>) () -> 26L, greenTag);

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mygauge").toString();
    System.out.println(result);

    assertHasTypeLineExactlyOnce(result, "application_mygauge", "gauge");
    assertHasHelpLineExactlyOnce(result, "application_mygauge", "awesome");

    assertHasValueLineExactlyOnce(result, "application_mygauge", "42.0", blueTag);
    assertHasValueLineExactlyOnce(result, "application_mygauge", "26.0", greenTag);
}
 
Example 10
Source Project: smallrye-metrics   Source File: JsonExporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGauges() {
    JsonExporter exporter = new JsonExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Gauge<Long> gaugeWithoutTags = () -> 1L;
    Gauge<Long> gaugeRed = () -> 2L;
    Gauge<Long> gaugeBlue = () -> 3L;

    final Metadata metadata = new MetadataBuilder()
            .withType(MetricType.GAUGE)
            .withName("mygauge")
            .build();

    registry.register(metadata, gaugeWithoutTags);
    registry.register(metadata, gaugeRed, new Tag("color", "red"));
    registry.register(metadata, gaugeBlue, new Tag("color", "blue"), new Tag("foo", "bar"));

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mygauge").toString();
    System.out.println(result);
    JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject();

    assertEquals(1, json.getInt("mygauge"));
    assertEquals(2, json.getInt("mygauge;color=red"));
    assertEquals(3, json.getInt("mygauge;color=blue;foo=bar"));
}
 
Example 11
Source Project: smallrye-metrics   Source File: JsonMetadataExporter.java    License: Apache License 2.0 6 votes vote down vote up
private JsonObject metricJSON(Metadata metadata, List<List<String>> tagSets) {
    JsonObjectBuilder obj = JsonProviderHolder.get().createObjectBuilder();

    obj.add("unit", metadata.getUnit());

    if (metadata.getType() != null) {
        obj.add("type", metadata.getType());
    }

    metadata.description().ifPresent(s -> obj.add("description", s));

    if (metadata.getDisplayName() != null) {
        obj.add("displayName", metadata.getDisplayName());
    }

    // append known sets of tags
    JsonArrayBuilder tagsArray = JsonProviderHolder.get().createArrayBuilder();
    tagSets.forEach(tagSet -> {
        JsonArrayBuilder innerArrayBuilder = JsonProviderHolder.get().createArrayBuilder();
        tagSet.forEach(innerArrayBuilder::add);
        tagsArray.add(innerArrayBuilder);
    });
    obj.add("tags", tagsArray);

    return obj.build();
}
 
Example 12
Source Project: smallrye-metrics   Source File: MetricTypeMismatchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void metricsWithDifferentType() {
    Metadata metadata1 = Metadata.builder().withName("metric1")
            .withDescription("description1").build();
    Metadata metadata2 = Metadata.builder().withName("metric1")
            .withDescription("description2").build();

    registry.histogram(metadata1);
    try {
        registry.meter(metadata2);
        fail("Must not be able to register if a metric with different type is registered under the same name");
    } catch (Exception e) {
        assertThat(e, instanceOf(IllegalStateException.class));
        assertEquals(1, registry.getMetrics().size());
    }
}
 
Example 13
Source Project: smallrye-metrics   Source File: JsonExporter.java    License: Apache License 2.0 6 votes vote down vote up
private Map<String, JsonValue> exportMetricsForMap(Map<MetricID, Metric> metricMap, Map<String, Metadata> metadataMap) {
    Map<String, JsonValue> result = new HashMap<>();

    // split into groups by metric name
    Map<String, Map<MetricID, Metric>> metricsGroupedByName = metricMap.entrySet().stream()
            .collect(Collectors.groupingBy(
                    entry -> entry.getKey().getName(),
                    Collectors.mapping(e -> e, Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
    // and then for each group, perform the export
    metricsGroupedByName.entrySet().stream()
            .map(entry -> exportMetricsByName(entry.getValue(), metadataMap.get(entry.getKey())))
            .forEach(map -> {
                map.forEach(result::put);
            });
    return result;
}
 
Example 14
Source Project: quarkus   Source File: SmallRyeMetricsRecorder.java    License: Apache License 2.0 6 votes vote down vote up
public void registerMetricFromProducer(String beanId, MetricType metricType,
        String metricName, String[] tags, String description,
        String displayName, String unit) {
    ArcContainer container = Arc.container();
    InjectableBean<Object> injectableBean = container.bean(beanId);
    BeanManager beanManager = container.beanManager();
    Metric reference = (Metric) beanManager.getReference(injectableBean, Metric.class,
            beanManager.createCreationalContext(injectableBean));
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    Metadata metadata = Metadata.builder()
            .withType(metricType)
            .withName(metricName)
            .withDescription(description)
            .withDisplayName(displayName)
            .withUnit(unit)
            .notReusable()
            .build();
    registry.register(metadata, reference, TagsUtils.parseTagsAsArray(tags));
}
 
Example 15
Source Project: smallrye-metrics   Source File: OpenMetricsExporter.java    License: Apache License 2.0 6 votes vote down vote up
private void addTags(StringBuilder sb, Map<String, String> tags, MetricRegistry.Type scope, Metadata metadata) {
    if (tags == null || tags.isEmpty()) {
        // always add the microprofile_scope even if there are no other tags
        if (writeScopeInTag(metadata)) {
            sb.append("{microprofile_scope=\"" + scope.getName().toLowerCase() + "\"}");
        }
        return;
    } else {
        Iterator<Map.Entry<String, String>> iter = tags.entrySet().iterator();
        sb.append("{");
        while (iter.hasNext()) {
            Map.Entry<String, String> tag = iter.next();
            sb.append(tag.getKey()).append("=\"").append(quoteValue(tag.getValue())).append("\"");
            if (iter.hasNext()) {
                sb.append(",");
            }
        }
        // append the microprofile_scope after other tags
        if (writeScopeInTag(metadata)) {
            sb.append(",microprofile_scope=\"" + scope.getName().toLowerCase() + "\"");
        }

        sb.append("}");
    }
}
 
Example 16
Source Project: smallrye-metrics   Source File: OpenMetricsExporter.java    License: Apache License 2.0 6 votes vote down vote up
private void writeTypeLine(StringBuilder sb, MetricRegistry.Type scope, String key, Metadata md, String suffix,
        String typeOverride) {
    if (!alreadyExportedNames.get().contains(md.getName())) {
        sb.append("# TYPE ");
        getNameWithScopeAndSuffix(sb, scope, key, suffix, md);
        if (typeOverride != null) {
            sb.append(typeOverride);
        } else if (md.getTypeRaw().equals(MetricType.TIMER)) {
            sb.append(SUMMARY);
        } else if (md.getTypeRaw().equals(MetricType.METERED)) {
            sb.append(COUNTER);
        } else {
            sb.append(md.getType());
        }
        sb.append(LF);
    }
}
 
Example 17
Source Project: apicurio-registry   Source File: RestMetricsInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
synchronized void init() {
    // Total counter
    final Metadata m1 = Metadata.builder()
            .withName(REST_REQUEST_COUNT)
            .withDescription(REST_REQUEST_COUNT_DESC + " Across all endpoints.")
            .withType(COUNTER)
            .build();
    final Tag[] tags1 = {new Tag("group", REST_GROUP_TAG), new Tag("metric", REST_REQUEST_COUNT)};
    counter = metricRegistry.counter(m1, tags1);
    // Concurrent gauge
    final Metadata m2 = Metadata.builder()
            .withName(REST_CONCURRENT_REQUEST_COUNT)
            .withDescription(REST_CONCURRENT_REQUEST_COUNT_DESC + " Across all endpoints.")
            .withType(CONCURRENT_GAUGE)
            .build();
    final Tag[] tags2 = {new Tag("group", REST_GROUP_TAG), new Tag("metric", REST_CONCURRENT_REQUEST_COUNT)};
    gauge = metricRegistry.concurrentGauge(m2, tags2);
    // Timer
    final Metadata m3 = Metadata.builder()
            .withName(REST_REQUEST_RESPONSE_TIME)
            .withDescription(REST_REQUEST_RESPONSE_TIME_DESC + " Across all endpoints.")
            .withType(TIMER)
            .withUnit(MILLISECONDS)
            .build();
    final Tag[] tags3 = {new Tag("group", REST_GROUP_TAG), new Tag("metric", REST_REQUEST_RESPONSE_TIME)};
    timer = metricRegistry.timer(m3, tags3);

    init = true;
}
 
Example 18
private Map<String, Metadata> registerCounters() {

        Map<String, Metadata> initCounters = new HashMap<>();
        registerUserEventCounters(initCounters);
        registerAdminEventCounters(initCounters);
        return Collections.unmodifiableMap(initCounters);
    }
 
Example 19
/**
 * Counters for all user events
 */
private void registerUserEventCounters(Map<String, Metadata> counters) {

    for (EventType type : EventType.values()) {
        if (type.equals(EventType.LOGIN) || type.equals(EventType.LOGIN_ERROR) || type.equals(EventType.REGISTER)) {
            continue;
        }
        String counterName = buildCounterName(type);
        counters.put(counterName, createCounter(counterName, false));
    }
}
 
Example 20
/**
 * Counters for all admin events
 */
private void registerAdminEventCounters(Map<String, Metadata> counters) {

    for (OperationType type : OperationType.values()) {
        String counterName = buildCounterName(type);
        counters.put(counterName, createCounter(counterName, true));
    }
}
 
Example 21
/**
 * Creates a counter based on a event name
 */
private static Metadata createCounter(final String name, boolean isAdmin) {

    String description = isAdmin ? "Generic KeyCloak Admin event" : "Generic KeyCloak User event";

    return Metadata.builder()
            .withName(name)
            .withDescription(description)
            .withType(MetricType.COUNTER).build();
}
 
Example 22
Source Project: quarkus   Source File: JaegerProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private MetricBuildItem metric(String name, MetricType type, Object implementor, Tag... tags) {
    Metadata metadata = Metadata.builder()
            .withName(name)
            .withDisplayName(name)
            .withType(type)
            .withUnit("none")
            .withDescription(name)
            .reusable()
            .build();
    if (implementor == null) {
        return new MetricBuildItem(metadata, true, "jaeger", tags);
    } else {
        return new MetricBuildItem(metadata, implementor, true, "jaeger", tags);
    }
}
 
Example 23
Source Project: smallrye-metrics   Source File: OpenMetricsExporter.java    License: Apache License 2.0 5 votes vote down vote up
private boolean writeScopeInPrefix(Metadata metadata) {
    if (metadata instanceof ExtendedMetadata) {
        ExtendedMetadata extendedMetadata = (ExtendedMetadata) metadata;
        if (extendedMetadata.isSkipsScopeInOpenMetricsExportCompletely())
            return false;
        return extendedMetadata.prependsScopeToOpenMetricsName().orElse(usePrefixForScope);
    } else {
        return usePrefixForScope;
    }
}
 
Example 24
Source Project: quarkus   Source File: MetricBuildItem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a metric build item from the specified metadata and tags.
 * Such metric will be picked up by the Metrics extension and registered in the VENDOR registry.
 * This constructor is applicable to all metric types except gauges.
 *
 * @param metadata The metadata that should be applied to the registered metric
 * @param enabled Whether this metric is enabled
 * @param tags The tags that will be applied to this metric
 * @param configRootName the name of the root configuration of the extension as defined by the <code>@ConfigRoot</code>
 *        annotation.
 */
public MetricBuildItem(Metadata metadata, boolean enabled, String configRootName, Tag... tags) {
    if (metadata.getTypeRaw() == MetricType.GAUGE) {
        throw new IllegalArgumentException("Gauges require a non-null implementation object");
    }
    this.metadata = metadata;
    this.tags = tags;
    this.implementor = null;
    this.enabled = enabled;
    this.configRootName = configRootName;
    this.registryType = MetricRegistry.Type.VENDOR;
}
 
Example 25
Source Project: smallrye-metrics   Source File: OpenMetricsExporterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void exportCounters() {
    OpenMetricsExporter exporter = new OpenMetricsExporter();
    MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);

    Metadata metadata = Metadata
            .builder()
            .withType(MetricType.COUNTER)
            .withName("mycounter")
            .withDescription("awesome")
            .build();
    Tag blueTag = new Tag("color", "blue");
    Counter blueCounter = registry.counter(metadata, blueTag);
    Tag greenTag = new Tag("color", "green");
    Counter greenCounter = registry.counter(metadata, greenTag);

    blueCounter.inc(10);
    greenCounter.inc(20);

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mycounter").toString();
    System.out.println(result);

    assertHasTypeLineExactlyOnce(result, "application_mycounter_total", "counter");
    assertHasHelpLineExactlyOnce(result, "application_mycounter_total", "awesome");

    assertHasValueLineExactlyOnce(result, "application_mycounter_total", "10.0", blueTag);
    assertHasValueLineExactlyOnce(result, "application_mycounter_total", "20.0", greenTag);

}
 
Example 26
Source Project: trader   Source File: Summary.java    License: Apache License 2.0 5 votes vote down vote up
void setPortfolioMetric(String owner, double total) {
	totals.put(owner, total);
	if (gauges.get(owner)==null) try { //gauge not yet registered for this portfolio
		org.eclipse.microprofile.metrics.Gauge<Double> gauge = () -> { return totals.get(owner); };

		Metadata metadata = Metadata.builder().withName("portfolio_value").withType(MetricType.GAUGE).withUnit(DOLLARS).build();

		metricRegistry.register(metadata, gauge, new Tag("owner", owner)); //registry injected via CDI

		gauges.put(owner, gauge);
	} catch (Throwable t) {
		logger.warning(t.getMessage());
	}
}
 
Example 27
Source Project: smallrye-metrics   Source File: MetricsMetadata.java    License: Apache License 2.0 5 votes vote down vote up
public static Metadata getMetadata(Object origin, String name, String unit, String description, String displayName,
        MetricType type) {
    Metadata metadata = Metadata.builder().withName(name)
            .withType(type)
            .withUnit(unit)
            .withDescription(description)
            .withDisplayName(displayName)
            .build();
    return new OriginAndMetadata(origin, metadata);
}
 
Example 28
Source Project: smallrye-metrics   Source File: MetadataMismatchTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void metricsWithSameTypeAndMetadata() {
    Metadata metadata1 = Metadata.builder().withName("myhistogram").withDescription("description1").build();
    Metadata metadata2 = Metadata.builder().withName("myhistogram").withDescription("description1").build();

    Histogram histogram1 = registry.histogram(metadata1);
    Histogram histogram2 = registry.histogram(metadata2);

    assertEquals(histogram1, histogram2);
    assertEquals(1, registry.getMetrics().size());
}
 
Example 29
Source Project: microprofile-metrics   Source File: MetricRegistryTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * if there is a mismatch because the type specified in the `Metadata` is different than the one
 * implied by the method name, an exception must be thrown
 */
@Test(expected = Exception.class)
@InSequence(7)
public void conflictingMetadataTest() {
    Metadata metadata = Metadata.builder().withName("metric1").withType(MetricType.COUNTER).build();
    metrics.meter(metadata);
}
 
Example 30
Source Project: smallrye-metrics   Source File: MetadataMismatchTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void metricsWithDifferentMetadata() {
    Metadata metadata1 = Metadata.builder().withName("myhistogram").withDescription("description1").build();
    Metadata metadata2 = Metadata.builder().withName("myhistogram").withDescription("description2").build();

    registry.histogram(metadata1);
    try {
        registry.histogram(metadata2);
        fail("Shouldn't be able to re-register a metric with different metadata");
    } catch (Exception e) {
        assertThat(e, instanceOf(IllegalStateException.class));
        assertEquals(1, registry.getMetrics().size());
    }
}