Skip to content

Commit 556319b

Browse files
committed
Fix reporting for requests with duration more than a second
1 parent 300aca5 commit 556319b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

modules/sttp4/src/main/scala/sttp/client4/smetrics/SmetricsBackend.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ object SmetricsBackend {
439439
for {
440440
recordDuration <- MeasureDuration[F].start
441441
} yield recordDuration.flatMap { recordDuration =>
442-
duration.observe(recordDuration.toSeconds.toDouble)
442+
duration.observe(recordDuration.toUnit(scala.concurrent.duration.SECONDS).toDouble)
443443
}
444444

445445
val active = activeMapper(request)

modules/sttp4/src/test/scala/sttp/client4/smetrics/SmetricsBackendSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SmetricsBackendSpec extends AsyncFunSuite with Matchers {
2323

2424
def inMemoryCollectorRegistry: CollectorRegistry[IO] = CollectorRegistry.empty[IO]
2525

26-
private val `[0, 0.1]` = Within(0, 0.1)
26+
private val `(0, 0.1]` = Within(0, 0.1)
2727

2828
def collect[A](
2929
stub: BackendStub[IO] => BackendStub[IO],
@@ -66,7 +66,7 @@ class SmetricsBackendSpec extends AsyncFunSuite with Matchers {
6666
events.collect {
6767
case MetricEvent("http_client_request_size_bytes", "summary", List("POST"), "observe", `reqSize`) => 1
6868
case MetricEvent("http_client_requests_active", "gauge", List("POST"), "inc", 1.0) => 2
69-
case MetricEvent("http_client_request_duration_seconds", "histogram", List("POST"), "observe", `[0, 0.1]`(_)) =>
69+
case MetricEvent("http_client_request_duration_seconds", "histogram", List("POST"), "observe", `(0, 0.1]`(_)) =>
7070
3
7171
case MetricEvent("http_client_requests_active", "gauge", List("POST"), "dec", 1.0) => 4
7272
case MetricEvent("http_client_response_size_bytes", "summary", List("POST", "2xx"), "observe", `rspSize`) => 5
@@ -103,7 +103,7 @@ class SmetricsBackendSpec extends AsyncFunSuite with Matchers {
103103
"histogram",
104104
List("POST"),
105105
"observe",
106-
`[0, 0.1]`(_),
106+
`(0, 0.1]`(_),
107107
) => 3
108108
case MetricEvent("http_client_requests_active", "gauge", List("POST"), "dec", 1.0) => 4
109109
case MetricEvent("http_client_response_size_bytes", "summary", List("POST", `sts`), "observe", `rspSize`) => 5
@@ -130,7 +130,7 @@ class SmetricsBackendSpec extends AsyncFunSuite with Matchers {
130130
events.collect {
131131
case MetricEvent("http_client_request_size_bytes", "summary", List("POST"), "observe", `body.length`) => 1
132132
case MetricEvent("http_client_requests_active", "gauge", List("POST"), "inc", 1.0) => 2
133-
case MetricEvent("http_client_request_duration_seconds", "histogram", List("POST"), "observe", `[0, 0.1]`(_)) =>
133+
case MetricEvent("http_client_request_duration_seconds", "histogram", List("POST"), "observe", `(0, 0.1]`(_)) =>
134134
3
135135
case MetricEvent("http_client_requests_active", "gauge", List("POST"), "dec", 1.0) => 4
136136
case MetricEvent("http_client_requests_failure", "counter", List("POST"), "inc", 1.0) => 5
@@ -279,7 +279,7 @@ class SmetricsBackendSpec extends AsyncFunSuite with Matchers {
279279
"histogram",
280280
List("POST", "labelForBackend", "labelForResource"),
281281
"observe",
282-
`[0, 0.1]`(_),
282+
`(0, 0.1]`(_),
283283
) =>
284284
3
285285
case MetricEvent(
@@ -466,7 +466,7 @@ object SmetricsBackendSpec {
466466

467467
case class Within(a: Double, b: Double) {
468468
def unapply(value: Double): Option[Double] =
469-
Option.when(value >= a && value <= b)(value)
469+
Option.when(value > a && value <= b)(value)
470470
}
471471

472472
implicit class ResponseOps[A](val response: Response[A]) extends AnyVal {

0 commit comments

Comments
 (0)