-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(ingestion/grafana): fix fails caused by text panels in ingestion #15291
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ef05bd9
fix(ingestion/grafana): fix fails caused by text panels in ingestion
acrylJonny c78b720
Merge branch 'master' into grafana-text-panel-fix
acrylJonny 4d48451
CUS-6824
acrylJonny 2c0b1e4
fixing issues
acrylJonny 5afa923
defensive against nones and nulls
acrylJonny 50696b6
cleaning
acrylJonny fedbc87
Merge branch 'master' into grafana-text-panel-fix
acrylJonny 97ae68e
defensive checks
acrylJonny 302b3e3
catering for no panel id
acrylJonny e2a35b8
deterministic fallback for multiple panels with no id
acrylJonny afad92b
guarantees that string config is always populated
acrylJonny 072c7d3
Update field_utils.py
acrylJonny 32b3e9d
Update field_utils.py
acrylJonny cfaa0e7
rawSQL fixes
acrylJonny d664226
Update grafana_config.py
acrylJonny d8be166
Update lineage.py
acrylJonny 336f335
Merge branch 'master' into grafana-text-panel-fix
acrylJonny b37b0a0
Merge branch 'master' into grafana-text-panel-fix
acrylJonny 475e8a5
fixing snapshot lineage overwrite
acrylJonny 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,13 @@ def extract_raw_sql_fields( | |
| report: Optional[Any] = None, | ||
| ) -> List[SchemaFieldClass]: | ||
| """Extract fields from raw SQL queries using DataHub's SQL parsing.""" | ||
| raw_sql = target.get("rawSql", "") | ||
| # Handle case variations: rawSql, rawSQL, etc. | ||
| raw_sql = "" | ||
| for key, value in target.items(): | ||
| if key.lower() == "rawsql" and value: | ||
| raw_sql = value | ||
| break | ||
|
|
||
| if not raw_sql: | ||
| return [] | ||
|
|
||
|
|
@@ -77,13 +83,15 @@ def extract_raw_sql_fields( | |
| schema_aware = False | ||
|
|
||
| if panel and panel.datasource_ref and connection_to_platform_map: | ||
| ds_type = panel.datasource_ref.type or "unknown" | ||
| ds_uid = panel.datasource_ref.uid or "unknown" | ||
| ds_type = panel.datasource_ref.type | ||
| ds_uid = panel.datasource_ref.uid | ||
|
|
||
| # Try to find mapping by datasource UID first, then by type | ||
| platform_config = connection_to_platform_map.get( | ||
| ds_uid | ||
| ) or connection_to_platform_map.get(ds_type) | ||
| # Try to find mapping by datasource UID first (if it exists), then by type | ||
| platform_config = None | ||
| if ds_uid: | ||
| platform_config = connection_to_platform_map.get(ds_uid) | ||
| if not platform_config and ds_type: | ||
| platform_config = connection_to_platform_map.get(ds_type) | ||
|
|
||
| if platform_config: | ||
| platform = platform_config.platform | ||
|
|
@@ -141,7 +149,13 @@ def extract_raw_sql_fields( | |
|
|
||
| def _extract_raw_sql_fields_fallback(target: Dict[str, Any]) -> List[SchemaFieldClass]: | ||
| """Fallback basic SQL parsing for when sqlglot fails.""" | ||
| raw_sql = target.get("rawSql", "").lower() | ||
| # Handle case variations: rawSql, rawSQL, etc. | ||
|
Contributor
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. same as before |
||
| raw_sql = "" | ||
| for key, value in target.items(): | ||
| if key.lower() == "rawsql" and value: | ||
| raw_sql = value | ||
| break | ||
|
|
||
| if not raw_sql: | ||
| return [] | ||
|
|
||
|
|
@@ -185,18 +199,20 @@ def _extract_raw_sql_fields_fallback(target: Dict[str, Any]) -> List[SchemaField | |
| # Clean up any remaining quotes or parentheses | ||
| field_name = field_name.strip("\"'()") | ||
|
|
||
| fields.append( | ||
| SchemaFieldClass( | ||
| fieldPath=field_name, | ||
| type=SchemaFieldDataTypeClass(type=StringTypeClass()), | ||
| nativeDataType="sql_column", | ||
| # Only create field if field_name is not empty | ||
| if field_name: | ||
| fields.append( | ||
| SchemaFieldClass( | ||
| fieldPath=field_name, | ||
| type=SchemaFieldDataTypeClass(type=StringTypeClass()), | ||
| nativeDataType="sql_column", | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| return fields | ||
|
|
||
| except (IndexError, ValueError, StopIteration) as e: | ||
| logger.warning(f"Failed to parse SQL: {target.get('rawSql')}", e) | ||
| logger.warning(f"Failed to parse SQL: {raw_sql}", e) | ||
| return [] | ||
|
|
||
|
|
||
|
|
@@ -208,13 +224,27 @@ def extract_fields_from_panel( | |
| ) -> List[SchemaFieldClass]: | ||
| """Extract all fields from a panel.""" | ||
| fields = [] | ||
| fields.extend( | ||
| extract_fields_from_targets( | ||
| panel.query_targets, panel, connection_to_platform_map, graph, report | ||
|
|
||
| # Extract fields from targets (only if there are targets) | ||
| if panel.safe_query_targets: | ||
| target_fields = extract_fields_from_targets( | ||
| panel.safe_query_targets, panel, connection_to_platform_map, graph, report | ||
| ) | ||
| ) | ||
| fields.extend(get_fields_from_field_config(panel.field_config)) | ||
| fields.extend(get_fields_from_transformations(panel.transformations)) | ||
| if target_fields: | ||
| fields.extend(target_fields) | ||
|
|
||
| # Extract fields from field config - use safe property to ensure non-None | ||
| field_config_fields = get_fields_from_field_config(panel.safe_field_config) | ||
| if field_config_fields: | ||
| fields.extend(field_config_fields) | ||
|
|
||
| # Extract fields from transformations (only if there are transformations) | ||
| if panel.safe_transformations: | ||
| transformation_fields = get_fields_from_transformations( | ||
| panel.safe_transformations | ||
| ) | ||
| if transformation_fields: | ||
| fields.extend(transformation_fields) | ||
|
|
||
| # Track schema field extraction | ||
| if report: | ||
|
|
@@ -234,6 +264,7 @@ def extract_fields_from_targets( | |
| report: Optional[Any] = None, | ||
| ) -> List[SchemaFieldClass]: | ||
| """Extract fields from panel targets.""" | ||
|
|
||
| fields = [] | ||
| for target in targets: | ||
| fields.extend(extract_sql_column_fields(target)) | ||
|
|
@@ -275,7 +306,9 @@ def get_fields_from_field_config( | |
| nativeDataType="value", | ||
| ) | ||
| ) | ||
| for override in field_config.get("overrides", []): | ||
|
|
||
| overrides = field_config.get("overrides") or [] | ||
| for override in overrides: | ||
| if override.get("matcher", {}).get("id") == "byName": | ||
| field_name = override.get("matcher", {}).get("options") | ||
| if field_name: | ||
|
|
@@ -293,15 +326,18 @@ def get_fields_from_transformations( | |
| transformations: List[Dict[str, Any]], | ||
| ) -> List[SchemaFieldClass]: | ||
| """Extract fields from transformations.""" | ||
|
|
||
| fields = [] | ||
| for transform in transformations: | ||
| if transform.get("type") == "organize": | ||
| for field_name in transform.get("options", {}).get("indexByName", {}): | ||
| fields.append( | ||
| SchemaFieldClass( | ||
| fieldPath=field_name, | ||
| type=SchemaFieldDataTypeClass(type=StringTypeClass()), | ||
| nativeDataType="transformed", | ||
| # Only create field if field_name is not empty | ||
| if field_name and field_name.strip(): | ||
| fields.append( | ||
| SchemaFieldClass( | ||
| fieldPath=field_name.strip(), | ||
| type=SchemaFieldDataTypeClass(type=StringTypeClass()), | ||
| nativeDataType="transformed", | ||
| ) | ||
| ) | ||
| ) | ||
| return fields | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
what about ?
any other variant to be considered?
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 short answer is that this is dictated by the implementation of the individual connector - so, although we've found Athena to be different to Postgres, there may be more, hence why leaving it as flexible would I think be best.