use super::{ManifestLoadStage, expand::ExpansionReport};
use metrics::{counter, describe_counter};
use std::sync::Once;
const FILTERED_TARGETS_TOTAL: &str = "netsuke_manifest_filtered_targets_total";
const FILTERED_ACTIONS_TOTAL: &str = "netsuke_manifest_filtered_actions_total";
const OMITTED_FILTERED_ENTRIES_TOTAL: &str = "netsuke_manifest_omitted_filtered_entries_total";
fn describe_expansion_metrics() {
static DESCRIBE: Once = Once::new();
DESCRIBE.call_once(|| {
describe_counter!(
FILTERED_TARGETS_TOTAL,
"Counts filtered target entries from normal manifest loading; no labels."
);
describe_counter!(
FILTERED_ACTIONS_TOTAL,
"Counts filtered action entries from normal manifest loading; no labels."
);
describe_counter!(
OMITTED_FILTERED_ENTRIES_TOTAL,
"Counts filtered entries omitted from normal manifest-loading reports; no labels."
);
});
}
pub(super) fn trace_expansion_report(report: &ExpansionReport) {
describe_expansion_metrics();
counter!(FILTERED_TARGETS_TOTAL)
.increment(u64::try_from(report.stats.filtered_targets).unwrap_or(u64::MAX));
counter!(FILTERED_ACTIONS_TOTAL)
.increment(u64::try_from(report.stats.filtered_actions).unwrap_or(u64::MAX));
counter!(OMITTED_FILTERED_ENTRIES_TOTAL)
.increment(u64::try_from(report.omitted_filtered_entries).unwrap_or(u64::MAX));
for entry in &report.filtered_entries {
tracing::debug!(
section = entry.section.as_str(),
entry_name_hash = entry.entry_name_hash.as_str(),
iteration_index = entry.iteration_index,
when_expression_len = entry.when_expression_len,
when_result = false,
"filtered manifest entry by when expression"
);
}
tracing::debug!(
filtered_targets = report.stats.filtered_targets,
filtered_actions = report.stats.filtered_actions,
filtered_entry_count = report.stats.filtered_targets + report.stats.filtered_actions,
omitted_filtered_entries = report.omitted_filtered_entries,
"expanded manifest foreach and when directives"
);
}
pub(super) fn notify_stage(
on_stage: &mut Option<&mut dyn FnMut(ManifestLoadStage)>,
stage: ManifestLoadStage,
) {
if let Some(callback) = on_stage.as_mut() {
callback(stage);
}
}