-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFLY-19351] Add Micrometer test to verify that applications with sha…
…red metrics names are not merged when exported Add test with multiple war deployments Add test with ear with multiple war subdeployments Rework how Prometheus metrics are retrieved and handled Add test to verify that metrics with identical names are exported separately
- Loading branch information
Showing
10 changed files
with
388 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../src/test/java/org/wildfly/test/integration/observability/container/PrometheusMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.wildfly.test.integration.observability.container; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class PrometheusMetric { | ||
private final String key; | ||
private final Map<String, String> tags; | ||
private final String value; | ||
private final String type; | ||
private final String help; | ||
|
||
public PrometheusMetric(String key, | ||
Map<String, String> tags, | ||
String value, | ||
String type, | ||
String help) { | ||
this.key = key; | ||
this.tags = Collections.unmodifiableMap(tags); | ||
this.value = value; | ||
this.type = type; | ||
this.help = help; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public Map<String, String> getTags() { | ||
return tags; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getHelp() { | ||
return help; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PrometheusMetric{" + | ||
"key='" + key + '\'' + | ||
", tags=" + tags + | ||
", value='" + value + '\'' + | ||
", type='" + type + '\'' + | ||
", help='" + help + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../org/wildfly/test/integration/observability/micrometer/multiple/BaseMultipleTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.wildfly.test.integration.observability.micrometer.multiple; | ||
|
||
import jakarta.ws.rs.client.Client; | ||
import jakarta.ws.rs.client.ClientBuilder; | ||
import jakarta.ws.rs.client.WebTarget; | ||
import org.jboss.as.test.shared.util.AssumeTestGroupUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.wildfly.test.integration.observability.container.PrometheusMetric; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class BaseMultipleTestCase { | ||
protected static final String SERVICE_ONE = "service-one"; | ||
protected static final String SERVICE_TWO = "service-two"; | ||
protected static final int REQUEST_COUNT = 5; | ||
|
||
// The @ServerSetup(MicrometerSetupTask.class) requires Docker to be available. | ||
// Otherwise the org.wildfly.extension.micrometer.registry.NoOpRegistry is installed which will result in 0 counters, | ||
// and cause the test fail seemingly intermittently on machines with broken Docker setup. | ||
@BeforeClass | ||
public static void checkForDocker() { | ||
AssumeTestGroupUtil.assumeDockerAvailable(); | ||
} | ||
|
||
protected void makeRequests(URI service) throws URISyntaxException { | ||
try (Client client = ClientBuilder.newClient()) { | ||
WebTarget target = client.target(service); | ||
for (int i = 0; i < REQUEST_COUNT; i++) { | ||
Assert.assertEquals(200, target.request().get().getStatus()); | ||
} | ||
} | ||
} | ||
|
||
protected @NotNull List<PrometheusMetric> getMetricsByName(List<PrometheusMetric> metrics, String key) { | ||
return metrics.stream() | ||
.filter(m -> m.getKey().equals(key)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...org/wildfly/test/integration/observability/micrometer/multiple/EarDeploymentTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.wildfly.test.integration.observability.micrometer.multiple; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.OperateOnDeployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.as.arquillian.api.ServerSetup; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.wildfly.test.integration.observability.container.OpenTelemetryCollectorContainer; | ||
import org.wildfly.test.integration.observability.container.PrometheusMetric; | ||
import org.wildfly.test.integration.observability.micrometer.MicrometerSetupTask; | ||
import org.wildfly.test.integration.observability.micrometer.multiple.application.DuplicateMetricResource1; | ||
import org.wildfly.test.integration.observability.micrometer.multiple.application.DuplicateMetricResource2; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
@RunWith(Arquillian.class) | ||
@ServerSetup(MicrometerSetupTask.class) | ||
public class EarDeploymentTestCase extends BaseMultipleTestCase { | ||
protected static final String ENTERPRISE_APP = "enterprise-app"; | ||
|
||
@Deployment(name = ENTERPRISE_APP) | ||
public static EnterpriseArchive createDeployment() { | ||
return ShrinkWrap.create(EnterpriseArchive.class, ENTERPRISE_APP + ".ear") | ||
.addAsModule(MultipleWarTestCase.createDeployment1()) | ||
.addAsModule(MultipleWarTestCase.createDeployment2()) | ||
.setApplicationXML(new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
+ "<application xmlns=\"https://jakarta.ee/xml/ns/jakartaee\" " + | ||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + | ||
" xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_10.xsd\" " + | ||
" version=\"10\">\n" | ||
+ " <display-name>metrics</display-name>\n" | ||
+ " <module>\n" | ||
+ " <web>\n" | ||
+ " <web-uri>" + SERVICE_ONE + ".war</web-uri>\n" | ||
+ " </web>\n" | ||
+ " </module>\n" | ||
+ " <module>\n" | ||
+ " <web>\n" | ||
+ " <web-uri>" + SERVICE_TWO + ".war</web-uri>\n" | ||
+ " </web>\n" | ||
+ " </module>\n" | ||
+ "</application>")); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void dataTest(@ArquillianResource @OperateOnDeployment(ENTERPRISE_APP) URL earUrl) | ||
throws URISyntaxException, InterruptedException { | ||
makeRequests(new URI(String.format("%s/%s/%s/%s", earUrl, ENTERPRISE_APP, SERVICE_ONE, DuplicateMetricResource1.TAG))); | ||
makeRequests(new URI(String.format("%s/%s/%s/%s", earUrl, ENTERPRISE_APP, SERVICE_TWO, DuplicateMetricResource2.TAG))); | ||
|
||
List<PrometheusMetric> results = getMetricsByName( | ||
OpenTelemetryCollectorContainer.getInstance().fetchMetrics(DuplicateMetricResource1.METER_NAME), | ||
DuplicateMetricResource1.METER_NAME + "_total"); // Adjust for Prometheus naming conventions | ||
|
||
Assert.assertEquals(2, results.size()); | ||
results.forEach(r -> Assert.assertEquals("" + REQUEST_COUNT, r.getValue())); | ||
} | ||
} |
Oops, something went wrong.