Added documented meters and additional counters
This commit is contained in:
@@ -77,6 +77,12 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.zipkin.brave</groupId>
|
||||
<artifactId>brave</artifactId>
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.modulith.observability.ModulithObservations.LowKeys;
|
||||
* Default implementation of {@link ModulithObservationConvention}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public class DefaultModulithObservationConvention implements ModulithObservationConvention {
|
||||
|
||||
|
||||
@@ -70,9 +70,10 @@ class ModuleEntryInterceptor implements MethodInterceptor {
|
||||
ModulithObservationConvention custom, Environment environment) {
|
||||
|
||||
Assert.notNull(module, "ObservedModule must not be null!");
|
||||
Assert.notNull(observationRegistry, "Tracer must not be null!");
|
||||
Assert.notNull(observationRegistry, "ObservationRegistry must not be null!");
|
||||
|
||||
this.module = module; this.observationRegistry = observationRegistry;
|
||||
this.module = module;
|
||||
this.observationRegistry = observationRegistry;
|
||||
this.customModulithObservationConvention = custom;
|
||||
this.environment = environment;
|
||||
}
|
||||
@@ -115,7 +116,6 @@ class ModuleEntryInterceptor implements MethodInterceptor {
|
||||
|
||||
LOGGER.trace("Entering {} via {}.", module.getDisplayName(), invokedMethod);
|
||||
|
||||
// TODO: Good name for metrics
|
||||
ModulithContext modulithContext = new ModulithContext(module, invocation, environment);
|
||||
var observation = Observation.createNotStarted(customModulithObservationConvention, DEFAULT,
|
||||
() -> modulithContext, observationRegistry);
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.modulith.observability;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.observation.Observation.Event;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -35,20 +36,24 @@ public class ModuleEventListener implements ApplicationListener<ApplicationEvent
|
||||
|
||||
private final ApplicationModulesRuntime runtime;
|
||||
private final Supplier<ObservationRegistry> observationRegistry;
|
||||
private final Supplier<MeterRegistry> meterRegistry;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ModuleEventListener} for the given {@link ApplicationModulesRuntime} and {@link Tracer}.
|
||||
* Creates a new {@link ModuleEventListener} for the given {@link ApplicationModulesRuntime} and {@link ObservationRegistry} and {@link MeterRegistry}.
|
||||
*
|
||||
* @param runtime must not be {@literal null}.
|
||||
* @param observationRegistrySupplier must not be {@literal null}.
|
||||
*/
|
||||
public ModuleEventListener(ApplicationModulesRuntime runtime, Supplier<ObservationRegistry> observationRegistrySupplier) {
|
||||
public ModuleEventListener(ApplicationModulesRuntime runtime, Supplier<ObservationRegistry> observationRegistrySupplier,
|
||||
Supplier<MeterRegistry> meterRegistrySupplier) {
|
||||
|
||||
Assert.notNull(runtime, "ApplicationModulesRuntime must not be null!");
|
||||
Assert.notNull(observationRegistrySupplier, "Tracer must not be null!");
|
||||
Assert.notNull(observationRegistrySupplier, "ObservationRegistry must not be null!");
|
||||
Assert.notNull(meterRegistrySupplier, "MeterRegistry must not be null!");
|
||||
|
||||
this.runtime = runtime;
|
||||
this.observationRegistry = observationRegistrySupplier;
|
||||
this.meterRegistry = meterRegistrySupplier;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -77,6 +82,14 @@ public class ModuleEventListener implements ApplicationListener<ApplicationEvent
|
||||
return;
|
||||
}
|
||||
|
||||
MeterRegistry registry = meterRegistry.get();
|
||||
if (registry != null) {
|
||||
Counter.builder(ModulithMetrics.EVENTS.getName()) //
|
||||
.tags(ModulithMetrics.LowKeys.EVENT_TYPE.name(), event.getClass().getSimpleName()) //
|
||||
.tags(ModulithMetrics.LowKeys.MODULE_NAME.name(), moduleByType.getDisplayName()) //
|
||||
.register(registry).increment();
|
||||
}
|
||||
|
||||
var observation = observationRegistry.get().getCurrentObservation();
|
||||
|
||||
if (observation == null) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.modulith.observability;
|
||||
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@@ -56,7 +55,7 @@ public class ModuleObservabilityBeanPostProcessor extends ModuleObservabilitySup
|
||||
|
||||
/**
|
||||
* Creates a new {@link ModuleObservabilityBeanPostProcessor} for the given {@link ApplicationModulesRuntime} and
|
||||
* {@link Tracer}.
|
||||
* {@link ObservationRegistry}.
|
||||
*
|
||||
* @param runtime must not be {@literal null}.
|
||||
* @param observationRegistry must not be {@literal null}.
|
||||
|
||||
@@ -23,7 +23,7 @@ import io.micrometer.observation.ObservationFilter;
|
||||
* to child.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ModulePassingObservationFilter implements ObservationFilter {
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.core.env.Environment;
|
||||
* A {@link Observation.Context} for Modulithic applications.
|
||||
*
|
||||
* @author Marcin Grzejsczak
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ModulithContext extends Observation.Context {
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.springframework.modulith.observability;
|
||||
|
||||
import io.micrometer.common.docs.KeyName;
|
||||
import io.micrometer.core.instrument.Meter;
|
||||
import io.micrometer.core.instrument.docs.MeterDocumentation;
|
||||
|
||||
enum ModulithMetrics implements MeterDocumentation {
|
||||
|
||||
/**
|
||||
* Counter for the events.
|
||||
*/
|
||||
EVENTS {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "modulith.events.processed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meter.Type getType() {
|
||||
return Meter.Type.COUNTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyName[] getKeyNames() {
|
||||
return LowKeys.values();
|
||||
}
|
||||
};
|
||||
|
||||
enum LowKeys implements KeyName {
|
||||
/**
|
||||
* Type of the emitted event.
|
||||
*/
|
||||
EVENT_TYPE {
|
||||
@Override
|
||||
public String asString() {
|
||||
return "event.type";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Name of the module.
|
||||
*/
|
||||
MODULE_NAME {
|
||||
@Override
|
||||
public String asString() {
|
||||
return "module.name";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import io.micrometer.observation.ObservationConvention;
|
||||
* {@link ObservationConvention} for {@link ModulithContext}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface ModulithObservationConvention extends ObservationConvention<ModulithContext> {
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.modulith.core.ArchitecturallyEvidentType;
|
||||
* Information about observed module.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface ObservedModule {
|
||||
|
||||
@@ -90,7 +90,7 @@ public interface ObservedModule {
|
||||
* method invocation on a Spring bean.
|
||||
*
|
||||
* @param invocation must not be {@literal null}.
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
boolean isEventListenerInvocation(MethodInvocation invocation);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* Represents a type in an {@link ObservedModule}.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
* @since 1.3
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ObservedModuleType {
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.modulith.observability;
|
||||
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -47,7 +46,7 @@ public class SpringDataRestModuleObservabilityBeanPostProcessor extends ModuleOb
|
||||
|
||||
/**
|
||||
* Creates a new {@link SpringDataRestModuleObservabilityBeanPostProcessor} for the given {@link ApplicationModulesRuntime}
|
||||
* and {@link Tracer}.
|
||||
* and {@link ObservationRegistry}.
|
||||
*
|
||||
* @param runtime must not be {@literal null}.
|
||||
* @param observationRegistry must not be {@literal null}.
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.springframework.modulith.observability.autoconfigure;
|
||||
import brave.handler.MutableSpan;
|
||||
import brave.handler.SpanHandler;
|
||||
import brave.propagation.TraceContext;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.observation.ObservationFilter;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -54,8 +54,8 @@ class ModuleObservabilityAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
static ModuleEventListener tracingModuleEventListener(ApplicationModulesRuntime runtime,
|
||||
ObjectProvider<ObservationRegistry> observationRegistry) {
|
||||
return new ModuleEventListener(runtime, observationRegistry::getObject);
|
||||
ObjectProvider<ObservationRegistry> observationRegistry, ObjectProvider<MeterRegistry> meterRegistry) {
|
||||
return new ModuleEventListener(runtime, observationRegistry::getObject, meterRegistry::getObject);
|
||||
}
|
||||
|
||||
// TODO: Have a custom thread pool for modulith
|
||||
|
||||
Reference in New Issue
Block a user