|
5 | 5 |
|
6 | 6 | package io.opentelemetry.contrib.jmxscraper.target_systems; |
7 | 7 |
|
8 | | -import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSum; |
9 | | -import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; |
| 8 | +import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute; |
| 9 | +import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup; |
10 | 10 | import static org.assertj.core.api.Assertions.assertThat; |
11 | | -import static org.assertj.core.api.Assertions.entry; |
12 | 11 |
|
13 | 12 | import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; |
| 13 | +import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcher; |
| 14 | +import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcherGroup; |
14 | 15 | import java.io.IOException; |
15 | 16 | import java.nio.file.Files; |
16 | 17 | import java.nio.file.Path; |
@@ -90,111 +91,122 @@ protected JmxScraperContainer customizeScraperContainer( |
90 | 91 | } |
91 | 92 |
|
92 | 93 | @Override |
93 | | - protected void verifyMetrics() { |
94 | | - waitAndAssertMetrics( |
95 | | - metric -> |
96 | | - assertSumWithAttributes( |
97 | | - metric, |
98 | | - "wildfly.session.count", |
99 | | - "The number of sessions created.", |
100 | | - "{session}", |
101 | | - attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), |
102 | | - metric -> |
103 | | - assertSumWithAttributes( |
104 | | - metric, |
105 | | - "wildfly.session.active", |
106 | | - "The number of currently active sessions.", |
107 | | - "{session}", |
108 | | - /* isMonotonic= */ false, |
109 | | - attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), |
110 | | - metric -> |
111 | | - assertSumWithAttributes( |
112 | | - metric, |
113 | | - "wildfly.session.expired", |
114 | | - "The number of sessions that have expired.", |
115 | | - "{session}", |
116 | | - attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), |
117 | | - metric -> |
118 | | - assertSumWithAttributes( |
119 | | - metric, |
120 | | - "wildfly.session.rejected", |
121 | | - "The number of sessions that have been rejected.", |
122 | | - "{session}", |
123 | | - attrs -> attrs.containsOnly(entry("deployment", "testapp.war"))), |
124 | | - metric -> |
125 | | - assertSumWithAttributes( |
126 | | - metric, |
127 | | - "wildfly.request.count", |
128 | | - "The number of requests received.", |
129 | | - "{request}", |
130 | | - attrs -> |
131 | | - attrs.containsOnly( |
132 | | - entry("server", "default-server"), entry("listener", "default"))), |
133 | | - metric -> |
134 | | - assertSumWithAttributes( |
135 | | - metric, |
136 | | - "wildfly.request.time", |
137 | | - "The total amount of time spent on requests.", |
138 | | - "ns", |
139 | | - attrs -> |
140 | | - attrs.containsOnly( |
141 | | - entry("server", "default-server"), entry("listener", "default"))), |
142 | | - metric -> |
143 | | - assertSumWithAttributes( |
144 | | - metric, |
145 | | - "wildfly.request.server_error", |
146 | | - "The number of requests that have resulted in a 5xx response.", |
147 | | - "{request}", |
148 | | - attrs -> |
149 | | - attrs.containsOnly( |
150 | | - entry("server", "default-server"), entry("listener", "default"))), |
151 | | - metric -> |
152 | | - assertSumWithAttributes( |
153 | | - metric, |
154 | | - "wildfly.network.io", |
155 | | - "The number of bytes transmitted.", |
156 | | - "By", |
157 | | - attrs -> |
158 | | - attrs.containsOnly( |
159 | | - entry("server", "default-server"), |
160 | | - entry("listener", "default"), |
161 | | - entry("state", "in")), |
162 | | - attrs -> |
163 | | - attrs.containsOnly( |
164 | | - entry("server", "default-server"), |
165 | | - entry("listener", "default"), |
166 | | - entry("state", "out"))), |
167 | | - metric -> |
168 | | - assertSumWithAttributes( |
169 | | - metric, |
170 | | - "wildfly.jdbc.connection.open", |
171 | | - "The number of open jdbc connections.", |
172 | | - "{connection}", |
173 | | - attrs -> |
174 | | - attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "active")), |
175 | | - attrs -> |
176 | | - attrs.containsOnly(entry("data_source", "ExampleDS"), entry("state", "idle"))), |
177 | | - metric -> |
178 | | - assertSumWithAttributes( |
179 | | - metric, |
180 | | - "wildfly.jdbc.request.wait", |
181 | | - "The number of jdbc connections that had to wait before opening.", |
182 | | - "{request}", |
183 | | - attrs -> attrs.containsOnly(entry("data_source", "ExampleDS"))), |
184 | | - metric -> |
185 | | - assertSum( |
186 | | - metric, |
187 | | - "wildfly.jdbc.transaction.count", |
188 | | - "The number of transactions created.", |
189 | | - "{transaction}"), |
190 | | - metric -> |
191 | | - assertSumWithAttributes( |
192 | | - metric, |
193 | | - "wildfly.jdbc.rollback.count", |
194 | | - "The number of transactions rolled back.", |
195 | | - "{transaction}", |
196 | | - attrs -> attrs.containsOnly(entry("cause", "system")), |
197 | | - attrs -> attrs.containsOnly(entry("cause", "resource")), |
198 | | - attrs -> attrs.containsOnly(entry("cause", "application")))); |
| 94 | + protected MetricsVerifier createMetricsVerifier() { |
| 95 | + |
| 96 | + AttributeMatcherGroup serverListenerAttributes = |
| 97 | + attributeGroup(attribute("server", "default-server"), attribute("listener", "default")); |
| 98 | + AttributeMatcher deploymentAttribute = attribute("deployment", "testapp.war"); |
| 99 | + AttributeMatcher datasourceAttribute = attribute("data_source", "ExampleDS"); |
| 100 | + return MetricsVerifier.create() |
| 101 | + .add( |
| 102 | + "wildfly.session.count", |
| 103 | + metric -> |
| 104 | + metric |
| 105 | + .isCounter() |
| 106 | + .hasDescription("The number of sessions created.") |
| 107 | + .hasUnit("{session}") |
| 108 | + .hasDataPointsWithOneAttribute(deploymentAttribute)) |
| 109 | + .add( |
| 110 | + "wildfly.session.active", |
| 111 | + metric -> |
| 112 | + metric |
| 113 | + .isUpDownCounter() |
| 114 | + .hasDescription("The number of currently active sessions.") |
| 115 | + .hasUnit("{session}") |
| 116 | + .hasDataPointsWithOneAttribute(deploymentAttribute)) |
| 117 | + .add( |
| 118 | + "wildfly.session.expired", |
| 119 | + metric -> |
| 120 | + metric |
| 121 | + .isCounter() |
| 122 | + .hasDescription("The number of sessions that have expired.") |
| 123 | + .hasUnit("{session}") |
| 124 | + .hasDataPointsWithOneAttribute(deploymentAttribute)) |
| 125 | + .add( |
| 126 | + "wildfly.session.rejected", |
| 127 | + metric -> |
| 128 | + metric |
| 129 | + .isCounter() |
| 130 | + .hasDescription("The number of sessions that have been rejected.") |
| 131 | + .hasUnit("{session}") |
| 132 | + .hasDataPointsWithOneAttribute(deploymentAttribute)) |
| 133 | + .add( |
| 134 | + "wildfly.request.count", |
| 135 | + metric -> |
| 136 | + metric |
| 137 | + .isCounter() |
| 138 | + .hasDescription("The number of requests received.") |
| 139 | + .hasUnit("{request}") |
| 140 | + .hasDataPointsWithAttributes(serverListenerAttributes)) |
| 141 | + .add( |
| 142 | + "wildfly.request.time", |
| 143 | + metric -> |
| 144 | + metric |
| 145 | + .isCounter() |
| 146 | + .hasDescription("The total amount of time spent on requests.") |
| 147 | + .hasUnit("ns") |
| 148 | + .hasDataPointsWithAttributes(serverListenerAttributes)) |
| 149 | + .add( |
| 150 | + "wildfly.request.server_error", |
| 151 | + metric -> |
| 152 | + metric |
| 153 | + .isCounter() |
| 154 | + .hasDescription("The number of requests that have resulted in a 5xx response.") |
| 155 | + .hasUnit("{request}") |
| 156 | + .hasDataPointsWithAttributes(serverListenerAttributes)) |
| 157 | + .add( |
| 158 | + "wildfly.network.io", |
| 159 | + metric -> |
| 160 | + metric |
| 161 | + .isCounter() |
| 162 | + .hasDescription("The number of bytes transmitted.") |
| 163 | + .hasUnit("By") |
| 164 | + .hasDataPointsWithAttributes( |
| 165 | + attributeGroup( |
| 166 | + attribute("server", "default-server"), |
| 167 | + attribute("listener", "default"), |
| 168 | + attribute("state", "in")), |
| 169 | + attributeGroup( |
| 170 | + attribute("server", "default-server"), |
| 171 | + attribute("listener", "default"), |
| 172 | + attribute("state", "out")))) |
| 173 | + .add( |
| 174 | + "wildfly.jdbc.connection.open", |
| 175 | + metric -> |
| 176 | + metric |
| 177 | + .isUpDownCounter() |
| 178 | + .hasDescription("The number of open jdbc connections.") |
| 179 | + .hasUnit("{connection}") |
| 180 | + .hasDataPointsWithAttributes( |
| 181 | + attributeGroup(datasourceAttribute, attribute("state", "active")), |
| 182 | + attributeGroup(datasourceAttribute, attribute("state", "idle")))) |
| 183 | + .add( |
| 184 | + "wildfly.jdbc.request.wait", |
| 185 | + metric -> |
| 186 | + metric |
| 187 | + .isCounter() |
| 188 | + .hasDescription( |
| 189 | + "The number of jdbc connections that had to wait before opening.") |
| 190 | + .hasUnit("{request}") |
| 191 | + .hasDataPointsWithOneAttribute(datasourceAttribute)) |
| 192 | + .add( |
| 193 | + "wildfly.jdbc.transaction.count", |
| 194 | + metric -> |
| 195 | + metric |
| 196 | + .isCounter() |
| 197 | + .hasDescription("The number of transactions created.") |
| 198 | + .hasUnit("{transaction}") |
| 199 | + .hasDataPointsWithoutAttributes()) |
| 200 | + .add( |
| 201 | + "wildfly.jdbc.rollback.count", |
| 202 | + metric -> |
| 203 | + metric |
| 204 | + .isCounter() |
| 205 | + .hasDescription("The number of transactions rolled back.") |
| 206 | + .hasUnit("{transaction}") |
| 207 | + .hasDataPointsWithAttributes( |
| 208 | + attributeGroup(attribute("cause", "system")), |
| 209 | + attributeGroup(attribute("cause", "resource")), |
| 210 | + attributeGroup(attribute("cause", "application")))); |
199 | 211 | } |
200 | 212 | } |
0 commit comments