diff --git a/ingestion/src/metadata/ingestion/source/redash.py b/ingestion/src/metadata/ingestion/source/redash.py index 55adb8554c3..faf891abdc3 100644 --- a/ingestion/src/metadata/ingestion/source/redash.py +++ b/ingestion/src/metadata/ingestion/source/redash.py @@ -24,6 +24,9 @@ from metadata.generated.schema.entity.services.connections.metadata.openMetadata OpenMetadataConnection, ) from metadata.generated.schema.entity.services.dashboardService import DashboardService +from metadata.generated.schema.metadataIngestion.dashboardServiceMetadataPipeline import ( + DashboardServiceMetadataPipeline, +) from metadata.generated.schema.metadataIngestion.workflow import ( Source as WorkflowSource, ) @@ -33,6 +36,7 @@ from metadata.ingestion.api.source import InvalidSourceException, Source, Source from metadata.ingestion.models.table_metadata import Chart as ModelChart from metadata.ingestion.models.table_metadata import Dashboard from metadata.ingestion.ometa.ometa_api import OpenMetadata +from metadata.utils.connections import get_connection, test_connection @dataclass @@ -63,12 +67,14 @@ class RedashSource(Source[Entity]): self.config = config self.metadata_config = metadata_config self.metadata = OpenMetadata(metadata_config) - + self.source_config: DashboardServiceMetadataPipeline = ( + self.config.sourceConfig.config + ) self.connection_config = self.config.serviceConnection.__root__.config self.status = RedashSourceStatus() - self.client = Redash( - self.connection_config.hostPort, self.connection_config.apiKey - ) + self.connection = get_connection(self.connection_config) + self.client = self.connection.client + self.service = self.metadata.get_service_or_create( entity=DashboardService, config=config ) diff --git a/ingestion/src/metadata/utils/connection_clients.py b/ingestion/src/metadata/utils/connection_clients.py index 74829a39cd4..ed109c5a01f 100644 --- a/ingestion/src/metadata/utils/connection_clients.py +++ b/ingestion/src/metadata/utils/connection_clients.py @@ -11,6 +11,12 @@ from dataclasses import dataclass +""" +Creating client for non-sqlalchemy package is neccessary, +Importing a Class directly in connection.py will break the ingestion, +if non-sqlalchemy package is not installed +""" + @dataclass class GlueClient: @@ -46,3 +52,9 @@ class KafkaClient: class MetabaseClient: def __init__(self, client) -> None: self.client = client + + +@dataclass +class RedashClient: + def __init__(self, client) -> None: + self.client = client diff --git a/ingestion/src/metadata/utils/connections.py b/ingestion/src/metadata/utils/connections.py index f244c3d3146..b6180575acf 100644 --- a/ingestion/src/metadata/utils/connections.py +++ b/ingestion/src/metadata/utils/connections.py @@ -31,6 +31,9 @@ from metadata.generated.schema.entity.services.connections.connectionBasicType i from metadata.generated.schema.entity.services.connections.dashboard.metabaseConnection import ( MetabaseConnection, ) +from metadata.generated.schema.entity.services.connections.dashboard.redashConnection import ( + RedashConnection, +) from metadata.generated.schema.entity.services.connections.database.bigQueryConnection import ( BigQueryConnection, ) @@ -58,6 +61,7 @@ from metadata.utils.connection_clients import ( GlueClient, KafkaClient, MetabaseClient, + RedashClient, SalesforceClient, ) from metadata.utils.credentials import set_google_credentials @@ -364,7 +368,31 @@ def _(connection: MetabaseClient) -> None: connection.client["connection"].hostPort + "/api/dashboard", headers=connection.client["metabase_session"], ) - + except Exception as err: + raise SourceConnectionException( + f"Unknown error connecting with {connection} - {err}." + ) + + +@get_connection.register +def _(connection: RedashConnection, verbose: bool = False): + + from redash_toolbelt import Redash + + try: + redash = Redash(connection.hostPort, connection.apiKey) + redash_client = RedashClient(redash) + return redash_client + + except Exception as err: + logger.error(f"Failed to connect with error : {err}") + logger.error(err) + + +@test_connection.register +def _(connection: RedashClient) -> None: + try: + connection.client.dashboards() except Exception as err: raise SourceConnectionException( f"Unknown error connecting with {connection} - {err}."