diff --git a/warehouse/metrics_mesh/models/metrics_factories.py b/warehouse/metrics_mesh/models/metrics_factories.py index 24ac8ec05..808f29240 100644 --- a/warehouse/metrics_mesh/models/metrics_factories.py +++ b/warehouse/metrics_mesh/models/metrics_factories.py @@ -287,6 +287,15 @@ ), entity_types=["artifact", "project", "collection"], ), + "dependencies": MetricQueryDef( + ref="dependencies.sql", + rolling=RollingConfig( + windows=[180], + unit="day", + cron="@daily", + ), + entity_types=["artifact", "project", "collection"], + ), }, default_dialect="clickhouse", ) diff --git a/warehouse/metrics_mesh/oso_metrics/dependencies.sql b/warehouse/metrics_mesh/oso_metrics/dependencies.sql new file mode 100644 index 000000000..5e9a0d91f --- /dev/null +++ b/warehouse/metrics_mesh/oso_metrics/dependencies.sql @@ -0,0 +1,14 @@ +select @metrics_sample_date(events.bucket_day) as metrics_sample_date, + events.event_source, + events.to_artifact_id, + '' as from_artifact_id, + @metric_name() as metric, + SUM(events.amount) as amount +from metrics.events_daily_to_artifact as events +where event_type = 'ADD_DEPENDENCY' + and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE') +group by 1, + metric, + from_artifact_id, + to_artifact_id, + event_source