-
-
Notifications
You must be signed in to change notification settings - Fork 6
chore: Add partition aware depth count metric #650
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
enochtangg
wants to merge
3
commits into
main
Choose a base branch
from
partition-aware-depth-count-metric
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.
+192
−11
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| use std::collections::HashSet; | ||
| use std::sync::Arc; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
|
|
@@ -45,6 +46,7 @@ pub async fn upkeep( | |
| let mut last_run = Instant::now(); | ||
| let mut last_vacuum = Instant::now(); | ||
| let mut last_backtrace_log = Instant::now(); | ||
| let mut emitted_partitions: HashSet<i32> = HashSet::new(); | ||
| loop { | ||
| select! { | ||
| _ = timer.tick() => { | ||
|
|
@@ -55,6 +57,7 @@ pub async fn upkeep( | |
| startup_time, | ||
| runtime_config_manager.clone(), | ||
| &mut last_vacuum, | ||
| &mut emitted_partitions, | ||
| ).await; | ||
| last_run = check_health(last_run, &config, health_reporter.clone()).await; | ||
|
|
||
|
|
@@ -126,6 +129,7 @@ pub async fn do_upkeep( | |
| startup_time: DateTime<Utc>, | ||
| runtime_config_manager: Arc<RuntimeConfigManager>, | ||
| last_vacuum: &mut Instant, | ||
| emitted_partitions: &mut HashSet<i32>, | ||
| ) -> UpkeepResults { | ||
| let current_time = Utc::now(); | ||
| let upkeep_start = Instant::now(); | ||
|
|
@@ -403,17 +407,20 @@ pub async fn do_upkeep( | |
|
|
||
| let now = Utc::now(); | ||
| let (depth_counts, max_lag, db_file_meta, wal_file_meta) = join!( | ||
| store.count_depths(), | ||
| store.count_depths_per_partition(), | ||
| store.pending_activation_max_lag(&now), | ||
| fs::metadata(config.db_path.clone()), | ||
| fs::metadata(config.db_path.clone() + "-wal") | ||
| ); | ||
|
|
||
| if let Ok(depths) = depth_counts { | ||
| result_context.pending = depths.pending as u32; | ||
| result_context.delay = depths.delay as u32; | ||
| result_context.claimed = depths.claimed as u32; | ||
| result_context.processing = depths.processing as u32; | ||
| let depths_per_partition = depth_counts.ok(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need an |
||
| if let Some(ref depths) = depths_per_partition { | ||
| for counts in depths.values() { | ||
| result_context.pending += counts.pending as u32; | ||
| result_context.delay += counts.delay as u32; | ||
| result_context.claimed += counts.claimed as u32; | ||
| result_context.processing += counts.processing as u32; | ||
| } | ||
| } | ||
|
|
||
| if !result_context.empty() { | ||
|
|
@@ -464,11 +471,37 @@ pub async fn do_upkeep( | |
| // Forwarded tasks | ||
| metrics::counter!("upkeep.forwarded_tasks").increment(result_context.forwarded); | ||
|
|
||
| // State of activations | ||
| metrics::gauge!("upkeep.current_pending_tasks").set(result_context.pending); | ||
| metrics::gauge!("upkeep.current_claimed_tasks").set(result_context.claimed); | ||
| metrics::gauge!("upkeep.current_processing_tasks").set(result_context.processing); | ||
| metrics::gauge!("upkeep.current_delayed_tasks").set(result_context.delay); | ||
| // State of activations, tagged per partition. Dashboards aggregating | ||
| // without a partition filter still see the global total via tag sum. | ||
| // Zero out gauges for partitions we emitted last cycle but no longer own. | ||
| if let Some(depths) = depths_per_partition { | ||
| let current: HashSet<i32> = depths.keys().copied().collect(); | ||
|
|
||
| for partition in emitted_partitions.difference(¤t) { | ||
| let partition = partition.to_string(); | ||
| metrics::gauge!("upkeep.current_pending_tasks", "partition" => partition.clone()) | ||
| .set(0.0); | ||
| metrics::gauge!("upkeep.current_claimed_tasks", "partition" => partition.clone()) | ||
| .set(0.0); | ||
| metrics::gauge!("upkeep.current_processing_tasks", "partition" => partition.clone()) | ||
| .set(0.0); | ||
| metrics::gauge!("upkeep.current_delayed_tasks", "partition" => partition).set(0.0); | ||
| } | ||
|
|
||
| for (partition, counts) in &depths { | ||
| let partition = partition.to_string(); | ||
| metrics::gauge!("upkeep.current_pending_tasks", "partition" => partition.clone()) | ||
| .set(counts.pending as f64); | ||
| metrics::gauge!("upkeep.current_claimed_tasks", "partition" => partition.clone()) | ||
| .set(counts.claimed as f64); | ||
| metrics::gauge!("upkeep.current_processing_tasks", "partition" => partition.clone()) | ||
| .set(counts.processing as f64); | ||
| metrics::gauge!("upkeep.current_delayed_tasks", "partition" => partition) | ||
| .set(counts.delay as f64); | ||
| } | ||
|
|
||
| *emitted_partitions = current; | ||
| } | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| metrics::gauge!("upkeep.pending_activation.max_lag.sec").set(max_lag); | ||
|
|
||
| if let Ok(db_file_meta) = db_file_meta { | ||
|
|
@@ -540,6 +573,7 @@ pub async fn check_health( | |
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::collections::HashSet; | ||
| use std::io::Write; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
@@ -701,6 +735,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -761,6 +796,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -812,6 +848,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -871,6 +908,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -924,6 +962,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -970,6 +1009,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1032,6 +1072,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1078,6 +1119,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1128,6 +1170,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1210,6 +1253,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
| assert_eq!(result_context.delay_elapsed, 1); | ||
|
|
@@ -1242,6 +1286,7 @@ mod tests { | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
| assert_eq!(result_context.delay_elapsed, 1); | ||
|
|
@@ -1298,6 +1343,7 @@ demoted_namespaces: | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1359,6 +1405,7 @@ demoted_namespaces: | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
@@ -1399,6 +1446,7 @@ demoted_namespaces: | |
| start_time, | ||
| runtime_config.clone(), | ||
| &mut last_vacuum, | ||
| &mut HashSet::new(), | ||
| ) | ||
| .await; | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.