Skip to content

Conversation

@hungrytech
Copy link
Contributor

@hungrytech hungrytech commented Mar 15, 2025

Subsystem
Micrometor metrics

Motivation
KTOR-8276

Solution
Changed the default value of distinctNotRegisteredRoutes to false.

Since a test already exists for no handler results in status 404, no route, and no exception if distinctNotRegisteredRoutes is false no additional tests were written.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2025

Walkthrough

The changes adjust how unregistered routes are reported in metrics. In the configuration class, the default value of distinctNotRegisteredRoutes is switched from true to false, so requests to unknown routes now report as "n/a" instead of including the actual requested path. The corresponding test is updated to assert this new behavior.

Changes

File(s) Change Summary
ktor-server/.../MicrometerMetrics.kt and ktor-server/.../MicrometerMetricsTests.kt Updated distinctNotRegisteredRoutes default from true to false in MicrometerMetricsConfig, and modified tests to expect "n/a" for unregistered routes.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4323416 and c6824e6.

📒 Files selected for processing (2)
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/src/io/ktor/server/metrics/micrometer/MicrometerMetrics.kt (1 hunks)
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/test/io/ktor/server/metrics/micrometer/MicrometerMetricsTests.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/src/io/ktor/server/metrics/micrometer/MicrometerMetrics.kt
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/test/io/ktor/server/metrics/micrometer/MicrometerMetricsTests.kt

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
docker-compose.yml (2)

32-74: Consider extracting setup script to a separate file

The bash script used in the setup service is quite long and complex. For better maintainability, consider extracting it to a separate shell script file and mounting it into the container.

This would make the docker-compose file cleaner and the setup script easier to maintain and modify.


27-27: Use specific version tags instead of environment variables

The docker-compose file uses ${STACK_VERSION} for all Elastic Stack component versions. While this allows for consistent versioning, it requires setting this environment variable before running the compose file.

Consider providing a default version in the docker-compose file itself or including a .env.example file to document required environment variables.

Also applies to: 84-84, 127-127, 161-161, 181-181, 202-202

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31bfd9d and 4323416.

📒 Files selected for processing (3)
  • docker-compose.yml (1 hunks)
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/src/io/ktor/server/metrics/micrometer/MicrometerMetrics.kt (1 hunks)
  • ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/test/io/ktor/server/metrics/micrometer/MicrometerMetricsTests.kt (1 hunks)
🔇 Additional comments (4)
ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/src/io/ktor/server/metrics/micrometer/MicrometerMetrics.kt (1)

69-69: Default for distinctNotRegisteredRoutes changed to false

The default value of distinctNotRegisteredRoutes has been changed from true to false, and the documentation has been updated to reflect this change. This means that unregistered routes will now be reported with a common "n/a" value in metrics instead of their actual request paths.

This change helps prevent metric cardinality explosion when applications receive many different unregistered route requests, which could potentially overwhelm monitoring systems.

Also applies to: 75-75

ktor-server/ktor-server-plugins/ktor-server-metrics-micrometer/jvm/test/io/ktor/server/metrics/micrometer/MicrometerMetricsTests.kt (1)

247-247: Test assertion updated to match new default behavior

The test assertion has been updated to expect "n/a" instead of the actual URI for unregistered routes, which aligns with the new default value of distinctNotRegisteredRoutes = false in the configuration.

This change ensures that the test correctly verifies the new default behavior where unregistered routes are labeled as "n/a" in metrics.

docker-compose.yml (2)

1-216: New Elastic Stack deployment configuration

A comprehensive docker-compose.yml file has been added to set up an Elastic Stack environment, which can be useful for monitoring the metrics generated by the Ktor application. The setup includes:

  • Elasticsearch for storing metrics data
  • Kibana for visualization
  • Metricbeat and Filebeat for collecting metrics and logs
  • Logstash for processing logs

The configuration includes proper security settings with SSL certificates and authentication, along with health checks to ensure services start in the correct order.

While this file is not directly related to the bug fix in the Micrometer metrics plugin, it provides a valuable infrastructure component for monitoring and analyzing metrics in a real environment.


167-170: Verify volume mounts permissions in host environment

The configuration includes several volume mounts that access sensitive system directories like /var/run/docker.sock, /sys/fs/cgroup, and /proc. Ensure that these mounts are necessary and that appropriate permissions are set in the host environment.

Mounting the Docker socket can be a security risk as it potentially gives containers root-equivalent access to the host. Consider restricting these permissions if possible.

Also applies to: 186-189

@hungrytech hungrytech force-pushed the KTOR-8276.micrometer-metrics-bug branch from 4323416 to c6824e6 Compare March 15, 2025 00:48
@hungrytech
Copy link
Contributor Author

@bjhham
Thank you for your review.

@bjhham bjhham enabled auto-merge (squash) April 4, 2025 07:47
@bjhham bjhham merged commit 871a76c into ktorio:main Apr 16, 2025
15 of 16 checks passed
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