-
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 Add a TestEnricher to manage lifecycle and injection of the Otel container
- Loading branch information
Showing
25 changed files
with
616 additions
and
209 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../microprofile/src/test/java/org/wildfly/test/integration/observability/TestContainer.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,15 @@ | ||
package org.wildfly.test.integration.observability; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Inherited | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.PARAMETER}) | ||
public @interface TestContainer { | ||
} |
69 changes: 69 additions & 0 deletions
69
...file/src/test/java/org/wildfly/test/integration/observability/TestContainersEnricher.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; | ||
|
||
import org.jboss.arquillian.test.spi.TestEnricher; | ||
import org.jboss.as.test.shared.util.AssumeTestGroupUtil; | ||
import org.wildfly.test.integration.observability.container.OpenTelemetryCollectorContainer; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestContainersEnricher implements TestEnricher { | ||
private static final ThreadLocal<OpenTelemetryCollectorContainer> otelCollectorContainer = new ThreadLocal<>(); | ||
|
||
@Override | ||
public void enrich(Object testCase) { | ||
AssumeTestGroupUtil.assumeDockerAvailable(); | ||
|
||
for (Field field : getFieldsWithAnnotation(testCase.getClass())) { | ||
OpenTelemetryCollectorContainer value = lookup(field.getType()); | ||
try { | ||
if (!field.canAccess(testCase)) { | ||
field.setAccessible(true); | ||
} | ||
field.set(testCase, value); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not set value on field " + field + " using " + value, e); | ||
} | ||
} | ||
} | ||
|
||
private OpenTelemetryCollectorContainer lookup(Class<?> type) { | ||
if (type.isAssignableFrom(OpenTelemetryCollectorContainer.class)) { | ||
|
||
OpenTelemetryCollectorContainer container = otelCollectorContainer.get(); | ||
if (container == null) { | ||
container = new OpenTelemetryCollectorContainer(); | ||
container.start(); | ||
otelCollectorContainer.set(container); | ||
} | ||
return container; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object[] resolve(Method method) { | ||
return new Object[0]; | ||
} | ||
|
||
private List<Field> getFieldsWithAnnotation(final Class<?> source) { | ||
return AccessController.doPrivileged((PrivilegedAction<List<Field>>) () -> { | ||
List<Field> foundFields = new ArrayList<>(); | ||
Class<?> nextSource = source; | ||
while (nextSource != Object.class) { | ||
for (Field field : nextSource.getDeclaredFields()) { | ||
if (field.isAnnotationPresent(TestContainer.class)) { | ||
field.setAccessible(true); | ||
foundFields.add(field); | ||
} | ||
} | ||
nextSource = nextSource.getSuperclass(); | ||
} | ||
return foundFields; | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ile/src/test/java/org/wildfly/test/integration/observability/TestContainersExtension.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,11 @@ | ||
package org.wildfly.test.integration.observability; | ||
|
||
import org.jboss.arquillian.core.spi.LoadableExtension; | ||
import org.jboss.arquillian.test.spi.TestEnricher; | ||
|
||
public class TestContainersExtension implements LoadableExtension { | ||
@Override | ||
public void register(ExtensionBuilder builder) { | ||
builder.service(TestEnricher.class, TestContainersEnricher.class); | ||
} | ||
} |
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
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
59 changes: 59 additions & 0 deletions
59
.../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,59 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
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
Oops, something went wrong.