forked from reactor/reactor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix reactor#1383 metrics() without Micrometer triggers NoClassDefFoun…
…dError Reorganizes the micrometer detection into a dedicated class `Metrics`, which avoids loading the entire `FluxMetrics` class, including Micrometer-dependent code.
- Loading branch information
1 parent
a0d5de1
commit b7ee63f
Showing
11 changed files
with
225 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2011-2018 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.util; | ||
|
||
import static io.micrometer.core.instrument.Metrics.globalRegistry; | ||
|
||
/** | ||
* Utilities around instrumentation and metrics with Micrometer. | ||
* | ||
* @author Simon Baslé | ||
*/ | ||
public class Metrics { | ||
|
||
static final boolean isMicrometerAvailable; | ||
|
||
static { | ||
boolean micrometer; | ||
try { | ||
globalRegistry.getRegistries(); | ||
micrometer = true; | ||
} | ||
catch (Throwable t) { | ||
micrometer = false; | ||
} | ||
isMicrometerAvailable = micrometer; | ||
} | ||
|
||
/** | ||
* Check if the current runtime supports metrics / instrumentation, by | ||
* verifying if Micrometer is on the classpath. | ||
* | ||
* @return true if the Micrometer instrumentation facade is available | ||
*/ | ||
public static final boolean isInstrumentationAvailable() { | ||
return isMicrometerAvailable; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
reactor-core/src/test/java/reactor/util/MetricsNoMicrometerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2011-2018 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.util; | ||
|
||
import org.assertj.core.api.Assumptions; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
/** | ||
* This test case should be OK to run in the normal test source set, but is intended | ||
* for a test sourceset that doesn't include Micrometer dependency, and which only runs | ||
* tests validating the likes of {@link Flux#metrics()} are NO-OP in that context. | ||
* | ||
* @author Simon Baslé | ||
*/ | ||
public class MetricsNoMicrometerTest { | ||
|
||
|
||
@BeforeClass | ||
public static void assumeNoMicrometer() { | ||
Assumptions.assumeThat(Metrics.isInstrumentationAvailable()) | ||
.as("Micrometer on the classpath").isFalse(); | ||
} | ||
|
||
@Test | ||
public void isMicrometerAvailable() { | ||
assertThat(Metrics.isInstrumentationAvailable()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void FluxMetricsNoOp() { | ||
assertThatCode(() -> Flux.just("foo").hide().metrics().blockLast()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void FluxMetricsFusedNoOp() { | ||
assertThatCode(() -> Flux.just("foo").metrics().blockLast()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void MonoMetricsNoOp() { | ||
assertThatCode(() -> Mono.just("foo").hide().metrics().block()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void MonoMetricsFusedNoOp() { | ||
assertThatCode(() -> Mono.just("foo").metrics().block()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
} |
Oops, something went wrong.