Skip to content

Commit 5ae7d49

Browse files
from<ActionStage> trait
1 parent 8c9fc22 commit 5ae7d49

File tree

2 files changed

+24
-48
lines changed

2 files changed

+24
-48
lines changed

nativelink-scheduler/src/memory_awaited_action_db.rs

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -647,57 +647,17 @@ impl<I: InstantWrapper, NowFn: Fn() -> I + Clone + Send + Sync> AwaitedActionDbI
647647
metrics.execution_stage_transitions.add(1, &base_attrs);
648648

649649
// Update active count for old stage
650-
let old_stage_attrs = match old_stage {
651-
ActionStage::Unknown => vec![opentelemetry::KeyValue::new(
652-
nativelink_util::metrics::EXECUTION_STAGE,
653-
ExecutionStage::Unknown,
654-
)],
655-
ActionStage::CacheCheck => vec![opentelemetry::KeyValue::new(
656-
nativelink_util::metrics::EXECUTION_STAGE,
657-
ExecutionStage::CacheCheck,
658-
)],
659-
ActionStage::Queued => vec![opentelemetry::KeyValue::new(
660-
nativelink_util::metrics::EXECUTION_STAGE,
661-
ExecutionStage::Queued,
662-
)],
663-
ActionStage::Executing => vec![opentelemetry::KeyValue::new(
664-
nativelink_util::metrics::EXECUTION_STAGE,
665-
ExecutionStage::Executing,
666-
)],
667-
ActionStage::Completed(_) | ActionStage::CompletedFromCache(_) => {
668-
vec![opentelemetry::KeyValue::new(
669-
nativelink_util::metrics::EXECUTION_STAGE,
670-
ExecutionStage::Completed,
671-
)]
672-
}
673-
};
650+
let old_stage_attrs = vec![opentelemetry::KeyValue::new(
651+
nativelink_util::metrics::EXECUTION_STAGE,
652+
ExecutionStage::from(old_stage.clone()),
653+
)];
674654
metrics.execution_active_count.add(-1, &old_stage_attrs);
675655

676656
// Update active count for new stage
677-
let new_stage_attrs = match new_stage {
678-
ActionStage::Unknown => vec![opentelemetry::KeyValue::new(
679-
nativelink_util::metrics::EXECUTION_STAGE,
680-
ExecutionStage::Unknown,
681-
)],
682-
ActionStage::CacheCheck => vec![opentelemetry::KeyValue::new(
683-
nativelink_util::metrics::EXECUTION_STAGE,
684-
ExecutionStage::CacheCheck,
685-
)],
686-
ActionStage::Queued => vec![opentelemetry::KeyValue::new(
687-
nativelink_util::metrics::EXECUTION_STAGE,
688-
ExecutionStage::Queued,
689-
)],
690-
ActionStage::Executing => vec![opentelemetry::KeyValue::new(
691-
nativelink_util::metrics::EXECUTION_STAGE,
692-
ExecutionStage::Executing,
693-
)],
694-
ActionStage::Completed(_) | ActionStage::CompletedFromCache(_) => {
695-
vec![opentelemetry::KeyValue::new(
696-
nativelink_util::metrics::EXECUTION_STAGE,
697-
ExecutionStage::Completed,
698-
)]
699-
}
700-
};
657+
let new_stage_attrs = vec![opentelemetry::KeyValue::new(
658+
nativelink_util::metrics::EXECUTION_STAGE,
659+
ExecutionStage::from(new_stage.clone()),
660+
)];
701661
metrics.execution_active_count.add(1, &new_stage_attrs);
702662

703663
// Record completion metrics

nativelink-util/src/metrics.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::sync::LazyLock;
1616

1717
use opentelemetry::{InstrumentationScope, KeyValue, Value, global, metrics};
1818

19+
use crate::action_messages::ActionStage;
20+
1921
// Metric attribute keys for cache operations.
2022
pub const CACHE_TYPE: &str = "cache.type";
2123
pub const CACHE_OPERATION: &str = "cache.operation.name";
@@ -111,6 +113,20 @@ impl From<ExecutionStage> for Value {
111113
}
112114
}
113115

116+
impl From<ActionStage> for ExecutionStage {
117+
fn from(stage: ActionStage) -> Self {
118+
match stage {
119+
ActionStage::Unknown => ExecutionStage::Unknown,
120+
ActionStage::CacheCheck => ExecutionStage::CacheCheck,
121+
ActionStage::Queued => ExecutionStage::Queued,
122+
ActionStage::Executing => ExecutionStage::Executing,
123+
ActionStage::Completed(_) | ActionStage::CompletedFromCache(_) => {
124+
ExecutionStage::Completed
125+
}
126+
}
127+
}
128+
}
129+
114130
/// Results of remote execution operations.
115131
#[derive(Debug, Clone, Copy)]
116132
pub enum ExecutionResult {

0 commit comments

Comments
 (0)