From d0c08fb6e65694bccc29c4e36d04f129eff94266 Mon Sep 17 00:00:00 2001 From: IceS2 Date: Thu, 22 Aug 2024 23:51:58 +0200 Subject: [PATCH] Add a Workaround for the Tier Calculation on DataInsightsReport (#17555) --- .../insights/DataInsightsReportApp.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/DataInsightsReportApp.java b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/DataInsightsReportApp.java index c8518709cc3..cb97612da34 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/DataInsightsReportApp.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/DataInsightsReportApp.java @@ -345,7 +345,7 @@ public class DataInsightsReportApp extends AbstractNativeApplication { // Get total Assets Data // This assumes that on a particular date the correct count per entities are given Map dateWithCount = - getDateMapWithCountFromChart( + getDateMapWithCountFromTierChart( "total_data_assets_by_tier", timeConfig.startTime(), timeConfig.endTime(), team); Double previousHasTier = dateWithCount.getOrDefault(timeConfig.startDay(), 0D); @@ -388,6 +388,38 @@ public class DataInsightsReportApp extends AbstractNativeApplication { dateMap); } + // Hack: Because on Data Insights when a Tier is not present is set as 'NoTier', this calculation + // will return 100% of the entities + // with Tier. + // This should be fixed by using the .missing() attribute for ElasticSearch aggregations and + // should be planned for 1.6. + // Meanwhile this is a workaround. + private Map getDateMapWithCountFromTierChart( + String chartName, Long startTime, Long endTime, String team) throws IOException { + String filter = prepareTeamFilter(team); + Map systemChartMap = + systemChartRepository.listChartData(chartName, startTime, endTime, filter); + return systemChartMap.get(chartName).getResults().stream() + .filter( + result -> + !result + .getGroup() + .equals( + "NoTier")) // Workaround to remove Assets without Tiers from the equation + .map( + result -> { + Map dayCount = new HashMap<>(); + dayCount.put( + TimestampUtils.timestampToString(result.getDay().longValue(), "dd"), + result.getCount()); + return dayCount; + }) + .flatMap(map -> map.entrySet().stream()) + .collect( + Collectors.groupingBy( + Map.Entry::getKey, Collectors.summingDouble(Map.Entry::getValue))); + } + private Map getDateMapWithCountFromChart( String chartName, Long startTime, Long endTime, String team) throws IOException { String filter = prepareTeamFilter(team);