Skip to content

Commit cc6268c

Browse files
authored
Add output_dir parameter for stable_tables_monitoring generator (#8570)
1 parent 03d670f commit cc6268c

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

sql_generators/stable_tables_monitoring/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010

1111
@click.command()
12+
@click.option(
13+
"--output-dir",
14+
"--output_dir",
15+
help="Output directory generated SQL is written to",
16+
type=click.Path(file_okay=False),
17+
default="sql",
18+
)
1219
@click.option(
1320
"--target-project",
1421
"--target_project",
@@ -22,6 +29,6 @@
2229
help="Monitoring enabled true or false",
2330
default=True,
2431
)
25-
def generate(target_project, enable_monitoring, **kwargs):
32+
def generate(target_project, output_dir, enable_monitoring, **kwargs):
2633
"""Call generate_stable_table_bigconfig_files function."""
27-
generate_stable_table_bigconfig_files(target_project, enable_monitoring)
34+
generate_stable_table_bigconfig_files(target_project, output_dir, enable_monitoring)

sql_generators/stable_tables_monitoring/stable_tables_monitoring.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,23 @@ def parse_config_name(config):
2020
return config, "v1"
2121

2222

23-
def generate_stable_table_bigconfig_files(target_project, enable_monitoring):
23+
def generate_stable_table_bigconfig_files(target_project, output_dir, enable_monitoring):
2424
"""Generate the metadata and bigconfig files and write to correct directories."""
25-
THIS_PATH = Path(__file__).parent
26-
TEMPLATES_DIR = THIS_PATH / "templates"
27-
SQL_BASE_DIR = THIS_PATH.parent.parent / "sql" / target_project
25+
templates_dir = Path(__file__).parent / "templates"
26+
sql_base_dir = Path(output_dir) / target_project
2827

29-
BIGEYE_COLLECTION = "Operational Checks"
30-
BIGEYE_SLACK_CHANNEL = "#de-bigeye-triage"
28+
bigeye_collection = "Operational Checks"
29+
bigeye_slack_channel = "#de-bigeye-triage"
3130

32-
env = Environment(loader=FileSystemLoader(str(TEMPLATES_DIR)))
31+
env = Environment(loader=FileSystemLoader(str(templates_dir)))
3332
bigconfig_template = env.get_template("bigconfig.yml.jinja")
3433
metadata_template = env.get_template("metadata.yaml.jinja")
3534

3635
stable_table_bigconfigs = ConfigLoader.get("monitoring", "stable_tables_monitoring")
3736

3837
# Create directory for each dataset
3938
for dataset_name, table_names in stable_table_bigconfigs.items():
40-
41-
target_dir = SQL_BASE_DIR / dataset_name
39+
target_dir = sql_base_dir / dataset_name
4240
target_dir.mkdir(parents=True, exist_ok=True)
4341

4442
# Create directory for each table each with a metadata.yaml and bigconfig.yml file
@@ -50,12 +48,12 @@ def generate_stable_table_bigconfig_files(target_project, enable_monitoring):
5048
dataset=dataset_name,
5149
name=name_part,
5250
version=version_part,
53-
bigeye_collection=BIGEYE_COLLECTION,
54-
bigeye_notification_slack_channel=BIGEYE_SLACK_CHANNEL,
51+
bigeye_collection=bigeye_collection,
52+
bigeye_notification_slack_channel=bigeye_slack_channel,
5553
)
5654

5755
metadata_rendered = metadata_template.render(
58-
bigeye_collection=BIGEYE_COLLECTION,
56+
bigeye_collection=bigeye_collection,
5957
enable_monitoring=enable_monitoring,
6058
name=name_part,
6159
)

0 commit comments

Comments
 (0)