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(ingestion/grafana): Add datasets and charts to dashboards with lineage and tags. Lineage back to source #12417

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

acrylJonny
Copy link
Contributor

@acrylJonny acrylJonny commented Jan 21, 2025

Adding functionality to the existing Grafana connector. The existing connector supports Dashboard identification only Changed implement the following:

  • Charts
    • Input datasets
    • Input Columns
  • Datasets
    • Dataset Schema
    • Subtyping with definition where SQL
  • Lineage:
    • between upstream sources and datasets
    • between datasets and charts
    • between charts and workbooks
    • Supports SQL lineage reconciliation using datahub.sql_parsing.sqlglot_lineage falling back to sqlparse
  • Tag extraction with propagation back from dashboard through to chart and dataset
  • Owner extraction
image

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

@acrylJonny acrylJonny marked this pull request as draft January 21, 2025 15:20
@github-actions github-actions bot added the ingestion PR or Issue related to the ingestion of metadata label Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 97.04142% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...datahub/ingestion/source/grafana/grafana_source.py 94.17% 6 Missing ⚠️
...on/src/datahub/ingestion/source/grafana/lineage.py 91.04% 6 Missing ⚠️
...rc/datahub/ingestion/source/grafana/grafana_api.py 97.10% 2 Missing ⚠️
...rc/datahub/ingestion/source/grafana/field_utils.py 98.93% 1 Missing ⚠️
Files with missing lines Coverage Δ
...b-react/src/app/ingest/source/builder/constants.ts 100.00% <100.00%> (ø)
...hub/ingestion/source/grafana/entity_mcp_builder.py 100.00% <100.00%> (ø)
...datahub/ingestion/source/grafana/grafana_config.py 100.00% <100.00%> (ø)
...ion/src/datahub/ingestion/source/grafana/models.py 100.00% <100.00%> (ø)
...ion/src/datahub/ingestion/source/grafana/report.py 100.00% <100.00%> (ø)
...tion/src/datahub/ingestion/source/grafana/types.py 100.00% <100.00%> (ø)
...rc/datahub/ingestion/source/grafana/field_utils.py 98.93% <98.93%> (ø)
...rc/datahub/ingestion/source/grafana/grafana_api.py 97.10% <97.10%> (ø)
...datahub/ingestion/source/grafana/grafana_source.py 95.04% <94.17%> (ø)
...on/src/datahub/ingestion/source/grafana/lineage.py 91.04% <91.04%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e18fa0...ac2e4cd. Read the comment docs.

@acrylJonny acrylJonny marked this pull request as ready for review January 21, 2025 22:21
@datahub-cyborg datahub-cyborg bot added the needs-review Label for PRs that need review from a maintainer. label Jan 21, 2025
@datahub-cyborg datahub-cyborg bot added pending-submitter-response Issue/request has been reviewed but requires a response from the submitter and removed needs-review Label for PRs that need review from a maintainer. labels Jan 22, 2025
@datahub-cyborg datahub-cyborg bot added needs-review Label for PRs that need review from a maintainer. and removed pending-submitter-response Issue/request has been reviewed but requires a response from the submitter labels Jan 22, 2025
@datahub-cyborg datahub-cyborg bot added pending-submitter-response Issue/request has been reviewed but requires a response from the submitter and removed needs-review Label for PRs that need review from a maintainer. labels Jan 22, 2025
Copy link
Collaborator

@mayurinehate mayurinehate left a comment

Choose a reason for hiding this comment

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

Looking good. I'd much appreciate a "Concept Mapping" section in docs.

)

# Generate dashboard container first
yield from gen_containers(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly this is new addition over only dashboard entity that was present earlier. so one container corresponding to each dashboard - to encompass panels (chart) and datasource (dataset) entity ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If so wondering if datasources are dashboard scoped or global in grafana.

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 is correct. For data sources (the database name, type and the database) are global but the SQL itself for each visual is set in each chart.

platform_instance=self.source_config.platform_instance,

yield from add_dataset_to_container(
container_key=folder_key,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can set parent_container_key = folder_key in gen_containers for dashboard instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mayurinehate, would you be able to suggest the appropriate changes as this is not super clear what the proposal is?

return None

ds_type, ds_uid = self._extract_datasource_info(panel.datasource)
raw_sql = self._extract_raw_sql(panel.targets)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious if we ingest raw query used in panel anywhere in model. I believe the language of query depends on the source it integrates with.

return None

ds_type, ds_uid = self._extract_datasource_info(panel.datasource)
raw_sql = self._extract_raw_sql(panel.targets)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious if we ingest raw query used in panel anywhere in datahub model? I believe the language of query depends on the source it integrates with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you be able to expand upon this?

service_account = grafana_client.create_service_account(
name="example-service-account", role="Viewer"
name="example-service-account", role="Admin"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any specific reason for changing role here ? Do we require elevated permissions for changes in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You need the admin permission to obtain access to the data source. A lot of the information used for lineage required admin access because otherwise you can't get compile the lineage.

@datahub-cyborg datahub-cyborg bot added pending-submitter-response Issue/request has been reviewed but requires a response from the submitter and removed needs-review Label for PRs that need review from a maintainer. labels Jan 28, 2025
from_start = sql.index("from")
select_part = sql[select_start:from_start].strip()

columns = [col.strip().split()[-1].strip() for col in select_part.split(",")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming that split by , will actually split by columns may be wrong assumption, eg: SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users
Not sure if we need to address this complexity though. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some more logic that targets this type of SQL

@datahub-cyborg datahub-cyborg bot added needs-review Label for PRs that need review from a maintainer. and removed pending-submitter-response Issue/request has been reviewed but requires a response from the submitter labels Feb 14, 2025
@acrylJonny
Copy link
Contributor Author

Looking good. I'd much appreciate a "Concept Mapping" section in docs.

Concept map has now been added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ingestion PR or Issue related to the ingestion of metadata needs-review Label for PRs that need review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants