Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Added metrics to SFlux/SMono #56

Merged
merged 1 commit into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/main/scala/reactor/core/scala/publisher/SFlux.scala
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ trait SFlux[T] extends SFluxLike[T, SFlux] with MapablePublisher[T] with ScalaCo

final def mergeWith(other: Publisher[_ <: T]): SFlux[T] = SFlux.fromPublisher(coreFlux.mergeWith(other))

/**
* Activate metrics for this sequence, provided there is an instrumentation facade
* on the classpath (otherwise this method is a pure no-op).
* <p>
* Metrics are gathered on [[Subscriber]] events, and it is recommended to also
* [[name]] (and optionally [[tag]]) the sequence.
*
* @return an instrumented [[SFlux]]
*/
final def metrics: SFlux[T] = SFlux.fromPublisher(coreFlux.metrics())

final def name(name: String): SFlux[T] = SFlux.fromPublisher(coreFlux.name(name))

final def next(): SMono[T] = SMono.fromPublisher(coreFlux.next())
Expand Down
15 changes: 13 additions & 2 deletions src/main/scala/reactor/core/scala/publisher/SMono.scala
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,19 @@ trait SMono[T] extends SMonoLike[T, SMono] with MapablePublisher[T] with ScalaCo
final def mergeWith(other: Publisher[_ <: T]): SFlux[T] = coreMono.mergeWith(other).asScala

/**
* Give a name to this sequence, which can be retrieved using [[Scannable.name()]]
* as long as this is the first reachable [[Scannable.parents()]].
* Activate metrics for this sequence, provided there is an instrumentation facade
* on the classpath (otherwise this method is a pure no-op).
* <p>
* Metrics are gathered on [[Subscriber]] events, and it is recommended to also
* [[name]] (and optionally [[tag]]) the sequence.
*
* @return an instrumented [[SMono]]
*/
final def metrics: SMono[T] = SMono.fromPublisher(coreMono.metrics())

/**
* Give a name to this sequence, which can be retrieved using [[Scannable.name]]
* as long as this is the first reachable [[Scannable.parents]].
*
* @param name a name for the sequence
* @return the same sequence, but bearing a name
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/reactor/core/scala/publisher/SFluxTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,11 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks
.expectNext(1, 2, 3, 4, 5, 6)
.verifyComplete()
}

".metrics should be a nop since Micrometer is not on the classpath" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also add a test with Micrometer on the classpath? You can add the library for test.

val flux = JFlux.just("plain", "awesome")
flux.asScala.metrics.coreFlux shouldBe theSameInstanceAs(flux)
}

".min" - {
"of numbers should emit the lowest value of ordering" in {
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/reactor/core/scala/publisher/SMonoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati
}
}
}

".metrics should be a nop since Micrometer is not on the classpath" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as SFluxTest, if you can add Micrometer on test classpath and add the test here that'd be good.

val mono = JMono.just("plain awesome")
mono.asScala.metrics.coreMono shouldBe theSameInstanceAs(mono)
}

".never will never signal any data, error or completion signal" in {
StepVerifier.create(SMono.never)
Expand Down