Skip to content

Fix native-image StatsD publishing and logback metrics#1148

Open
n0tl3ss wants to merge 4 commits into
6.1.xfrom
fix-native-image-statsd-logback-1062
Open

Fix native-image StatsD publishing and logback metrics#1148
n0tl3ss wants to merge 4 commits into
6.1.xfrom
fix-native-image-statsd-logback-1062

Conversation

@n0tl3ss

@n0tl3ss n0tl3ss commented Apr 24, 2026

Copy link
Copy Markdown
Member

Summary

  • add a native-image-specific StatsD UDP line sink and shaded Netty native-image metadata so StatsD publishing keeps working in GraalVM native images
  • switch the logback binder to an async-safe implementation that avoids recursive counter updates when logging happens during metric emission
  • address review feedback for UTF-8 packet sizing, native-image runtime matching, UDP sender reuse, scheduler startup guards, and repeated logback binding

Testing

  • ./gradlew :micronaut-micrometer-core:test --tests 'io.micronaut.configuration.metrics.binder.logging.LogbackMeterRegistryBinderFactorySpec'
  • ./gradlew :micronaut-micrometer-registry-statsd:test --tests 'io.micronaut.configuration.metrics.micrometer.statsd.NativeImageUdpStatsdLineSinkSpec'
  • ./gradlew spotlessCheck
  • ./gradlew --no-daemon -Dorg.gradle.workers.max=1 :micronaut-micrometer-core:test
  • ./gradlew :micronaut-micrometer-registry-statsd:test

Resolves #1062

@n0tl3ss n0tl3ss added the type: bug Something isn't working label Apr 24, 2026
@n0tl3ss n0tl3ss self-assigned this Apr 24, 2026
Co-Authored-By: Codex with GPT-5 <codex@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses GraalVM native-image reliability issues for StatsD publishing and fixes a logback metrics recursion risk by introducing a native-image-specific UDP line sink plus an async-safe LogbackMetrics implementation.

Changes:

  • Add a native-image UDP StatsD line sink and GraalVM native-image metadata/reflection hints for shaded Netty classes.
  • Switch the LogbackMetrics binder to an async-safe implementation using LongAdder + FunctionCounter via a TurboFilter.
  • Add regression tests covering native-image StatsD behavior and the logback recursion scenario.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/StatsdMeterRegistryFactory.java Uses the native-image UDP sink when available; registers native-image reflection hints.
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/NativeImageUdpStatsdLineSink.java New native-image-friendly UDP sender with buffering/flush scheduling.
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/NativeImageStatsdCondition.java Enables the workaround only for native-image + UDP protocol.
micrometer-registry-statsd/src/main/resources/META-INF/native-image/io.micronaut.micrometer/micronaut-micrometer-registry-statsd/native-image.properties Adds native-image runtime init args for shaded Netty classes.
micrometer-registry-statsd/src/test/groovy/.../StatsdNativeImageMetadataSpec.groovy Verifies shaded native-image properties and reflection hints are present.
micrometer-registry-statsd/src/test/groovy/.../NativeImageUdpStatsdLineSinkSpec.groovy Tests bean condition + UDP send behavior for the new sink.
micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/logging/MicronautLogbackMetrics.java New async-safe LogbackMetrics variant using TurboFilter + LongAdder.
micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/logging/LogbackMeterRegistryBinderFactory.java Switches binder to return MicronautLogbackMetrics.
micrometer-core/src/test/groovy/.../LogbackMeterRegistryBinderFactorySpec.groovy Regression test guarding against counter/log recursion.

Co-Authored-By: Codex with GPT-5 <codex@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses StatsD metric publishing failures in GraalVM native images by introducing a native-image-specific UDP line sink and adding native-image metadata for shaded Netty, and it hardens the Logback metrics binder against recursion when logging occurs during metric emission.

Changes:

  • Add a native-image-only StatsD UDP lineSink implementation and wire it into the StatsD registry factory when running as a native executable.
  • Package GraalVM native-image metadata and add reflection hints for shaded Netty/JCTools classes used by the StatsD registry in native images.
  • Replace the default Logback binder with an async-safe implementation and add regression tests for both the native-image StatsD path and the logback recursion scenario.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
micrometer-registry-statsd/src/test/groovy/io/micronaut/configuration/metrics/micrometer/statsd/StatsdNativeImageMetadataSpec.groovy Adds regression coverage for packaged native-image properties and reflection hints.
micrometer-registry-statsd/src/test/groovy/io/micronaut/configuration/metrics/micrometer/statsd/NativeImageUdpStatsdLineSinkSpec.groovy Adds tests for sink bean conditions, UDP send behavior, and concurrency characteristics.
micrometer-registry-statsd/src/main/resources/META-INF/native-image/io.micronaut.micrometer/micronaut-micrometer-registry-statsd/native-image.properties Adds GraalVM runtime-initialization metadata for shaded Netty used by StatsD in native images.
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/StatsdMeterRegistryFactory.java Wires the optional native-image UDP sink into StatsD registry creation; adds TypeHint for shaded dependencies.
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/NativeImageUdpStatsdLineSink.java Introduces the native-image-friendly UDP line sink with buffering and scheduled flush.
micrometer-registry-statsd/src/main/java/io/micronaut/configuration/metrics/micrometer/statsd/NativeImageStatsdCondition.java Adds a condition to activate the workaround only under native-image + UDP.
micrometer-core/src/test/groovy/io/micronaut/configuration/metrics/binder/logging/LogbackMeterRegistryBinderFactorySpec.groovy Adds regression tests for logback recursion avoidance and proper cleanup.
micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/logging/MicronautLogbackMetrics.java Adds an async-safe Logback metrics binder using LongAdder + FunctionCounter.
micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/logging/LogbackMeterRegistryBinderFactory.java Switches the produced binder from Micrometer’s LogbackMetrics to MicronautLogbackMetrics.

Co-Authored-By: Codex with GPT-5 <codex@openai.com>
@sonarqubecloud

Copy link
Copy Markdown

@n0tl3ss
n0tl3ss requested a review from sdelamo April 27, 2026 23:29
@github-project-automation github-project-automation Bot moved this to Backlog in 5.0.1 Release May 8, 2026
@sdelamo sdelamo removed this from 5.0.1 Release Jun 2, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in 5.0.2 Release Jun 2, 2026
@sdelamo sdelamo removed this from 5.0.2 Release Jun 3, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in 5.0.3 Release Jun 3, 2026
@sdelamo
sdelamo changed the base branch from 6.0.x to 6.1.x June 9, 2026 15:55
@sdelamo sdelamo removed this from 5.0.3 Release Jun 9, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in 5.1.0 Release Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Micrometer StatsD not pushing custom metrics to datadog when run with GraalVM native-image

3 participants