@@ -26,8 +26,6 @@ import scala.concurrent.duration._
26
26
27
27
class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
28
28
29
- import PrometheusRegistry ._
30
-
31
29
object CustomRequestLabeler extends HttpRequestLabeler {
32
30
override def name = " custom_request_dim"
33
31
def label = " custom_request_label"
@@ -40,20 +38,18 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
40
38
override def label (response : HttpResponse ): String = label
41
39
}
42
40
43
- val serverDimensions = List (Dimension (" server_dim" , " server_label" ))
44
- val customRequestDimensions = List (Dimension (CustomRequestLabeler .name, CustomRequestLabeler .label))
45
- val customResponseDimensions = List (Dimension (CustomResponseLabeler .name, CustomResponseLabeler .label))
46
-
47
- val requestsDimensions = (
48
- serverDimensions ++
49
- customRequestDimensions ++
50
- List (Dimension (MethodLabeler .name, " GET" ))
51
- ).sorted
52
- val responsesDimensions = (
53
- requestsDimensions ++
54
- customResponseDimensions ++
55
- List (Dimension (PathLabeler .name, " /api" ), Dimension (StatusGroupLabeler .name, " 2xx" ))
56
- ).sorted
41
+ val serverDimensions = List (
42
+ Dimension (" server_dim" , " server_label" )
43
+ )
44
+ val requestsDimensions = List (
45
+ Dimension (MethodLabeler .name, " GET" ),
46
+ Dimension (CustomRequestLabeler .name, CustomRequestLabeler .label)
47
+ )
48
+ val responsesDimensions = List (
49
+ Dimension (StatusGroupLabeler .name, " 2xx" ),
50
+ Dimension (PathLabeler .name, " /api" ),
51
+ Dimension (CustomResponseLabeler .name, CustomResponseLabeler .label)
52
+ )
57
53
58
54
trait Fixture {
59
55
@@ -105,6 +101,18 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
105
101
)
106
102
}
107
103
104
+ it should " not have any dimensions by default" in new Fixture {
105
+ registry.serverDimensions shouldBe empty
106
+ registry.requestsDimensions shouldBe empty
107
+ registry.responsesDimensions shouldBe empty
108
+ }
109
+
110
+ it should " add proper dimensions when configured" in new DimensionFixture {
111
+ registry.serverDimensions should contain theSameElementsInOrderAs serverDimensions.map(_.name)
112
+ registry.requestsDimensions should contain theSameElementsInOrderAs requestsDimensions.map(_.name)
113
+ registry.responsesDimensions should contain theSameElementsInOrderAs responsesDimensions.map(_.name)
114
+ }
115
+
108
116
it should " set requestsActive metrics in the underlying registry" in new Fixture {
109
117
registry.requestsActive.inc()
110
118
underlyingCounterValue(" akka_http_requests_active" ) shouldBe 1L
@@ -116,8 +124,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
116
124
}
117
125
118
126
it should " set requestsActive metrics in the underlying registry with dimensions" in new DimensionFixture {
119
- registry.requestsActive.inc(requestsDimensions)
120
- underlyingCounterValue(" akka_http_requests_active" , requestsDimensions) shouldBe 1L
127
+ val dim = serverDimensions ++ requestsDimensions
128
+ registry.requestsActive.inc(dim)
129
+ underlyingCounterValue(" akka_http_requests_active" , dim) shouldBe 1L
121
130
}
122
131
123
132
it should " set requests metrics in the underlying registry" in new Fixture {
@@ -131,8 +140,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
131
140
}
132
141
133
142
it should " set requests metrics in the underlying registry with dimensions" in new DimensionFixture {
134
- registry.requests.inc(requestsDimensions)
135
- underlyingCounterValue(" akka_http_requests_total" , requestsDimensions) shouldBe 1L
143
+ val dims = serverDimensions ++ requestsDimensions
144
+ registry.requests.inc(dims)
145
+ underlyingCounterValue(" akka_http_requests_total" , dims) shouldBe 1L
136
146
}
137
147
138
148
it should " set requestsSize metrics in the underlying registry" in new Fixture {
@@ -146,8 +156,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
146
156
}
147
157
148
158
it should " set requestsSize metrics in the underlying registry with dimensions" in new DimensionFixture {
149
- registry.requestsSize.update(3 , requestsDimensions)
150
- underlyingHistogramValue(" akka_http_requests_size_bytes" , requestsDimensions) shouldBe 3L
159
+ val dims = serverDimensions ++ requestsDimensions
160
+ registry.requestsSize.update(3 , dims)
161
+ underlyingHistogramValue(" akka_http_requests_size_bytes" , dims) shouldBe 3L
151
162
}
152
163
153
164
it should " set responses metrics in the underlying registry" in new Fixture {
@@ -161,8 +172,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
161
172
}
162
173
163
174
it should " set responses metrics in the underlying registry with dimensions" in new DimensionFixture {
164
- registry.responses.inc(responsesDimensions)
165
- underlyingCounterValue(" akka_http_responses_total" , responsesDimensions) shouldBe 1L
175
+ val dims = serverDimensions ++ requestsDimensions ++ responsesDimensions
176
+ registry.responses.inc(dims)
177
+ underlyingCounterValue(" akka_http_responses_total" , dims) shouldBe 1L
166
178
}
167
179
168
180
it should " set responsesErrors metrics in the underlying registry" in new Fixture {
@@ -176,8 +188,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
176
188
}
177
189
178
190
it should " set responsesErrors metrics in the underlying registry with dimensions" in new DimensionFixture {
179
- registry.responsesErrors.inc(responsesDimensions)
180
- underlyingCounterValue(" akka_http_responses_errors_total" , responsesDimensions) shouldBe 1L
191
+ val dims = serverDimensions ++ requestsDimensions ++ responsesDimensions
192
+ registry.responsesErrors.inc(dims)
193
+ underlyingCounterValue(" akka_http_responses_errors_total" , dims) shouldBe 1L
181
194
}
182
195
183
196
it should " set responsesDuration metrics in the underlying registry" in new Fixture {
@@ -191,8 +204,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
191
204
}
192
205
193
206
it should " set responsesDuration metrics in the underlying registry with dimension" in new DimensionFixture {
194
- registry.responsesDuration.observe(3 .seconds, responsesDimensions)
195
- underlyingHistogramValue(" akka_http_responses_duration_seconds" , responsesDimensions) shouldBe 3.0
207
+ val dims = serverDimensions ++ requestsDimensions ++ responsesDimensions
208
+ registry.responsesDuration.observe(3 .seconds, dims)
209
+ underlyingHistogramValue(" akka_http_responses_duration_seconds" , dims) shouldBe 3.0
196
210
}
197
211
198
212
it should " set responsesSize metrics in the underlying registry" in new Fixture {
@@ -206,8 +220,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
206
220
}
207
221
208
222
it should " set responsesSize metrics in the underlying registry with dimensions" in new DimensionFixture {
209
- registry.responsesSize.update(3 , responsesDimensions)
210
- underlyingHistogramValue(" akka_http_responses_size_bytes" , responsesDimensions) shouldBe 3L
223
+ val dims = serverDimensions ++ requestsDimensions ++ responsesDimensions
224
+ registry.responsesSize.update(3 , dims)
225
+ underlyingHistogramValue(" akka_http_responses_size_bytes" , dims) shouldBe 3L
211
226
}
212
227
213
228
it should " set connectionsActive metrics in the underlying registry" in new Fixture {
@@ -221,8 +236,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
221
236
}
222
237
223
238
it should " set connectionsActive metrics in the underlying registry with dimensions" in new DimensionFixture {
224
- registry.connectionsActive.inc(serverDimensions)
225
- underlyingCounterValue(" akka_http_connections_active" , serverDimensions) shouldBe 1L
239
+ val dims = serverDimensions
240
+ registry.connectionsActive.inc(dims)
241
+ underlyingCounterValue(" akka_http_connections_active" , dims) shouldBe 1L
226
242
}
227
243
228
244
it should " set connections metrics in the underlying registry" in new Fixture {
@@ -236,7 +252,8 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
236
252
}
237
253
238
254
it should " set connections metrics in the underlying registry with dimensions" in new DimensionFixture {
239
- registry.connections.inc(serverDimensions)
240
- underlyingCounterValue(" akka_http_connections_total" , serverDimensions) shouldBe 1L
255
+ val dims = serverDimensions
256
+ registry.connections.inc(dims)
257
+ underlyingCounterValue(" akka_http_connections_total" , dims) shouldBe 1L
241
258
}
242
259
}
0 commit comments