Skip to content

Commit 613b63a

Browse files
committed
Enhancement Request 37553976 - [37149363->14.1.1.0.21] Metrics generated by Coherence should conform to OpenObservability spec (14.1.1.0 cl 114142 --> 14.1.1.0 CE)
[git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v14.1.1.0/": change = 114152]
1 parent 7c9267f commit 613b63a

File tree

6 files changed

+339
-13
lines changed

6 files changed

+339
-13
lines changed

prj/coherence-metrics/src/main/java/com/tangosol/coherence/metrics/internal/MetricsResource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.coherence.metrics.internal;
88

@@ -391,7 +391,7 @@ private void writeTags(Writer writer, Map<String, String> mapTags) throws IOExce
391391
.append('"');
392392
if (iterator.hasNext())
393393
{
394-
writer.append(", ");
394+
writer.append(",");
395395
}
396396
}
397397

prj/coherence-metrics/src/test/java/com/tangosol/coherence/metrics/internal/PrometheusFormatterTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.coherence.metrics.internal;
88

@@ -41,7 +41,7 @@ public void testMetricWithTags() throws IOException
4141
new PrometheusFormatter(false, MetricsResource.Format.Legacy, Collections.singletonList(metric))
4242
.writeMetrics(writer);
4343

44-
String expected = "vendor:coherence_cluster_size{cluster=\"testCluster\", node_id=\"1\", site=\"testSite\"} 3\n";
44+
String expected = "vendor:coherence_cluster_size{cluster=\"testCluster\",node_id=\"1\",site=\"testSite\"} 3\n";
4545

4646
assertThat(writer.toString(), equalTo(expected));
4747
}
@@ -55,7 +55,7 @@ public void testMetricWithMicroprofileName() throws IOException
5555
new PrometheusFormatter(false, MetricsResource.Format.Microprofile, Collections.singletonList(metric))
5656
.writeMetrics(writer);
5757

58-
String expected = "vendor_Coherence_ClusterSize{cluster=\"testCluster\", node_id=\"1\", site=\"testSite\"} 3\n";
58+
String expected = "vendor_Coherence_ClusterSize{cluster=\"testCluster\",node_id=\"1\",site=\"testSite\"} 3\n";
5959

6060
assertThat(writer.toString(), equalTo(expected));
6161
}
@@ -69,7 +69,7 @@ public void testMetricWithDotFormattedName() throws IOException
6969
new PrometheusFormatter(false, MetricsResource.Format.DotDelimited, Collections.singletonList(metric))
7070
.writeMetrics(writer);
7171

72-
String expected = "coherence_cluster_size{cluster=\"testCluster\", node_id=\"1\", site=\"testSite\"} 3\n";
72+
String expected = "coherence_cluster_size{cluster=\"testCluster\",node_id=\"1\",site=\"testSite\"} 3\n";
7373

7474
assertThat(writer.toString(), equalTo(expected));
7575
}
@@ -85,7 +85,7 @@ public void testExtendedMetricWithTags() throws IOException
8585

8686
String expected = "# TYPE vendor:coherence_cluster_size gauge\n"
8787
+ "# HELP vendor:coherence_cluster_size Cluster size\n"
88-
+ "vendor:coherence_cluster_size{cluster=\"testCluster\", node_id=\"1\", site=\"testSite\"} 3\n";
88+
+ "vendor:coherence_cluster_size{cluster=\"testCluster\",node_id=\"1\",site=\"testSite\"} 3\n";
8989

9090
assertThat(writer.toString(), equalTo(expected));
9191
}

prj/test/functional/metrics/pom.xml

+54-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
~ Copyright (c) 2000, 2021, Oracle and/or its affiliates.
4-
~
5-
~ Licensed under the Universal Permissive License v 1.0 as shown at
6-
~ http://oss.oracle.com/licenses/upl.
3+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
4+
5+
Licensed under the Universal Permissive License v 1.0 as shown at
6+
https://oss.oracle.com/licenses/upl.
77
-->
88
<project xmlns="http://maven.apache.org/POM/4.0.0"
99
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -20,6 +20,56 @@
2020
<artifactId>metrics</artifactId>
2121
<name>Coherence Metrics Tests</name>
2222

23+
<profiles>
24+
<profile>
25+
<id>metrics-format-test</id>
26+
<activation>
27+
<activeByDefault>false</activeByDefault>
28+
</activation>
29+
<properties>
30+
<skipTests>false</skipTests>
31+
</properties>
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-failsafe-plugin</artifactId>
37+
<version>${maven.failsafe.plugin.version}</version>
38+
<executions>
39+
<execution>
40+
<goals>
41+
<goal>integration-test</goal>
42+
<goal>verify</goal>
43+
</goals>
44+
<configuration>
45+
<includes>
46+
<include>**/MetricsFormatTests.java</include>
47+
</includes>
48+
</configuration>
49+
</execution>
50+
</executions>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.codehaus.mojo</groupId>
54+
<artifactId>exec-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>Metrics Format Tests</id>
58+
<phase>verify</phase>
59+
<goals>
60+
<goal>exec</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
<configuration>
65+
<skip>${skipTests}</skip>
66+
<executable>${project.basedir}/src/test/python/run_test.sh</executable>
67+
</configuration>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
</profile>
72+
</profiles>
2373
<dependencies>
2474
<dependency>
2575
<groupId>${coherence.group.id}</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
package metrics;
8+
9+
import com.oracle.bedrock.runtime.LocalPlatform;
10+
import com.oracle.bedrock.runtime.coherence.CoherenceClusterMember;
11+
import com.oracle.bedrock.runtime.coherence.options.LocalHost;
12+
import com.oracle.bedrock.runtime.coherence.options.Logging;
13+
import com.oracle.bedrock.runtime.java.options.IPv4Preferred;
14+
import com.oracle.bedrock.runtime.java.options.SystemProperty;
15+
import com.oracle.bedrock.testsupport.deferred.Eventually;
16+
import com.oracle.bedrock.util.Capture;
17+
import com.tangosol.coherence.metrics.internal.MetricsResource;
18+
import com.tangosol.internal.net.metrics.MetricsHttpHelper;
19+
import java.net.HttpURLConnection;
20+
import java.net.URI;
21+
22+
import java.io.BufferedReader;
23+
import java.io.InputStream;
24+
import java.io.InputStreamReader;
25+
import java.io.PrintWriter;
26+
27+
import java.util.ArrayList;
28+
import java.util.Collection;
29+
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
import org.junit.runners.Parameterized;
33+
34+
import static org.hamcrest.CoreMatchers.is;
35+
import static org.hamcrest.MatcherAssert.assertThat;
36+
37+
@RunWith(Parameterized.class)
38+
public class MetricsFormatTests
39+
extends AbstractMetricsFunctionalTest
40+
{
41+
// ----- Parameterized Setup --------------------------------------------
42+
43+
/**
44+
* Create the test parameters.
45+
*
46+
* @return the test parameters
47+
*/
48+
@Parameterized.Parameters(name = "Format={0}")
49+
public static Collection<Object[]> getTestParameters()
50+
{
51+
ArrayList<Object[]> parameters = new ArrayList<>();
52+
53+
// Run Coherence with no metrics format configured - i.e. use whatever is the current default
54+
parameters.add(new Object[]{"None Specified", "foo", false});
55+
// Run Coherence with the legacy metrics format configured
56+
parameters.add(new Object[]{"Legacy", MetricsResource.PROP_USE_LEGACY_NAMES, true});
57+
// Run Coherence with the MP metrics format configured
58+
parameters.add(new Object[]{"MP", MetricsResource.PROP_USE_MP_NAMES, true});
59+
// Run Coherence with the dot delimited metrics format configured
60+
parameters.add(new Object[]{"Dot Delimited", "foo", false});
61+
62+
return parameters;
63+
}
64+
65+
// ----- constructors ---------------------------------------------------
66+
/**
67+
* Create the test instance.
68+
*
69+
* @param sFormat the descriptive name of the test
70+
* @param sProperty the system property to set to configure the metric name format
71+
* @param fValue the value to set the system property to
72+
* @param format the expected metrics format
73+
*/
74+
public MetricsFormatTests(String sFormat, String sProperty, boolean fValue)
75+
{
76+
super("client-cache-config-metrics.xml");
77+
f_sFormat = sFormat;
78+
f_sProperty = sProperty;
79+
f_fPropertyValue = fValue;
80+
}
81+
82+
// ----- test -----------------------------------------------------------
83+
/**
84+
* Just extracts metrics into the file so their format can be verified by an external tool.
85+
*
86+
* @throws Exception
87+
*/
88+
@Test
89+
public void shouldHaveCorrectFormat() throws Exception
90+
{
91+
LocalPlatform platform = LocalPlatform.get();
92+
Capture<Integer> port = new Capture<>(platform.getAvailablePorts());
93+
94+
String additionalMetricsProperty = "foo";
95+
if (!f_sFormat.equals("Legacy"))
96+
{
97+
additionalMetricsProperty = MetricsResource.PROP_USE_LEGACY_NAMES;
98+
}
99+
// start Coherence with metrics configured with the test format
100+
try (CoherenceClusterMember member = platform.launch(CoherenceClusterMember.class,
101+
SystemProperty.of(f_sProperty, f_fPropertyValue),
102+
SystemProperty.of(additionalMetricsProperty, false),
103+
SystemProperty.of(MetricsHttpHelper.PROP_METRICS_ENABLED, true),
104+
SystemProperty.of("coherence.metrics.http.port", port),
105+
SystemProperty.of("test.persistence.enabled", false),
106+
SystemProperty.of("coherence.management.extendedmbeanname", true),
107+
SystemProperty.of(Logging.PROPERTY_LEVEL, "9"),
108+
IPv4Preferred.yes(),
109+
LocalHost.only()))
110+
{
111+
Eventually.assertDeferred(() -> member.isServiceRunning(MetricsHttpHelper.getServiceName()), is(true));
112+
113+
String sURL = "http://127.0.0.1:" + port.get() + "/metrics";
114+
115+
HttpURLConnection con = (HttpURLConnection) URI.create(sURL).toURL().openConnection();
116+
con.setRequestProperty("Accept", "text/plain");
117+
con.setRequestMethod("GET");
118+
119+
int responseCode = con.getResponseCode();
120+
assertThat(responseCode, is(200));
121+
122+
try (PrintWriter writer = new PrintWriter("target/" + f_sFormat + ".metrics.txt");
123+
InputStream in = con.getInputStream())
124+
{
125+
BufferedReader isr = new BufferedReader(new InputStreamReader(in));
126+
String line;
127+
int counter = 0;
128+
while ((line = isr.readLine()) != null )
129+
{
130+
writer.print(line + "\n");
131+
// limit example size otherwise verification takes too much time to complete
132+
if (counter++ == 110)
133+
{
134+
break;
135+
}
136+
}
137+
writer.print("# EOF");
138+
}
139+
}
140+
}
141+
142+
// ----- data members ----------------------------------------------------
143+
144+
/**
145+
* The text description of the format to set.
146+
*/
147+
private final String f_sFormat;
148+
149+
/**
150+
* The system property to set to configure the name format.
151+
*/
152+
private final String f_sProperty;
153+
154+
/**
155+
* The value of the system property to set to configure the name format.
156+
*/
157+
private final boolean f_fPropertyValue;
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2000, 2025, Oracle and/or its affiliates.
4+
#
5+
# Licensed under the Universal Permissive License v 1.0 as shown at
6+
# https://oss.oracle.com/licenses/upl.
7+
#
8+
9+
echo "Metrics Format Test"
10+
echo "$(pwd)"
11+
12+
cd src/test/python || exit 1
13+
rm -rf .pyenv || true
14+
git clone --branch v2.3.22 https://github.com/pyenv/pyenv.git .pyenv
15+
export PYENV_ROOT=$(pwd)/.pyenv
16+
export PATH=${PYENV_ROOT}/bin:${PATH}
17+
eval "$(pyenv init --path)"
18+
echo $PATH
19+
20+
${PYENV_ROOT}/bin/pyenv install 3.11
21+
${PYENV_ROOT}/bin/pyenv versions
22+
${PYENV_ROOT}/bin/pyenv global 3.11
23+
which python
24+
25+
pip install abnf
26+
27+
echo "Current path: $(pwd)"
28+
python ./verify_metrics_format.py

0 commit comments

Comments
 (0)