Repository navigation
feat: add Micrometer metrics module (replaces Dropwizard Metrics) - #93
Conversation
Add enkan-component-micrometer as a replacement for enkan-component-metrics. Micrometer is the industry-standard metrics facade supporting Prometheus, Datadog, CloudWatch, and other backends via pluggable MeterRegistry. New module provides: - MicrometerComponent (default SimpleMeterRegistry, accepts custom registry) - MicrometerMiddleware (request timer, active requests gauge, error counter) - MicrometerCommand + MicrometerCommandRegister (REPL /micrometer command) All classes in enkan-component-metrics are marked @deprecated(forRemoval=true) and will be removed in a future major release. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Micrometer-based metrics component/module (intended to replace the existing Dropwizard Metrics-based module) and deprecates the old metrics classes to guide migration.
Changes:
- Add new
enkan-component-micrometermodule with aMicrometerComponent,MicrometerMiddleware, and REPL/micrometercommand. - Deprecate all classes in
enkan-component-metricswith@Deprecated(forRemoval = true)and Javadoc guidance. - Add unit tests covering the new middleware and REPL command behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pom.xml |
Adds Micrometer version property and includes the new module in the reactor build. |
enkan-component-micrometer/pom.xml |
Defines the new Micrometer component module and dependencies. |
enkan-component-micrometer/src/main/java/enkan/component/micrometer/MicrometerComponent.java |
Implements Micrometer registry wrapper + timer/counter/gauge lifecycle. |
enkan-component-micrometer/src/main/java/enkan/middleware/micrometer/MicrometerMiddleware.java |
Adds HTTP/request middleware instrumentation (timer, active gauge, error counter). |
enkan-component-micrometer/src/main/java/enkan/system/command/MicrometerCommand.java |
Adds REPL command to display Micrometer metrics. |
enkan-component-micrometer/src/main/java/enkan/system/command/MicrometerCommandRegister.java |
Registers the new /micrometer command with the REPL. |
enkan-component-micrometer/src/test/java/enkan/middleware/micrometer/MicrometerMiddlewareTest.java |
Tests active requests, timer updates, and error counting. |
enkan-component-micrometer/src/test/java/enkan/system/command/MicrometerCommandTest.java |
Tests REPL output sections and “not started/registered” cases. |
enkan-component-metrics/src/main/java/enkan/component/metrics/MetricsComponent.java |
Marks Dropwizard metrics component as deprecated for removal. |
enkan-component-metrics/src/main/java/enkan/middleware/metrics/MetricsMiddleware.java |
Marks Dropwizard metrics middleware as deprecated for removal. |
enkan-component-metrics/src/main/java/enkan/system/command/MetricsCommand.java |
Marks old /metrics command as deprecated for removal. |
enkan-component-metrics/src/main/java/enkan/system/command/MetricsCommandRegister.java |
Marks old command register as deprecated for removal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public <NNREQ, NNRES> RES handle(REQ req, MiddlewareChain<REQ, RES, NNREQ, NNRES> chain) { | ||
| Timer.Sample sample = Timer.start(micrometer.getRegistry()); | ||
| micrometer.getActiveRequests().incrementAndGet(); | ||
| try { | ||
| return chain.next(req); | ||
| } catch (Exception ex) { | ||
| micrometer.getErrorCounter().increment(); | ||
| throw ex; | ||
| } finally { | ||
| sample.stop(micrometer.getRequestTimer()); | ||
| micrometer.getActiveRequests().decrementAndGet(); | ||
| } |
| public void stop(MicrometerComponent component) { | ||
| removeMeter(metricPrefix + ".http.server.requests"); | ||
| removeMeter(metricPrefix + ".http.server.errors"); | ||
| removeMeter(metricPrefix + ".http.server.active.requests"); | ||
| component.requestTimer = null; | ||
| component.errorCounter = null; | ||
| component.activeRequests.set(0); | ||
| } |
- Capture Timer/Counter/AtomicInteger as local variables in middleware before calling chain.next() to avoid NPE if component is stopped concurrently during a request. - Store registered Meter references directly and remove by reference in stop(), so prefix mutation after start() cannot leak meters. - Remove unused removeMeter helper and Meter import. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Micrometer-backed metrics component/module to Enkan (as a successor to the existing Dropwizard Metrics module), and deprecates the Dropwizard-based APIs to guide migration.
Changes:
- Introduce new
enkan-component-micrometermodule (component, middleware, REPL command + tests). - Add Micrometer version property and include the new module in the multi-module build.
- Deprecate existing
enkan-component-metrics(Dropwizard Metrics) classes with@Deprecated(forRemoval = true).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pom.xml |
Adds Micrometer version property and includes the new micrometer module in the reactor build. |
enkan-component-micrometer/pom.xml |
Defines the new module and pulls in micrometer-core plus test deps. |
enkan-component-micrometer/src/main/java/enkan/component/micrometer/MicrometerComponent.java |
Adds a SystemComponent wrapping a MeterRegistry and registering/removing Enkan meters. |
enkan-component-micrometer/src/main/java/enkan/middleware/micrometer/MicrometerMiddleware.java |
Adds middleware to track active requests, request timing, and error counts. |
enkan-component-micrometer/src/main/java/enkan/system/command/MicrometerCommand.java |
Adds /micrometer REPL command to display Micrometer metrics. |
enkan-component-micrometer/src/main/java/enkan/system/command/MicrometerCommandRegister.java |
Registers the new /micrometer REPL command. |
enkan-component-micrometer/src/test/java/enkan/middleware/micrometer/MicrometerMiddlewareTest.java |
Adds tests for active requests, timers, and error counting behavior. |
enkan-component-micrometer/src/test/java/enkan/system/command/MicrometerCommandTest.java |
Adds tests for REPL command output and component state handling. |
enkan-component-metrics/src/main/java/enkan/system/command/MetricsCommandRegister.java |
Deprecates the Dropwizard Metrics command register in favor of Micrometer. |
enkan-component-metrics/src/main/java/enkan/system/command/MetricsCommand.java |
Deprecates the Dropwizard Metrics REPL command in favor of Micrometer. |
enkan-component-metrics/src/main/java/enkan/middleware/metrics/MetricsMiddleware.java |
Deprecates the Dropwizard Metrics middleware in favor of Micrometer. |
enkan-component-metrics/src/main/java/enkan/component/metrics/MetricsComponent.java |
Deprecates the Dropwizard Metrics component in favor of Micrometer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| component.requestTimer = null; | ||
| component.errorCounter = null; | ||
| component.activeRequestsGauge = null; | ||
| component.activeRequests.set(0); |
…ht requests The gauge is already removed from the registry in stop(), so the AtomicInteger value is no longer observable. Resetting to 0 could race with in-flight requests that decrement after stop(), driving the counter negative and corrupting the next start() cycle. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
enkan-component-micrometermodule using Micrometer 1.15.0 as the metrics facadeenkan-component-metrics(Dropwizard Metrics) with@Deprecated(forRemoval = true)MeterRegistryNew module provides:
MeterRegistry(defaultSimpleMeterRegistry, accepts custom registry via constructor)/micrometercommandDesign decisions:
stop()removes only Enkan's meters (notregistry.clear()) to support shared registriesGauge.builder()used for safe re-registration on component restart (REPL dev workflow)finallyblock to handle all Throwable pathsenkan-component-metricsfor easy migrationTest plan
MicrometerMiddlewareTest— 6 tests (active requests, timer, error counter, exception paths)MicrometerCommandTest— 5 tests (output sections, not started, not registered)mvn testpasses (all modules, no regressions)kotowari-exampleto useMicrometerComponent+MicrometerMiddleware🤖 Generated with Claude Code