api: add database query performance profiling - #1559
Draft
Himavarshit18 wants to merge 1 commit into
Draft
Conversation
Implements query performance profiling wrapper for Nebraska's database layer to enable identification of slow queries, performance bottlenecks, and optimization opportunities. Features: - QueryProfiler wrapper for sqlx.DB with execution time tracking - Slow query detection with configurable threshold (default: 100ms) - Prometheus metrics: duration histogram, slow query counter, error counter - Structured logging for slow queries with query type and duration - Runtime configuration for threshold updates - Database connection pool statistics logging Metrics exported: - nebraska_db_query_duration_seconds - histogram by query type - nebraska_db_slow_queries_total - counter by query type - nebraska_db_query_errors_total - counter by query type Testing: - 14 comprehensive unit tests covering all functionality - Tests for query execution, slow query detection, error handling - Tests for metrics registration and threshold configuration - All tests passing with sqlmock for isolated testing Documentation: - Complete usage guide with configuration examples - Prometheus metrics reference with PromQL queries - Grafana dashboard and alerting examples - Performance impact analysis and best practices Enables production debugging of query performance, proactive monitoring of database operations, and data-driven optimization decisions for Nebraska operators. Signed-off-by: Himavarshit18 <himavarshitreddyk@gmail.com>
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
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.
Fixes #1558
Implements query performance profiling for Nebraska's database layer to enable identification of slow queries and performance bottlenecks through Prometheus metrics and structured logging.
Changes
Added three files implementing query performance profiling:
backend/pkg/api/query_profiler.gobackend/pkg/api/query_profiler_test.gobackend/pkg/api/QUERY_PROFILING.mdTesting
Real Testing Results
Tested with actual database operations. Query profiler successfully detected slow queries and collected metrics:
Sample queries tested:
Real log output:
Unit Tests
All unit tests passing (100%):
Build Verification
Configuration
Opt-in via environment variables:
Runtime configuration also supported via API.
Metrics
Three Prometheus metrics exported:
Example PromQL queries:
Performance Impact
Minimal overhead:
Benefits
Compatibility
Checklist
QUERY_PROFILING.md)