Skip to content

Commit

Permalink
Add summary of platform properties to prometheus (#367)
Browse files Browse the repository at this point in the history
This will make it easier for people to create auto-scaling
policies based on prometheus data.
  • Loading branch information
allada committed Nov 2, 2023
1 parent cf2f3e4 commit d9af3b9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cas/scheduler/simple_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use error::{error_if, make_err, make_input_err, Code, Error, ResultExt};
use metrics_utils::{
AsyncCounterWrapper, Collector, CollectorState, CounterWithTime, FuncCounterWrapper, MetricsComponent, Registry,
};
use platform_property_manager::PlatformPropertyManager;
use platform_property_manager::{PlatformPropertyManager, PlatformPropertyValue};
use scheduler::{ActionScheduler, WorkerScheduler};
use worker::{Worker, WorkerId, WorkerTimestamp, WorkerUpdate};

Expand Down Expand Up @@ -297,7 +297,7 @@ impl SimpleSchedulerImpl {
}

fn find_recently_completed_action(
&mut self,
&self,
unique_qualifier: &ActionInfoHashKey,
) -> Option<watch::Receiver<Arc<ActionState>>> {
self.recently_completed_actions
Expand Down Expand Up @@ -713,7 +713,7 @@ impl ActionScheduler for SimpleScheduler {
&self,
unique_qualifier: &ActionInfoHashKey,
) -> Option<watch::Receiver<Arc<ActionState>>> {
let mut inner = self.get_inner_lock();
let inner = self.get_inner_lock();
let result = inner
.find_existing_action(unique_qualifier)
.or_else(|| inner.find_recently_completed_action(unique_qualifier));
Expand Down Expand Up @@ -876,13 +876,27 @@ impl MetricsComponent for SimpleScheduler {
&inner.max_job_retries,
"The amount of times a job is allowed to retry from an internal error before it is dropped.",
);
let mut props = HashMap::<&String, u64>::new();
for (_worker_id, worker) in inner.workers.workers.iter() {
c.publish_with_labels(
"workers",
worker,
"",
vec![("worker_id".into(), worker.id.to_string().into())],
);
for (property, prop_value) in &worker.platform_properties.properties {
let current_value = props.get(&property).unwrap_or(&0);
if let PlatformPropertyValue::Minimum(worker_value) = prop_value {
props.insert(property, *current_value + *worker_value);
}
}
}
for (property, prop_value) in props {
c.publish(
&format!("{property}_available_properties"),
&prop_value,
format!("Total sum of available properties for {property}"),
);
}
for (_, active_action) in inner.active_actions.iter() {
let action_name = active_action.action.action_info.unique_qualifier.action_name().into();
Expand Down

0 comments on commit d9af3b9

Please sign in to comment.