8000 feat: add Micrometer metrics module (replaces Dropwizard Metrics) by kawasima · Pull Request #93 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

feat: add Micrometer metrics module (replaces Dropwizard Metrics) - #93

Merged
kawasima merged 3 commits into
developfrom
feature/micrometer-integration
Mar 19, 2026
Merged

kawasima merged 3 commits into
developfrom
feature/micrometer-integration

Conversation

@kawasima
Copy link
Copy Markdown
Collaborator

Summary

  • Add new enkan-component-micrometer module using Micrometer 1.15.0 as the metrics facade
  • Deprecate all classes in enkan-component-metrics (Dropwizard Metrics) with @Deprecated(forRemoval = true)
  • Micrometer supports Prometheus, Datadog, CloudWatch, etc. via pluggable MeterRegistry

New module provides:

  • MicrometerComponent — wraps MeterRegistry (default SimpleMeterRegistry, accepts custom registry via constructor)
  • MicrometerMiddleware — request timer, active requests gauge, error counter
  • MicrometerCommand + MicrometerCommandRegister — REPL /micrometer command

Design decisions:

  • stop() removes only Enkan's meters (not registry.clear()) to support shared registries
  • Gauge.builder() used for safe re-registration on component restart (REPL dev workflow)
  • Timer stop in finally block to handle all Throwable paths
  • Follows same structure as existing enkan-component-metrics for easy migration

Test plan

  • MicrometerMiddlewareTest — 6 tests (active requests, timer, error counter, exception paths)
  • MicrometerCommandTest — 5 tests (output sections, not started, not registered)
  • Full mvn test passes (all modules, no regressions)
  • Optional: update kotowari-example to use MicrometerComponent + MicrometerMiddleware

🤖 Generated with Claude Code

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>
@kawasima
kawasima requested a review from Copilot March 19, 2026 03:12
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-micrometer module with a MicrometerComponent, MicrometerMiddleware, and REPL /micrometer command.
  • Deprecate all classes in enkan-component-metrics with @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.

Comment on lines +23 to +34
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();
}
Comment on lines +59 to +66
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>
@kawasima
kawasima requested a review from Copilot March 19, 2026 03:21
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-micrometer module (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>
@kawasima
kawasima merged commit 0c029d5 into develop Mar 19, 2026
@kawasima
kawasima deleted the feature/micrometer-integration branch March 19, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0