Skip to content

Commit

Permalink
Fix MPmetricbaseMetricsTest so that it is checking gc.time as a gauge…
Browse files Browse the repository at this point in the history
… which does not have a _total appended to it
  • Loading branch information
Channyboy committed Oct 25, 2023
1 parent c77da94 commit 56b7b46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions spec/src/main/asciidoc/changelog.adoc
Expand Up @@ -32,6 +32,7 @@ A full list of changes may be found on the link:https://github.com/eclipse/micro
=== Other changes

* Include new recommendation for multi-application deployments to use a `mp.metrics.defaultAppName` property (https://github.com/eclipse/microprofile-metrics/issues/766[766])
* (5.1.1) Fix `MPMetricBaseMetricsTest` TCK test where gc.time was being checked as a counter. The `gc.time` metric is a gauge. (https://github.com/eclipse/microprofile-metrics/issues/786[786])

[[release_notes_5_0]]
== Changes in 5.0
Expand Down Expand Up @@ -164,6 +165,7 @@ A full list of changes may be found on the link:https://github.com/eclipse/micro
* (5.0.1) Removed private gauges from TCK (https://github.com/eclipse/microprofile-metrics/pull/770[770])
* (5.0.1) The `@Timed` annotation defaults to SECONDS when it should be NANOSECONDS (https://github.com/eclipse/microprofile-metrics/issues/760[760])
* (5.0.1) Errors in MicroProfile 6.0 javadoc generation (https://github.com/eclipse/microprofile-metrics/issues/764[764])
* (5.0.2) Fix `MPMetricBaseMetricsTest` TCK test where gc.time was being checked as a counter. The `gc.time` metric is a gauge. (https://github.com/eclipse/microprofile-metrics/issues/786[786])

[[release_notes_4_0]]
== Changes in 4.0
Expand Down
@@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
*
* See the NOTICES file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -303,28 +303,28 @@ public void testGcTimeMetrics() {
String data = given().header(wantPromMetricsFormat).get("/metrics?scope=base").asString();

Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.BASE_SCOPE);
MiniMeta gcCountMetricMeta = baseNames.get("gc.time");
Set<String> expectedTags = gcCountMetricMeta.tags.keySet();
MiniMeta gcTimeMetricMeta = baseNames.get("gc.time");
Set<String> expectedTags = gcTimeMetricMeta.tags.keySet();

String[] lines = data.split("\n");

boolean found = false;
for (String line : lines) {
// explicitly check for the metric line wth value (i.e. the use of `{`)
if (line.contains("gc_time_seconds_total{")) {
final Pattern gcTimeTotalPattern = Pattern.compile("(gc_time_seconds_total\\{.*?\\}) (\\d+\\.\\d+)");
assertThat("Line format should be gc_time_seconds_total\\{.*?\\} \\d+\\.\\d+",
if (line.contains("gc_time_seconds{")) {
final Pattern gcTimeTotalPattern = Pattern.compile("(gc_time_seconds\\{.*?\\}) (\\d+\\.\\d+)");
assertThat("Line format should be gc_time_seconds\\{.*?\\} \\d+\\.\\d+",
gcTimeTotalPattern.matcher(line).matches());

final String metricID = gcTimeTotalPattern.matcher(line).replaceAll("$1");
final String tags = metricID.replaceAll("^gc_time_seconds_total\\{", "").replaceAll("\\}$", "");
final String tags = metricID.replaceAll("^gc_time_seconds\\{", "").replaceAll("\\}$", "");

for (String expectedTag : expectedTags) {
assertThat("The metric should contain a " + expectedTag + " tag", tags,
containsString(expectedTag + "="));
}
final String value = gcTimeTotalPattern.matcher(line).replaceAll("$2");
Assert.assertTrue("gc.time.seconds.total value should be numeric and not negative",
Assert.assertTrue("gc.time value should be numeric and not negative",
Double.valueOf(value).doubleValue() >= 0);

found = true;
Expand Down

0 comments on commit 56b7b46

Please sign in to comment.