-
Notifications
You must be signed in to change notification settings - Fork 124
feat(DENG-9188) Add BigConfig checks to targeted stable tables #8436
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
Draft
phil-lee70
wants to merge
3
commits into
main
Choose a base branch
from
deng-9188
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Stable Tables Targeted | ||
|
|
||
| This generator builds the BigEye `biconfig.yml` and `metadata.yaml` files for targeted stable tables. The reason for this appproach is to mitigate any potential negative impacts should there be increased future costs associated with freshness and volume checks. | ||
|
|
||
| ## Conifguration | ||
|
|
||
| Modify the `bqetl_project.yaml` file. Example: | ||
|
|
||
| ```yaml | ||
| monitoring: | ||
| stable_tables_targeted: | ||
| mozilla_vpn_external: | ||
| - waitlist_v1 | ||
| ``` | ||
| ## Running the generator | ||
| To test this generator run `./bqetl generate stable_tables_targeted`. | ||
|
|
||
| Output: | ||
|
|
||
| <img width="442" height="258" alt="Screenshot 2025-11-17 at 10 46 34 AM" src="https://github.com/user-attachments/assets/13218167-fcd1-4fed-bbf2-d32537aad872" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """Generate metadata and bigconfig files for targeted stable tables.""" | ||
|
|
||
| import click | ||
|
|
||
| from bigquery_etl.cli.utils import is_valid_project | ||
| from sql_generators.stable_tables_targeted.stable_tables_targeted import ( | ||
| generate_stable_table_bigconfig_files, | ||
| ) | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option( | ||
| "--target-project", | ||
| "--target_project", | ||
| help="GCP project ID", | ||
| default="moz-fx-data-shared-prod", | ||
| callback=is_valid_project, | ||
| ) | ||
| @click.option( | ||
| "--enable-monitoring", | ||
| "--enable_monitoring", | ||
| help="Monitoring enabled true or false", | ||
| default=True, | ||
| ) | ||
| def generate(target_project, enable_monitoring, **kwargs): | ||
| """Call generate_mobile_kpi_support_metrics function.""" | ||
| generate_stable_table_bigconfig_files(target_project, enable_monitoring) |
76 changes: 76 additions & 0 deletions
76
sql_generators/stable_tables_targeted/stable_tables_targeted.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """Generate metadata and bigconfig files for targeted stable tables.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
| from jinja2 import Environment, FileSystemLoader | ||
|
|
||
|
|
||
| def load_yaml_file(file_path): | ||
| """Load bqetl project yaml file to get stable table datasets and table names.""" | ||
| with open(file_path, "r") as file: | ||
| return yaml.safe_load(file) | ||
|
|
||
|
|
||
| def write_file(content, file_path): | ||
| """Write metadata.yaml and bigconfig.yml to correct directories.""" | ||
| with open(file_path, "w") as file: | ||
| file.write(content) | ||
|
|
||
|
|
||
| def parse_config_name(config): | ||
| """Parse config name into name and version parts.""" | ||
| if "_" in config: | ||
| return config.rsplit("_", 1) | ||
| return config, "v1" | ||
|
|
||
|
|
||
| def generate_stable_table_bigconfig_files(target_project, enable_monitoring): | ||
| """Generate the metadata and bigconfig files and write to correct directories.""" | ||
| THIS_PATH = Path(__file__).parent | ||
| TEMPLATES_DIR = THIS_PATH / "templates" | ||
| SQL_BASE_DIR = THIS_PATH.parent.parent / "sql" / target_project | ||
|
|
||
| BIGEYE_COLLECTION = "Operational Checks" | ||
| BIGEYE_SLACK_CHANNEL = "#de-bigeye-triage" | ||
|
|
||
| env = Environment(loader=FileSystemLoader(str(TEMPLATES_DIR))) | ||
| bigconfig_template = env.get_template("stable_tables_targeted.bigconfig.yml") | ||
| metadata_template = env.get_template("stable_tables_targeted.metadata.yaml") | ||
|
|
||
| project_config = load_yaml_file("bqetl_project.yaml") | ||
| stable_table_bigconfigs = project_config.get("monitoring", {}).get( | ||
| "stable_tables_targeted", {} | ||
| ) | ||
|
|
||
| common_metadata_vars = { | ||
| "bigeye_collection": BIGEYE_COLLECTION, | ||
| "enable_monitoring": enable_monitoring, | ||
| } | ||
|
|
||
| # Create directory for each dataset | ||
| for dataset_name, table_name in stable_table_bigconfigs.items(): | ||
|
|
||
| target_dir = SQL_BASE_DIR / dataset_name | ||
| target_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Create directory for each table each with a metadata.yaml and bigconfig.yml file | ||
| for table in table_name: | ||
| name_part, version_part = parse_config_name(table) | ||
|
|
||
| rendered_content = bigconfig_template.render( | ||
| project_id=target_project, | ||
| dataset=dataset_name, | ||
| name=name_part, | ||
| version=version_part, | ||
| bigeye_collection=BIGEYE_COLLECTION, | ||
| bigeye_notification_slack_channel=BIGEYE_SLACK_CHANNEL, | ||
| ) | ||
|
|
||
| metadata_rendered = metadata_template.render(**common_metadata_vars) | ||
|
|
||
| stable_table_bigconfig_dir = target_dir / table | ||
| stable_table_bigconfig_dir.mkdir(exist_ok=True) | ||
|
|
||
| write_file(metadata_rendered, stable_table_bigconfig_dir / "metadata.yaml") | ||
| write_file(rendered_content, stable_table_bigconfig_dir / "bigconfig.yml") |
13 changes: 13 additions & 0 deletions
13
sql_generators/stable_tables_targeted/templates/stable_tables_targeted.bigconfig.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| type: BIGCONFIG_FILE | ||
|
|
||
| tag_deployments: | ||
| - collection: | ||
| name: {{ bigeye_collection }} | ||
| notification_channels: | ||
| - slack: '{{ bigeye_notification_slack_channel }}' | ||
| deployments: | ||
| - column_selectors: | ||
| - name: {{ project_id }}.{{ project_id }}.{{ dataset }}_derived.{{ name }}_{{ version }}.* | ||
| metrics: | ||
| - saved_metric_id: volume | ||
| - saved_metric_id: freshness |
12 changes: 12 additions & 0 deletions
12
sql_generators/stable_tables_targeted/templates/stable_tables_targeted.metadata.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| friendly_name: Stable Table BigEye Checks | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the friendly name should match that of the related stable table |
||
| description: |- | ||
| There are two main namespaces in BigQuery for used during telemetry ingestion process. | ||
| Those namespaces end with _live and _stable . _live is the initial landing zone in BigQuery for our ping data | ||
| coming from our ingestion-sink which uses a smaller time window to batch telemetry data together. | ||
| However, there is a potential for duplicate entries in this dataset which is why once a day copy_deduplicate DAG performs de-duplication of this data | ||
| and saves the result in the corresponding _stable namespace (which also acts as long term storage of this raw data). | ||
| These BigEye checks add freshness and volume checks to these stable tables. | ||
|
|
||
| monitoring: | ||
| enabled: {% if enable_monitoring %}true{% else %}false{% endif %} | ||
| collection: {{ bigeye_collection }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL generator could be renamed to something like
stable_table_monitoringto make it clearer that it is generating monitoring related configs