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

Added description to validation task for better observability #1364

Merged
merged 1 commit into from
Jul 30, 2024
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
14 changes: 12 additions & 2 deletions metricflow/validation/data_warehouse_model_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class DataWarehouseValidationTask:

query_and_params_callable: Callable[[], Tuple[str, SqlBindParameters]]
error_message: str
description: str
context: Optional[ValidationContext] = None
on_fail_subtasks: List[DataWarehouseValidationTask] = field(default_factory=lambda: [])

Expand Down Expand Up @@ -155,6 +156,7 @@ def gen_semantic_model_tasks(
semantic_model=SemanticModelReference(semantic_model_name=semantic_model.name),
),
error_message=f"Unable to access semantic model `{semantic_model.name}` in data warehouse",
description=f"Validating semantic_model {semantic_model.name}",
)
)

Expand Down Expand Up @@ -236,6 +238,7 @@ def gen_dimension_tasks(
element_type=SemanticModelElementType.DIMENSION,
),
error_message=f"Unable to query dimension `{spec.qualified_name}` on semantic model `{semantic_model.name}` in data warehouse",
description=f"Validating dimension `{spec.qualified_name}` in semantic_model `{semantic_model.name}`",
)
)

Expand All @@ -261,6 +264,7 @@ def gen_dimension_tasks(
),
error_message=f"Failed to query dimensions in data warehouse for semantic model `{semantic_model.name}`",
on_fail_subtasks=semantic_model_sub_tasks,
description=f"Validating all dimensions in semantic_model `{semantic_model.name}`",
)
)
return tasks
Expand Down Expand Up @@ -317,6 +321,7 @@ def gen_entity_tasks(
element_type=SemanticModelElementType.ENTITY,
),
error_message=f"Unable to query entity `{spec.element_name}` on semantic model `{semantic_model.name}` in data warehouse",
description=f"Validating entity `{spec.element_name}` in semantic_model `{semantic_model.name}`",
)
)

Expand All @@ -341,6 +346,7 @@ def gen_entity_tasks(
),
error_message=f"Failed to query entities in data warehouse for semantic model `{semantic_model.name}`",
on_fail_subtasks=semantic_model_sub_tasks,
description=f"Validating all entities in semantic_model `{semantic_model.name}`",
)
)
return tasks
Expand Down Expand Up @@ -413,6 +419,7 @@ def gen_measure_tasks(
element_type=SemanticModelElementType.MEASURE,
),
error_message=f"Unable to query measure `{spec.element_name}` on semantic model `{semantic_model.name}` in data warehouse",
description=f"Validating measure `{spec.element_name}` in semantic_model `{semantic_model.name}`",
)
)

Expand All @@ -435,6 +442,7 @@ def gen_measure_tasks(
),
error_message=f"Failed to query measures in data warehouse for semantic model `{semantic_model.name}`",
on_fail_subtasks=source_node_to_sub_task[source_node],
description=f"Validating all measures in semantic_model `{semantic_model.name}`",
)
)
return tasks
Expand Down Expand Up @@ -478,7 +486,8 @@ def gen_metric_tasks(
file_context=FileContext.from_metadata(metadata=metric.metadata),
metric=MetricModelReference(metric_name=metric.name),
),
error_message=f"Unable to query metric `{metric.name}`.",
error_message=f"Unable to query metric `{metric.name}`",
description=f"Validating metric `{metric.name}`",
)
)
return tasks
Expand Down Expand Up @@ -513,7 +522,8 @@ def gen_saved_query_tasks(
element_type=SavedQueryElementType.METRIC,
element_value=saved_query.name,
),
error_message=f"Unable to query saved query `{saved_query.name}`.",
error_message=f"Unable to query saved query `{saved_query.name}`",
description=f"Validating saved_query `{saved_query.name}`",
)
)
return tasks
Expand Down
8 changes: 6 additions & 2 deletions tests_metricflow/validation/test_data_warehouse_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def good_query() -> Tuple[str, SqlBindParameters]:
return ("SELECT 'foo' AS foo", SqlBindParameters())

tasks = [
DataWarehouseValidationTask(query_and_params_callable=good_query, error_message="Could not select foo"),
DataWarehouseValidationTask(
query_and_params_callable=good_query, description="Validating foo", error_message="Could not select foo"
),
]

issues = dw_validator.run_tasks(tasks=tasks)
Expand All @@ -73,7 +75,9 @@ def bad_query() -> Tuple[str, SqlBindParameters]:
return ("SELECT (true) AS col1 FROM doesnt_exist", SqlBindParameters())

err_msg_bad = "Could not access table 'doesnt_exist' in data warehouse"
bad_task = DataWarehouseValidationTask(query_and_params_callable=bad_query, error_message=err_msg_bad)
bad_task = DataWarehouseValidationTask(
query_and_params_callable=bad_query, description="Validating foo", error_message=err_msg_bad
)

tasks.append(bad_task)
issues = dw_validator.run_tasks(tasks=tasks)
Expand Down
Loading