-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: Add comprehensive Prometheus metrics support #6202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rossigee
wants to merge
7
commits into
dani-garcia:main
Choose a base branch
from
rossigee:feature/prometheus-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements optional Prometheus metrics collection with secure endpoint for monitoring and observability. Features: - Disabled by default, enabled via ENABLE_METRICS environment variable - Secure token-based authentication with Argon2 hashing support - Comprehensive metrics collection across all system components - Conditional compilation with enable_metrics feature flag - HTTP request instrumentation with automatic path normalization - Database connection pool and query performance monitoring - Authentication attempt tracking and session management - Business metrics for users, organizations, and vault items - System uptime and build information tracking Security: - Token authentication required (METRICS_TOKEN configuration) - Support for both plain text and Argon2 hashed tokens - Path normalization prevents high cardinality metric explosion - No-op implementations when metrics disabled for zero overhead - Network access controls recommended for production deployment Implementation: - Added prometheus dependency with conditional compilation - Created secure /metrics endpoint with request guard authentication - Implemented HTTP middleware fairing for automatic instrumentation - Added database metrics utilities with timing macros - Comprehensive unit and integration test coverage - Complete documentation with Prometheus, Grafana, and alerting examples Files added: - src/metrics.rs - Core metrics collection module - src/api/metrics.rs - Secure metrics endpoint implementation - src/api/middleware.rs - HTTP request instrumentation - src/db/metrics.rs - Database timing utilities - METRICS.md - Configuration and usage guide - MONITORING.md - Complete monitoring setup documentation - examples/metrics-config.env - Configuration examples - scripts/test-metrics.sh - Automated testing script - Comprehensive test suites for both enabled/disabled scenarios This implementation follows security best practices with disabled-by-default configuration and provides production-ready monitoring capabilities for Vaultwarden deployments.
- Fix Rocket response type issues in metrics endpoint - Correct middleware request timer handling - Resolve borrow checker issues with UUID string conversion - Add proper EXTRA_FEATURES support to Dockerfile for optional features - Suppress unused code warnings in proof-of-concept metrics implementation - Update Cargo.lock with resolved dependencies These fixes enable successful compilation of the metrics feature and production-ready Docker image building with: docker build --build-arg EXTRA_FEATURES="enable_metrics" The metrics-enabled image has been successfully built and tested.
You sort of beat me to it. I was thinking of adding OTel: also metrics, but mostly traces. Even though the vw service is not highly distributed (maybe a db backend on a different machine), traces are still useful just to verify where exactly the time is spent. Also helps a lot with debugging. I despise logs unless they are audit logs. ;-) Great job adding the Prometheus metrics! |
fix(config): also correct typo in config.rs
…e/vaultwarden into feature/prometheus-metrics
The DbConn type was missing an import for the non-feature version of update_business_metrics function, causing compilation failure during Docker build.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive Prometheus metrics support to Vaultwarden, providing observability into application performance, database health, authentication patterns, and business metrics.
Key Features
/metrics
(disabled by default)--features enable_metrics
Metrics Categories
Security Considerations
ENABLE_METRICS=true
Documentation
METRICS.md
MONITORING.md
Test Plan
Breaking Changes
None - this is an optional feature that's disabled by default.
Files Added/Modified
src/api/metrics.rs
- Metrics endpoint implementationMETRICS.md
- Configuration and usage guideMONITORING.md
- Complete monitoring setup guideexamples/metrics-config.env
- Configuration examplesscripts/test-metrics.sh
- Testing scriptCargo.toml
- Added optional prometheus dependencyREADME.md
- Added metrics feature documentationdocker/Dockerfile.debian
- Support for extra features in build