@@ -26,8 +26,6 @@ import scala.concurrent.duration._
2626
2727class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
2828
29- import PrometheusRegistry ._
30-
3129 object CustomRequestLabeler extends HttpRequestLabeler {
3230 override def name = " custom_request_dim"
3331 def label = " custom_request_label"
@@ -40,20 +38,18 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
4038 override def label (response : HttpResponse ): String = label
4139 }
4240
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+ )
5753
5854 trait Fixture {
5955
@@ -105,6 +101,18 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
105101 )
106102 }
107103
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+
108116 it should " set requestsActive metrics in the underlying registry" in new Fixture {
109117 registry.requestsActive.inc()
110118 underlyingCounterValue(" akka_http_requests_active" ) shouldBe 1L
@@ -116,8 +124,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
116124 }
117125
118126 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
121130 }
122131
123132 it should " set requests metrics in the underlying registry" in new Fixture {
@@ -131,8 +140,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
131140 }
132141
133142 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
136146 }
137147
138148 it should " set requestsSize metrics in the underlying registry" in new Fixture {
@@ -146,8 +156,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
146156 }
147157
148158 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
151162 }
152163
153164 it should " set responses metrics in the underlying registry" in new Fixture {
@@ -161,8 +172,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
161172 }
162173
163174 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
166178 }
167179
168180 it should " set responsesErrors metrics in the underlying registry" in new Fixture {
@@ -176,8 +188,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
176188 }
177189
178190 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
181194 }
182195
183196 it should " set responsesDuration metrics in the underlying registry" in new Fixture {
@@ -191,8 +204,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
191204 }
192205
193206 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
196210 }
197211
198212 it should " set responsesSize metrics in the underlying registry" in new Fixture {
@@ -206,8 +220,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
206220 }
207221
208222 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
211226 }
212227
213228 it should " set connectionsActive metrics in the underlying registry" in new Fixture {
@@ -221,8 +236,9 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
221236 }
222237
223238 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
226242 }
227243
228244 it should " set connections metrics in the underlying registry" in new Fixture {
@@ -236,7 +252,8 @@ class PrometheusRegistrySpec extends AnyFlatSpec with Matchers {
236252 }
237253
238254 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
241258 }
242259}
0 commit comments