Skip to content

Commit

Permalink
feat(sqlmesh): add onchain rolling window metrics (#2517)
Browse files Browse the repository at this point in the history
* feat(sqlmesh): add new/returning user model

* chore: configure factory query defs

* feat(sqlmesh): create daily and monthly active address models

* feat(sqlmesh): add active contracts

* Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql

Co-authored-by: Reuven Gonzales <[email protected]>

* Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql

Co-authored-by: Reuven Gonzales <[email protected]>

* Update warehouse/metrics_mesh/oso_metrics/user_retention_classification.sql

Co-authored-by: Reuven Gonzales <[email protected]>

* fix(sqlmesh): metric dates

* fix: active_addresses follow developer metric naming conventions

* refactor: active addresses models

---------

Co-authored-by: Reuven Gonzales <[email protected]>
  • Loading branch information
ccerv1 and ravenac95 authored Nov 26, 2024
1 parent ec26503 commit abc4a98
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 12 deletions.
62 changes: 53 additions & 9 deletions warehouse/metrics_mesh/models/metrics_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
ref="stars.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"active_addresses": MetricQueryDef(
ref="active_addresses.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"commits": MetricQueryDef(
ref="commits.sql",
time_aggregations=["daily", "weekly", "monthly"],
Expand All @@ -45,14 +41,14 @@
ref="forks.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"gas_fees": MetricQueryDef(
ref="gas_fees.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"repositories": MetricQueryDef(
ref="repositories.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"active_contracts": MetricQueryDef(
ref="active_contracts.sql",
time_aggregations=["daily", "weekly", "monthly"],
),
"contributors": MetricQueryDef(
ref="contributors.sql",
time_aggregations=["daily", "weekly", "monthly"],
Expand Down Expand Up @@ -100,6 +96,18 @@
cron="@daily",
),
),
"user_retention_classifications": MetricQueryDef(
ref="user_retention_classification.sql",
vars={
"activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"],
},
rolling=RollingConfig(
windows=[30, 90, 180],
unit="day",
cron="@daily",
),
entity_types=["artifact", "project", "collection"],
),
"change_in_30_day_developer_activity": MetricQueryDef(
vars={
"comparison_interval": 30,
Expand Down Expand Up @@ -187,7 +195,7 @@
),
entity_types=["artifact", "project", "collection"],
),
"avg_time_to_first_response": MetricQueryDef(
"avg_time_to_first_response": MetricQueryDef(
ref="prs_time_to_merge.sql",
rolling=RollingConfig(
windows=[90, 180],
Expand All @@ -196,6 +204,42 @@
),
entity_types=["artifact", "project", "collection"],
),
"active_addresses_aggregation": MetricQueryDef(
ref="active_addresses.sql",
vars={
"activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"],
},
time_aggregations=["daily", "monthly"],
),
"active_addresses_rolling": MetricQueryDef(
ref="active_addresses.sql",
vars={
"activity_event_types": ["CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT"],
},
rolling=RollingConfig(
windows=[30, 90, 180],
unit="day",
cron="@daily",
),
),
"gas_fees": MetricQueryDef(
ref="gas_fees.sql",
rolling=RollingConfig(
windows=[30, 90, 180],
unit="day",
cron="@daily",
),
entity_types=["artifact", "project", "collection"],
),
"transactions": MetricQueryDef(
ref="transactions.sql",
rolling=RollingConfig(
windows=[30, 90, 180],
unit="day",
cron="@daily",
),
entity_types=["artifact", "project", "collection"],
),
},
default_dialect="clickhouse",
)
6 changes: 3 additions & 3 deletions warehouse/metrics_mesh/oso_metrics/active_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ select @metrics_sample_date(events.bucket_day) as metrics_sample_date,
events.to_artifact_id,
'' as from_artifact_id,
@metric_name() as metric,
COUNT(distinct events.from_artifact_id) as amount
COUNT(DISTINCT events.from_artifact_id) as amount
from metrics.events_daily_to_artifact as events
where event_type in ('CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT')
where event_type in @activity_event_types
and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE')
group by 1,
metric,
from_artifact_id,
to_artifact_id,
event_source
event_source,
16 changes: 16 additions & 0 deletions warehouse/metrics_mesh/oso_metrics/active_contracts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
select @metrics_sample_date(events.bucket_day) as metrics_sample_date,
events.event_source,
events.to_artifact_id as to_artifact_id,
'' as from_artifact_id,
@metric_name() as metric,
COUNT(distinct events.to_artifact_id) as amount
from metrics.events_daily_to_artifact as events
where events.event_type in (
'CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT'
)
and events.bucket_day BETWEEN @metrics_start('DATE') AND @metrics_end('DATE')
group by 1,
metric,
from_artifact_id,
to_artifact_id,
event_source
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
with first_events as (
select
from_artifact_id,
min(time::date) as first_event_date
from @first_of_event_from_artifact
where event_type in (@activity_event_types)
group by from_artifact_id
),
active_users as (
select distinct
from_artifact_id,
event_date,
event_source,
@metrics_entity_type_col(
'to_{entity_type}_id',
include_column_alias := true
)
from @metrics_source(
event_types := @activity_event_types
)
where event_date >= @metrics_start('DATE')
)

select
@metrics_end('DATE') as metrics_sample_date,
active.event_source,
@metrics_entity_type_col(
'to_{entity_type}_id',
table_alias := active,
include_column_alias := true
),
'' as from_artifact_id,
@metric_name('new_users') as metric,
COUNT(DISTINCT active.from_artifact_id) as amount
from active_users active
join first_events on first_events.from_artifact_id = active.from_artifact_id
where first_events.first_event_date >= @metrics_start('DATE')
group by
metrics_sample_date,
metric,
from_artifact_id,
@metrics_entity_type_col(
'to_{entity_type}_id',
table_alias := active
),
event_source

union all

select
@metrics_end('DATE') as metrics_sample_date,
active.event_source,
@metrics_entity_type_col(
'to_{entity_type}_id',
table_alias := active,
include_column_alias := true
),
'' as from_artifact_id,
@metric_name('returning_users') as metric,
COUNT(DISTINCT active.from_artifact_id) as amount
from active_users active
join first_events on first_events.from_artifact_id = active.from_artifact_id
where first_events.first_event_date < @metrics_start('DATE')
group by
metrics_sample_date,
metric,
from_artifact_id,
@metrics_entity_type_col(
'to_{entity_type}_id',
table_alias := active
),
event_source

0 comments on commit abc4a98

Please sign in to comment.