-
Notifications
You must be signed in to change notification settings - Fork 90
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
add jobstore metrics #4816
add jobstore metrics #4816
Conversation
WalkthroughThe pull request introduces comprehensive telemetry metrics for the BoltDB job store implementation. The changes focus on enhancing observability by adding detailed metric tracking for various database operations. A new Changes
Sequence DiagramsequenceDiagram
participant Client
participant BoltJobStore
participant MetricRecorder
participant Database
Client->>BoltJobStore: Invoke Operation (e.g., GetJob)
BoltJobStore->>MetricRecorder: Create Metric Recorder
BoltJobStore->>Database: Perform Database Operation
Database-->>BoltJobStore: Return Result
BoltJobStore->>MetricRecorder: Record Operation Metrics
BoltJobStore-->>Client: Return Result
Possibly related PRs
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pkg/jobstore/boltdb/store.go
(42 hunks)pkg/jobstore/metrics.go
(1 hunks)
🔇 Additional comments (9)
pkg/jobstore/metrics.go (1)
1-117
: Telemetry metrics are properly defined and initializedThe metrics are correctly set up using OpenTelemetry conventions. The units, descriptions, and bucket boundaries are appropriately specified for each metric.
pkg/jobstore/boltdb/store.go (8)
164-177
: Well-implementedmetricRecorder
methodThe
metricRecorder
function is effectively designed to initialize metric recorders with the correct attributes, enhancing observability for database operations.
191-196
: Enhanced observability inGetJob
methodThe integration of telemetry metrics into the
GetJob
method effectively improves observability, allowing for detailed monitoring of job retrieval operations.
Line range hint
258-277
: Proper metric recording ingetExecution
functionThe additions of metric recordings, such as latency measurements and data counters, in the
getExecution
function are correctly implemented to monitor execution retrieval performance.
355-364
: Efficient metric logging within loopsMetrics within loops, like in the execution fetching loop, are correctly placed to account for each iteration, ensuring accurate data aggregation.
660-666
: Consistent attribute usage in telemetryThe attributes added to the metric recorder in
GetExecutions
are consistent and provide valuable context for the operations being monitored.
919-928
: Validation and normalization inCreateJob
The job creation process includes necessary validation and normalization steps before storing the job, adhering to best practices.
1002-1007
: Correct handling of job deletion inDeleteJob
The
DeleteJob
method appropriately records metrics and handles the deletion process, including index updates.
1061-1065
: Accurate state transition metrics inUpdateJobState
Metrics capturing the state transitions in
UpdateJobState
provide detailed insights into job state changes, enhancing observability.
defer recorder.Latency(ctx, jobstore.OperationPartDuration, jobstore.AttrOperationPartReifyID) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using defer
with recorder.Latency
; measure latency explicitly
Using defer
with recorder.Latency
may not accurately measure the latency of specific operation segments because defer
delays execution until the surrounding function returns. This can result in capturing the total execution time of the function rather than the intended code block, leading to misleading metrics.
Apply the following changes to measure latency explicitly:
// In reifyJobID function (lines 229-230)
- defer recorder.Latency(ctx, jobstore.OperationPartDuration, jobstore.AttrOperationPartReifyID)
+ startTime := time.Now()
// ... code for reifyJobID ...
+ recorder.Latency(ctx, jobstore.OperationPartDuration, jobstore.AttrOperationPartReifyID, time.Since(startTime))
// In getJobsIncludeTags function (line 537)
- defer recorder.Latency(ctx, jobstore.OperationPartDuration, "filter_include_tags")
+ startTime := time.Now()
// ... code for getJobsIncludeTags ...
+ recorder.Latency(ctx, jobstore.OperationPartDuration, "filter_include_tags", time.Since(startTime))
// In getJobsExcludeTags function (line 567)
- defer recorder.Latency(ctx, jobstore.OperationPartDuration, "filter_exclude_tags")
+ startTime := time.Now()
// ... code for getJobsExcludeTags ...
+ recorder.Latency(ctx, jobstore.OperationPartDuration, "filter_exclude_tags", time.Since(startTime))
// In getJobsBuildList function (lines 587-588)
- defer recorder.Latency(ctx, jobstore.OperationPartDuration, "build_list")
+ startTime := time.Now()
// ... code for getJobsBuildList ...
+ recorder.Latency(ctx, jobstore.OperationPartDuration, "build_list", time.Since(startTime))
// In getJobHistory function (line 828)
- defer recorder.Latency(ctx, jobstore.OperationPartDuration, "determine_pagination")
+ startTime := time.Now()
// ... code for pagination determination ...
+ recorder.Latency(ctx, jobstore.OperationPartDuration, "determine_pagination", time.Since(startTime))
Also applies to: 537-537, 567-567, 587-588, 828-828
Summary by CodeRabbit
New Features
Improvements
Performance