diff --git a/bootstrap/sql/com.mysql.cj.jdbc.Driver/v007__create_db_connection_info.sql b/bootstrap/sql/com.mysql.cj.jdbc.Driver/v007__create_db_connection_info.sql index 4d22727c385..7038316645d 100644 --- a/bootstrap/sql/com.mysql.cj.jdbc.Driver/v007__create_db_connection_info.sql +++ b/bootstrap/sql/com.mysql.cj.jdbc.Driver/v007__create_db_connection_info.sql @@ -9,7 +9,8 @@ SET json = JSON_INSERT( JSON_ARRAY( JSON_OBJECT('name', 'entityFqn', 'chartDataType', 'STRING'), JSON_OBJECT('name', 'owner', 'chartDataType', 'STRING'), - JSON_OBJECT('name', 'entityType', 'chartDataType', 'STRING') + JSON_OBJECT('name', 'entityType', 'chartDataType', 'STRING'), + JSON_OBJECT('name', 'entityHref', 'chartDataType', 'STRING') ) ) WHERE name = 'mostViewedEntities'; \ No newline at end of file diff --git a/bootstrap/sql/org.postgresql.Driver/v007__create_db_connection_info.sql b/bootstrap/sql/org.postgresql.Driver/v007__create_db_connection_info.sql index f0766143477..c1f74cf8257 100644 --- a/bootstrap/sql/org.postgresql.Driver/v007__create_db_connection_info.sql +++ b/bootstrap/sql/org.postgresql.Driver/v007__create_db_connection_info.sql @@ -6,6 +6,6 @@ UPDATE data_insight_chart SET json = jsonb_set( json, '{dimensions}', - '[{"name":"entityFqn","chartDataType":"STRING"},{"name":"owner","chartDataType":"STRING"},{"name":"owner","entityType":"STRING"}]' + '[{"name":"entityFqn","chartDataType":"STRING"},{"name":"entityType","chartDataType":"STRING"},{"name":"owner","chartDataType":"STRING"},{"name":"entityHref","chartDataType":"STRING"}]' ) WHERE name = 'mostViewedEntities'; \ No newline at end of file diff --git a/ingestion/src/metadata/data_insight/processor/web_analytic_report_data_processor.py b/ingestion/src/metadata/data_insight/processor/web_analytic_report_data_processor.py index 36664b0af8c..ccac7f4df30 100644 --- a/ingestion/src/metadata/data_insight/processor/web_analytic_report_data_processor.py +++ b/ingestion/src/metadata/data_insight/processor/web_analytic_report_data_processor.py @@ -15,6 +15,7 @@ Processor class used to compute refined report data from __future__ import annotations +import re from collections import namedtuple from typing import Generator, Iterable, Optional @@ -107,12 +108,28 @@ class WebAnalyticEntityViewReportDataProcessor(DataProcessor): continue entity_obj = EntityObj(split_url[0], split_url[1]) + entity_type = entity_obj.entity_type + re_pattern = re.compile(f"(.*{entity_type}/{entity_obj.fqn})") + + if ( + entity_obj.fqn in refined_data + and not refined_data[entity_obj.fqn]["entityHref"] + ): + # if we've seen the entity previously but were not able to get + # the URL we'll try again from the new event. + try: + entity_href = re.search(re_pattern, event.eventData.fullUrl).group( + 1 + ) + refined_data[entity_obj.fqn]["entityHref"] = entity_href + except IndexError: + logger.debug(f"Could not find entity Href for {entity_obj.fqn}") if entity_obj.fqn not in refined_data: entity = self.metadata.get_by_name( ENTITIES[entity_obj.entity_type], fqn=entity_obj.fqn, - fields="*", + fields=["tags"], ) try: @@ -143,10 +160,18 @@ class WebAnalyticEntityViewReportDataProcessor(DataProcessor): "`tags` attribute not supported for entity type", ) + try: + entity_href = re.search(re_pattern, event.eventData.fullUrl).group( + 1 + ) + except IndexError: + entity_href = None + refined_data[split_url[1]] = { - "entityType": entity_obj.entity_type.title(), + "entityType": ENTITIES[entity_type].__name__, "entityTier": entity_tier, "entityFqn": entity_obj.fqn, + "entityHref": entity_href, "tagsFQN": tags, "owner": owner, "ownerId": owner_id, diff --git a/ingestion/src/metadata/ingestion/sink/elasticsearch_mapping/web_analytic_entity_view_report_data_index_mapping.py b/ingestion/src/metadata/ingestion/sink/elasticsearch_mapping/web_analytic_entity_view_report_data_index_mapping.py index b65268dc386..3887dba5c4d 100644 --- a/ingestion/src/metadata/ingestion/sink/elasticsearch_mapping/web_analytic_entity_view_report_data_index_mapping.py +++ b/ingestion/src/metadata/ingestion/sink/elasticsearch_mapping/web_analytic_entity_view_report_data_index_mapping.py @@ -29,6 +29,9 @@ WEB_ANALYTIC_ENTITY_VIEW_REPORT_DATA_INDEX_MAPPING = textwrap.dedent( "entityType": { "type": "keyword" }, + "entityHref": { + "type": "keyword" + }, "entityTier": { "type": "keyword" }, diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/dataInsight/MostViewedEntitiesAggregator.java b/openmetadata-service/src/main/java/org/openmetadata/service/dataInsight/MostViewedEntitiesAggregator.java index ab852a175ee..f8404fca5cc 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/dataInsight/MostViewedEntitiesAggregator.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/dataInsight/MostViewedEntitiesAggregator.java @@ -32,14 +32,20 @@ public class MostViewedEntitiesAggregator extends DataInsightAggregatorInterface Sum sumPageViews = entityFqnBucket.getAggregations().get("pageViews"); MultiBucketsAggregation ownerBucket = entityFqnBucket.getAggregations().get("owner"); MultiBucketsAggregation entityTypeBucket = entityFqnBucket.getAggregations().get("entityType"); + MultiBucketsAggregation entityHrefBucket = entityFqnBucket.getAggregations().get("entityHref"); String owner = null; String entityType = null; + String entityHref = null; if (!ownerBucket.getBuckets().isEmpty()) { owner = ownerBucket.getBuckets().get(0).getKeyAsString(); } if (!entityTypeBucket.getBuckets().isEmpty()) { - entityType = entityTypeBucket.getBuckets().get(0).getKeyAsString().toLowerCase(); + entityType = entityTypeBucket.getBuckets().get(0).getKeyAsString(); + } + + if (!entityHrefBucket.getBuckets().isEmpty()) { + entityHref = entityHrefBucket.getBuckets().get(0).getKeyAsString(); } data.add( @@ -47,6 +53,7 @@ public class MostViewedEntitiesAggregator extends DataInsightAggregatorInterface .withEntityFqn(tableFqn) .withOwner(owner) .withEntityType(entityType) + .withEntityHref(entityHref) .withPageViews(sumPageViews.getValue())); } return data; diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataInsightChartRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataInsightChartRepository.java index 1e25771c498..fc217557da7 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataInsightChartRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataInsightChartRepository.java @@ -56,6 +56,8 @@ public class DataInsightChartRepository extends EntityRepository SUPPORTS_TEAM_FILTER = Arrays.asList( "TotalEntitiesByType", @@ -191,13 +193,16 @@ public class DataInsightChartRepository extends EntityRepository