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
38 changes: 37 additions & 1 deletion src/mozanalysis/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DataSource:
converter=group_id_column_converter,
)

EXPERIMENT_COLUMN_TYPES = (None, "simple", "native", "glean")
EXPERIMENT_COLUMN_TYPES = (None, "simple", "native", "glean", "events_stream")

@experiments_column_type.validator
def _check_experiments_column_type(self, attribute, value):
Expand Down Expand Up @@ -177,6 +177,16 @@ def experiments_column_expr(self) -> str:
).branch IS NOT NULL
)"""

elif self.experiments_column_type == "events_stream":
return """AND (
ds.{submission_date} != e.enrollment_date
OR IF(
JSON_VALUE(ds.event_extra, '$.experiment') = '{experiment_slug}',
JSON_VALUE(ds.event_extra, '$.branch'),
NULL
) IS NOT NULL
)""" # noqa:E501

else:
raise ValueError

Expand Down Expand Up @@ -413,6 +423,32 @@ def get_sanity_metrics(self, experiment_slug: str) -> list[Metric]:
),
]

elif self.experiments_column_type == "events_stream":
return [
Metric(
name=self.name + "_has_contradictory_branch",
data_source=self,
select_expr=agg_any(
"""IF(
JSON_VALUE(ds.event_extra, '$.experiment') = '{experiment_slug}',
JSON_VALUE(ds.event_extra, '$.branch'),
NULL
) != e.branch """
Comment on lines +432 to +436
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think you're right that this matches the other checks a little more closely than just checking the branch alone, and either way it's no harm to check the experiment + branch.

),
),
Metric(
name=self.name + "_has_non_enrolled_data",
data_source=self,
select_expr=agg_any(
f"""IF(
JSON_VALUE(ds.event_extra, '$.experiment') = '{experiment_slug}',
JSON_VALUE(ds.event_extra, '$.branch'),
NULL
) IS NULL"""
),
),
]

else:
raise ValueError

Expand Down
4 changes: 3 additions & 1 deletion tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from mozanalysis.metrics import AnalysisBasis, DataSource, Metric


@pytest.mark.parametrize("experiments_column_type", [None, "simple", "native", "glean"])
@pytest.mark.parametrize(
"experiments_column_type", [None, "simple", "native", "glean", "events_stream"]
)
def test_datasource_constructor_succeeds(experiments_column_type):
DataSource(
name="foo",
Comment on lines 10 to 15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there should be more tests than this (e.g., for the two functions you modified here). I know we have more comprehensive testing in jetstream so maybe not a big deal, but if you've got some time and inclination now want to tackle that here? Otherwise can you just file a ticket (in mozanalysis issues is good) to add unit tests for those two functions?

Expand Down