Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public MetricsVerifier disableStrictMode() {
*/
@CanIgnoreReturnValue
public MetricsVerifier add(String metricName, Consumer<MetricAssert> assertion) {
if (assertions.containsKey(metricName)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] this ensures that we don't have duplicated assertions for the same metric.

throw new IllegalArgumentException("Duplicate assertion for metric " + metricName);
}
assertions.put(
metricName,
metric -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

package io.opentelemetry.contrib.jmxscraper.target_systems;

import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSum;
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes;
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute;
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcher;
import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcherGroup;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -90,111 +91,122 @@ protected JmxScraperContainer customizeScraperContainer(
}

@Override
protected void verifyMetrics() {
waitAndAssertMetrics(
metric ->
assertSumWithAttributes(
metric,
"wildfly.session.count",
"The number of sessions created.",
"{session}",
attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.session.active",
"The number of currently active sessions.",
"{session}",
/* isMonotonic= */ false,
attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.session.expired",
"The number of sessions that have expired.",
"{session}",
attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.session.rejected",
"The number of sessions that have been rejected.",
"{session}",
attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.request.count",
"The number of requests received.",
"{request}",
attrs ->
attrs.containsOnly(
entry("server", "default-server"), entry("listener", "default"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.request.time",
"The total amount of time spent on requests.",
"ns",
attrs ->
attrs.containsOnly(
entry("server", "default-server"), entry("listener", "default"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.request.server_error",
"The number of requests that have resulted in a 5xx response.",
"{request}",
attrs ->
attrs.containsOnly(
entry("server", "default-server"), entry("listener", "default"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.network.io",
"The number of bytes transmitted.",
"By",
attrs ->
attrs.containsOnly(
entry("server", "default-server"),
entry("listener", "default"),
entry("state", "in")),
attrs ->
attrs.containsOnly(
entry("server", "default-server"),
entry("listener", "default"),
entry("state", "out"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.jdbc.connection.open",
"The number of open jdbc connections.",
"{connection}",
attrs ->
attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "active")),
attrs ->
attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "idle"))),
metric ->
assertSumWithAttributes(
metric,
"wildfly.jdbc.request.wait",
"The number of jdbc connections that had to wait before opening.",
"{request}",
attrs -> attrs.containsOnly(entry("data_source", "ExampleDS"))),
metric ->
assertSum(
metric,
"wildfly.jdbc.transaction.count",
"The number of transactions created.",
"{transaction}"),
metric ->
assertSumWithAttributes(
metric,
"wildfly.jdbc.rollback.count",
"The number of transactions rolled back.",
"{transaction}",
attrs -> attrs.containsOnly(entry("cause", "system")),
attrs -> attrs.containsOnly(entry("cause", "resource")),
attrs -> attrs.containsOnly(entry("cause", "application"))));
protected MetricsVerifier createMetricsVerifier() {

AttributeMatcherGroup serverListenerAttributes =
attributeGroup(attribute("server", "default-server"), attribute("listener", "default"));
AttributeMatcher deploymentAttribute = attribute("deployment", "testapp.war");
AttributeMatcher datasourceAttribute = attribute("data_source", "ExampleDS");
return MetricsVerifier.create()
.add(
"wildfly.session.count",
metric ->
metric
.isCounter()
.hasDescription("The number of sessions created.")
.hasUnit("{session}")
.hasDataPointsWithOneAttribute(deploymentAttribute))
.add(
"wildfly.session.active",
metric ->
metric
.isUpDownCounter()
.hasDescription("The number of currently active sessions.")
.hasUnit("{session}")
.hasDataPointsWithOneAttribute(deploymentAttribute))
.add(
"wildfly.session.expired",
metric ->
metric
.isCounter()
.hasDescription("The number of sessions that have expired.")
.hasUnit("{session}")
.hasDataPointsWithOneAttribute(deploymentAttribute))
.add(
"wildfly.session.rejected",
metric ->
metric
.isCounter()
.hasDescription("The number of sessions that have been rejected.")
.hasUnit("{session}")
.hasDataPointsWithOneAttribute(deploymentAttribute))
.add(
"wildfly.request.count",
metric ->
metric
.isCounter()
.hasDescription("The number of requests received.")
.hasUnit("{request}")
.hasDataPointsWithAttributes(serverListenerAttributes))
.add(
"wildfly.request.time",
metric ->
metric
.isCounter()
.hasDescription("The total amount of time spent on requests.")
.hasUnit("ns")
.hasDataPointsWithAttributes(serverListenerAttributes))
.add(
"wildfly.request.server_error",
metric ->
metric
.isCounter()
.hasDescription("The number of requests that have resulted in a 5xx response.")
.hasUnit("{request}")
.hasDataPointsWithAttributes(serverListenerAttributes))
.add(
"wildfly.network.io",
metric ->
metric
.isCounter()
.hasDescription("The number of bytes transmitted.")
.hasUnit("By")
.hasDataPointsWithAttributes(
attributeGroup(
attribute("server", "default-server"),
attribute("listener", "default"),
attribute("state", "in")),
attributeGroup(
attribute("server", "default-server"),
attribute("listener", "default"),
attribute("state", "out"))))
.add(
"wildfly.jdbc.connection.open",
metric ->
metric
.isUpDownCounter()
.hasDescription("The number of open jdbc connections.")
.hasUnit("{connection}")
.hasDataPointsWithAttributes(
attributeGroup(datasourceAttribute, attribute("state", "active")),
attributeGroup(datasourceAttribute, attribute("state", "idle"))))
.add(
"wildfly.jdbc.request.wait",
metric ->
metric
.isCounter()
.hasDescription(
"The number of jdbc connections that had to wait before opening.")
.hasUnit("{request}")
.hasDataPointsWithOneAttribute(datasourceAttribute))
.add(
"wildfly.jdbc.transaction.count",
metric ->
metric
.isCounter()
.hasDescription("The number of transactions created.")
.hasUnit("{transaction}")
.hasDataPointsWithoutAttributes())
.add(
"wildfly.jdbc.rollback.count",
metric ->
metric
.isCounter()
.hasDescription("The number of transactions rolled back.")
.hasUnit("{transaction}")
.hasDataPointsWithAttributes(
attributeGroup(attribute("cause", "system")),
attributeGroup(attribute("cause", "resource")),
attributeGroup(attribute("cause", "application"))));
}
}
4 changes: 3 additions & 1 deletion jmx-scraper/src/main/resources/wildfly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ rules:
- bean: jboss.as:subsystem=datasources,data-source=*,statistics=pool
metricAttribute:
data_source: param(data-source)
type: counter
prefix: wildfly.jdbc.
mapping:
ActiveCount:
metric: &metric connection.open
type: updowncounter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[for reviewer] this was actually a mistake made when creating the yaml mapping.

unit: &unit "{connection}"
desc: &desc The number of open jdbc connections.
metricAttribute:
state: const(active)
IdleCount:
metric: *metric
type: updowncounter
unit: *unit
desc: *desc
metricAttribute:
state: const(idle)
WaitCount:
type: counter
metric: request.wait
unit: "{request}"
desc: The number of jdbc connections that had to wait before opening.
Expand Down
Loading