Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,22 @@ pub const BUILTIN_SOURCES: &[BuiltinSource] = &[
"commit_change_size",
"code_lines_added",
"lines_added",
"lines_removed",
"pr_created",
"pr_created_merged",
"pr_merged",
"pr_cycle_hours",
"pr_change_size",
],
dimensions: &["source", "category"],
dimensions: &[
"category",
"change_type",
"destination_branch",
"file_extension",
"project",
"repository",
"source",
],
},
BuiltinSource {
source: SourceSeed {
Expand Down Expand Up @@ -429,7 +438,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "commit_count",
}],
dimensions: &["source"],
dimensions: &["project", "repository", "source"],
},
MetricSeed {
metric_key: "git.code_lines",
Expand All @@ -450,7 +459,13 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "code_lines_added",
}],
dimensions: &["source"],
dimensions: &[
"change_type",
"file_extension",
"project",
"repository",
"source",
],
},
MetricSeed {
metric_key: "git.lines_added",
Expand All @@ -471,7 +486,42 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "lines_added",
}],
dimensions: &["category", "source"],
dimensions: &[
"category",
"change_type",
"file_extension",
"project",
"repository",
"source",
],
},
MetricSeed {
metric_key: "git.lines_removed",
source_key: "git",
label: "Lines removed",
description: Some("All lines removed, by file category"),
explanation: Some(
"Lines removed across all reported file changes, with file-category, repository, and source breakdowns available.",
),
unit: Some("lines"),
format: MetricFormat::Integer,
direction: MetricDirection::Neutral,
entity_type: EntityType::Person,
computation: SeedComputation::Sum,
transform: None,
peer_cohort_key: Some(CohortKey::OrgUnit),
inputs: &[InputSeed {
input_role: MetricInputRole::Value,
measure_key: "lines_removed",
}],
dimensions: &[
"category",
"change_type",
"file_extension",
"project",
"repository",
"source",
],
},
MetricSeed {
metric_key: "git.prs_created",
Expand All @@ -490,7 +540,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "pr_created",
}],
dimensions: &["source"],
dimensions: &["destination_branch", "project", "repository", "source"],
},
MetricSeed {
metric_key: "git.prs_merged",
Expand All @@ -509,7 +559,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "pr_merged",
}],
dimensions: &["source"],
dimensions: &["destination_branch", "project", "repository", "source"],
},
MetricSeed {
metric_key: "git.merge_rate",
Expand All @@ -536,7 +586,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
measure_key: "pr_created",
},
],
dimensions: &[],
dimensions: &["destination_branch", "project", "repository", "source"],
},
MetricSeed {
metric_key: "git.commits_per_active_day",
Expand Down Expand Up @@ -582,7 +632,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "commit_change_size",
}],
dimensions: &["source"],
dimensions: &["project", "repository", "source"],
},
MetricSeed {
metric_key: "git.pr_size",
Expand All @@ -603,7 +653,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "pr_change_size",
}],
dimensions: &["source"],
dimensions: &["destination_branch", "project", "repository", "source"],
},
MetricSeed {
metric_key: "git.pr_cycle_time_h",
Expand All @@ -624,7 +674,7 @@ pub const BUILTIN_METRICS: &[MetricSeed] = &[
input_role: MetricInputRole::Value,
measure_key: "pr_cycle_hours",
}],
dimensions: &["source"],
dimensions: &["destination_branch", "project", "repository", "source"],
},
// ─────────────────────────── collaboration ───────────────────────────
MetricSeed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl ValueTransform {
format!("if(({out}) IS NULL, NULL, {clamped})")
}

/// Rust-side application, for values the builder fabricates (zero-fill).
#[cfg(test)]
pub fn apply(&self, value: f64) -> f64 {
let mut out = self.multiplier.unwrap_or(1.0) * value + self.offset.unwrap_or(0.0);
if let Some(clamp_min) = self.clamp_min {
Expand Down Expand Up @@ -198,16 +198,6 @@ impl MetricDefinition {
.find(|d| *d == dimension)
}

// Sums and distinct counts zero-fill: an absent entity genuinely summed
// to nothing / has zero distinct subjects. Ratios and medians of no
// observations are unknowable, not zero.
pub fn is_zero_filled(&self) -> bool {
matches!(
self.spec,
ComputationSpec::Sum { .. } | ComputationSpec::DistinctCount { .. }
)
}

pub fn observation_relation(&self) -> &ObservationRelation {
match &self.spec {
ComputationSpec::Sum { value }
Expand Down
42 changes: 31 additions & 11 deletions src/backend/services/analytics/src/domain/metric_results/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use super::compiler::{
CompiledQuery, PeerQueryRow, PeriodQueryRow, compile_breakdown_query, compile_histogram_query,
compile_peer_batch_query, compile_period_batch_query, compile_timeseries_query,
};
use super::validation::{ValidatedMetricResultsRequest, ValidatedMetricView};
use super::validation::{
ValidatedDimensionFilter, ValidatedMetricResultsRequest, ValidatedMetricView,
};
use super::view::Bucket;

#[derive(Debug)]
Expand Down Expand Up @@ -55,8 +57,10 @@ pub enum PlannedQuery {
}

pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
let mut period_groups: BTreeMap<String, Vec<BatchItem>> = BTreeMap::new();
let mut peer_groups: BTreeMap<(String, String), Vec<BatchItem>> = BTreeMap::new();
let mut period_groups: BTreeMap<(String, Vec<ValidatedDimensionFilter>), Vec<BatchItem>> =
BTreeMap::new();
let mut peer_groups: BTreeMap<(String, String, Vec<ValidatedDimensionFilter>), Vec<BatchItem>> =
BTreeMap::new();
let mut singles = Vec::new();

for (metric_index, metric) in req.metrics.iter().enumerate() {
Expand All @@ -69,7 +73,10 @@ pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
match view {
ValidatedMetricView::Period => {
period_groups
.entry(metric.def.observation_relation().source_ref().to_owned())
.entry((
metric.def.observation_relation().source_ref().to_owned(),
metric.filters.clone(),
))
.or_default()
.push(item());
}
Expand All @@ -78,6 +85,7 @@ pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
.entry((
metric.def.observation_relation().source_ref().to_owned(),
cohort_key.clone(),
metric.filters.clone(),
))
.or_default()
.push(item());
Expand All @@ -91,7 +99,13 @@ pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
bucket: *bucket,
dimensions: dimensions.clone(),
},
query: compile_timeseries_query(&metric.def, req, *bucket, dimensions),
query: compile_timeseries_query(
&metric.def,
req,
*bucket,
dimensions,
&metric.filters,
),
});
}
ValidatedMetricView::Breakdown { dimensions } => {
Expand All @@ -102,7 +116,12 @@ pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
view: UnbatchedView::Breakdown {
dimensions: dimensions.clone(),
},
query: compile_breakdown_query(&metric.def, req, dimensions),
query: compile_breakdown_query(
&metric.def,
req,
dimensions,
&metric.filters,
),
});
}
ValidatedMetricView::Histogram => {
Expand All @@ -111,22 +130,22 @@ pub fn plan_queries(req: &ValidatedMetricResultsRequest) -> Vec<PlannedQuery> {
view_index,
def: Box::new(metric.def.clone()),
view: UnbatchedView::Histogram,
query: compile_histogram_query(&metric.def, req),
query: compile_histogram_query(&metric.def, req, &metric.filters),
});
}
}
}
}

let mut planned = Vec::with_capacity(period_groups.len() + peer_groups.len() + singles.len());
for items in period_groups.into_values() {
for ((_, filters), items) in period_groups {
let defs: Vec<&MetricDefinition> = items.iter().map(|item| &item.def).collect();
let query = compile_period_batch_query(&defs, req);
let query = compile_period_batch_query(&defs, req, &filters);
planned.push(PlannedQuery::PeriodBatch { items, query });
}
for ((_, cohort_key), items) in peer_groups {
for ((_, cohort_key, filters), items) in peer_groups {
let defs: Vec<&MetricDefinition> = items.iter().map(|item| &item.def).collect();
let query = compile_peer_batch_query(&defs, req, &cohort_key);
let query = compile_peer_batch_query(&defs, req, &cohort_key, &filters);
planned.push(PlannedQuery::PeerBatch { items, query });
}
planned.extend(singles);
Expand Down Expand Up @@ -287,6 +306,7 @@ mod tests {
fn views(views: Vec<ValidatedMetricView>, key: &str) -> ValidatedMetricRequest {
ValidatedMetricRequest {
def: def(key, Some("org_unit")),
filters: vec![],
views,
}
}
Expand Down
Loading
Loading