Skip to content

Commit

Permalink
Merge pull request #787 from Channyboy/786-main
Browse files Browse the repository at this point in the history
Fix MPmetricbaseMetricsTest so that it is checking gc.time as a gauge…
  • Loading branch information
Channyboy authored Jan 8, 2024
2 parents 90f5a15 + 56b7b46 commit cf1f4e9
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 cf1f4e9

Please sign in to comment.