forked from quarkusio/quarkus
-
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.
- Loading branch information
1 parent
3dce2bd
commit 62da5bf
Showing
13 changed files
with
265 additions
and
4 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
30 changes: 30 additions & 0 deletions
30
...eployment/src/main/java/io/quarkus/micrometer/deployment/binder/StorkBinderProcessor.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,30 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.micrometer.runtime.MicrometerRecorder; | ||
import io.quarkus.micrometer.runtime.config.MicrometerConfig; | ||
|
||
public class StorkBinderProcessor { | ||
|
||
static final String OBSERVABLE_CLIENT = "io.smallrye.stork.api.Service"; | ||
static final String METRICS_BEAN_CLASS = "io.quarkus.micrometer.runtime.binder.stork.StorkObservationCollectorBean"; | ||
|
||
static final Class<?> OBSERVABLE_CLIENT_CLASS = MicrometerRecorder.getClassForName(OBSERVABLE_CLIENT); | ||
|
||
static class StorkMetricsSupportEnabled implements BooleanSupplier { | ||
MicrometerConfig mConfig; | ||
|
||
public boolean getAsBoolean() { | ||
return OBSERVABLE_CLIENT_CLASS != null && mConfig.checkBinderEnabledWithDefault(mConfig.binder.stork); | ||
} | ||
} | ||
|
||
@BuildStep(onlyIf = StorkMetricsSupportEnabled.class) | ||
AdditionalBeanBuildItem addRedisClientMetric() { | ||
return AdditionalBeanBuildItem.unremovableOf(METRICS_BEAN_CLASS); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...yment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsDisabledTest.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,33 @@ | ||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.stork.api.Service; | ||
|
||
public class StorkMetricsDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("test-logging.properties") | ||
.overrideConfigKey("quarkus.micrometer.binder.stork.enabled", "false") | ||
.overrideConfigKey("quarkus.micrometer.binder-enabled-default", "false") | ||
.overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false") | ||
.withEmptyApplication(); | ||
|
||
@Inject | ||
Instance<Service> bean; | ||
|
||
@Test | ||
void testNoInstancePresentIfNoRedisClientsClass() { | ||
assertTrue(bean.isUnsatisfied(), | ||
"No redis metrics bean"); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...er/deployment/src/test/java/io/quarkus/micrometer/deployment/binder/StorkMetricsTest.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,22 @@ | ||
|
||
package io.quarkus.micrometer.deployment.binder; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@DisabledOnOs(OS.WINDOWS) | ||
public class StorkMetricsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest(); | ||
|
||
@Inject | ||
MeterRegistry registry; | ||
|
||
} |
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
77 changes: 77 additions & 0 deletions
77
...c/main/java/io/quarkus/micrometer/runtime/binder/stork/StorkObservationCollectorBean.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,77 @@ | ||
package io.quarkus.micrometer.runtime.binder.stork; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Typed; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.smallrye.stork.api.ServiceInstance; | ||
import io.smallrye.stork.api.observability.ObservationCollector; | ||
import io.smallrye.stork.api.observability.ObservationPoints; | ||
|
||
@ApplicationScoped | ||
@Typed(ObservationCollector.class) | ||
public class StorkObservationCollectorBean implements ObservationCollector { | ||
|
||
final MeterRegistry registry = Metrics.globalRegistry; | ||
|
||
private final EventCompletionHandler STORK_HANDLER = ev -> { | ||
//TODO | ||
}; | ||
public static ObservationPoints.StorkResolutionEvent STORK_METRICS; | ||
|
||
@Override | ||
public ObservationPoints.StorkResolutionEvent create(String serviceName, String serviceDiscoveryType, | ||
String serviceSelectionType) { | ||
STORK_METRICS = new ObservationPoints.StorkResolutionEvent(serviceName, serviceDiscoveryType, serviceSelectionType, | ||
STORK_HANDLER) { | ||
|
||
private final Tags tags = Tags.of(Tag.of("client-name", getServiceName()));; | ||
private final Counter instanceCounter = Counter.builder("stork.instances.count") | ||
.description("The number of service instances discovered") | ||
.tags(tags) | ||
.register(registry);; | ||
private String name = serviceName; | ||
|
||
private volatile long endOfServiceDiscovery; | ||
|
||
private final Timer timer = Timer.builder("stork.service-discovery.duration") | ||
.description("The duration of the operations (commands of batches") | ||
.tags(tags) | ||
.register(registry); | ||
|
||
@Override | ||
public void onServiceDiscoverySuccess(List<ServiceInstance> instances) { | ||
this.endOfServiceDiscovery = System.nanoTime(); | ||
if (instances != null) { | ||
instanceCounter.increment(instances.size()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onServiceDiscoveryFailure(Throwable throwable) { | ||
// Noop | ||
} | ||
|
||
@Override | ||
public void onServiceSelectionSuccess(long id) { | ||
// Noop | ||
} | ||
|
||
@Override | ||
public void onServiceSelectionFailure(Throwable throwable) { | ||
// Noop | ||
} | ||
|
||
}; | ||
return STORK_METRICS; | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
...crometer/runtime/src/main/java/io/quarkus/micrometer/runtime/config/StorkConfigGroup.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,33 @@ | ||
package io.quarkus.micrometer.runtime.config; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class StorkConfigGroup implements MicrometerConfig.CapabilityEnabled { | ||
/** | ||
* Stork metrics support. | ||
* <p> | ||
* Support for Stork metrics will be enabled if Micrometer support is enabled, | ||
* the Quarkus Stork extension is on the classpath | ||
* and either this value is true, or this value is unset and | ||
* {@code quarkus.micrometer.binder-enabled-default} is true. | ||
*/ | ||
@ConfigItem | ||
public Optional<Boolean> enabled; | ||
|
||
@Override | ||
public Optional<Boolean> getEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getSimpleName() | ||
+ "{enabled=" + enabled | ||
+ '}'; | ||
} | ||
|
||
} |
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