Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dbt sync): Support metric key remapping #311

Merged
merged 3 commits into from
Aug 16, 2024
Merged

Conversation

Vitor-Avila
Copy link
Contributor

dbt introduced new restrictions to metric names with MetricFlow (for example, it's no longer possible to have __ in metric names). As a consequence, in order to upgrade to a supported version customers have to update all their metric names according to new rules. The metric mapping with Preset happens based on the metric name, so a re-name in dbt would result in new metrics in Preset, leaving old metrics out of sync.

This PR introduces a way to map a dbt metric with a Preset metric with diverging names, to minimize the impact of this change.

This PR also improves the meta handling in general for metrics (so that Preset-specific fields can be controlled through dbt) and also improves the handling for the metric label (it wasn't being pulled from MetricFlow metrics).

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Looks good! Left a small suggestion.

meta = metric.get("meta", {})
kwargs = meta.pop("superset", {})
metric_meta = parse_metric_meta(
metric.get("meta", metric.get("config", {}).get("meta", {})),
Copy link
Member

Choose a reason for hiding this comment

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

I think we should move this logic to the parse_metric_meta, it would make it easier to understand. Here we'd simply do:

metric_meta = parse_metric_meta(metric)

And the parse_metric_meta function would handle the retrieval of meta.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes sense! let me get that done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@betodealmeida I implemented a base MetricSchema (shared across OG/MF/etc) o that I can also use it as the type hint for this helper. This caused some additional updates to other files.

"""
Parses the metric's meta information.
"""
kwargs = metric.get("meta", {}).pop("superset", {})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still need to use .get("meta", {}) here as logic to handle meta || config.meta for dbt Cloud will be added in a future PR

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Double approved!

@Vitor-Avila
Copy link
Contributor Author

double thanks!

test

@Vitor-Avila Vitor-Avila merged commit 59fbead into main Aug 16, 2024
5 checks passed
@Vitor-Avila Vitor-Avila deleted the metric-key-mapping branch August 16, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants