Repository navigation
Fixes 31478: stop Data Insights summary cards counting test case results #31759
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0636bdb
fix(data-insights): exclude data-quality docs from data-asset totals
ulixius9 5f1b76c
fix(data-insights): move the chart scope migration to 1.13.5
ulixius9 112d064
Merge branch 'main' into baku
IceS2 f7585aa
Merge branch 'main' into baku
IceS2 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
Empty file.
Empty file.
Empty file.
Empty file.
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
26 changes: 26 additions & 0 deletions
26
...adata-service/src/main/java/org/openmetadata/service/migration/mysql/v1135/Migration.java
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.openmetadata.service.migration.mysql.v1135; | ||
|
|
||
| import static org.openmetadata.service.migration.utils.v1135.DataInsightChartMigration.alignDataAssetChartScope; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.openmetadata.service.migration.api.MigrationProcessImpl; | ||
| import org.openmetadata.service.migration.utils.MigrationFile; | ||
|
|
||
| @Slf4j | ||
| public class Migration extends MigrationProcessImpl { | ||
|
|
||
| public Migration(MigrationFile migrationFile) { | ||
| super(migrationFile); | ||
| } | ||
|
|
||
| @Override | ||
| @SneakyThrows | ||
| public void runDataMigration() { | ||
| try { | ||
| alignDataAssetChartScope(); | ||
| } catch (Exception e) { | ||
| LOG.error("v1135: failed to align the data asset scope of the Data Insights charts", e); | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ta-service/src/main/java/org/openmetadata/service/migration/postgres/v1135/Migration.java
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.openmetadata.service.migration.postgres.v1135; | ||
|
|
||
| import static org.openmetadata.service.migration.utils.v1135.DataInsightChartMigration.alignDataAssetChartScope; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.openmetadata.service.migration.api.MigrationProcessImpl; | ||
| import org.openmetadata.service.migration.utils.MigrationFile; | ||
|
|
||
| @Slf4j | ||
| public class Migration extends MigrationProcessImpl { | ||
|
|
||
| public Migration(MigrationFile migrationFile) { | ||
| super(migrationFile); | ||
| } | ||
|
|
||
| @Override | ||
| @SneakyThrows | ||
| public void runDataMigration() { | ||
| try { | ||
| alignDataAssetChartScope(); | ||
| } catch (Exception e) { | ||
| LOG.error("v1135: failed to align the data asset scope of the Data Insights charts", e); | ||
| } | ||
| } | ||
| } |
124 changes: 124 additions & 0 deletions
124
...c/main/java/org/openmetadata/service/migration/utils/v1135/DataInsightChartMigration.java
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 |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Copyright 2021 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.openmetadata.service.migration.utils.v1135; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart; | ||
| import org.openmetadata.service.jdbi3.DataInsightSystemChartRepository; | ||
| import org.openmetadata.service.util.EntityUtil; | ||
|
|
||
| /** | ||
| * Realigns the system Data Insights charts that report on data assets so a summary card and the | ||
| * breakdown below it count the same documents. | ||
| * | ||
| * <p>The {@code di-data-assets-*} pattern the charts read also resolves the data-quality aliases, | ||
| * and those documents carry no {@code entityType}. A breakdown grouped on {@code | ||
| * entityType.keyword} drops them, while the summary cards' old {@code must_not} filter let them | ||
| * through, so the card always ran ahead of the chart by the number of test case results in the | ||
| * window (#31478). The charts were created back in 1.5.0 and every deployment already holds those | ||
| * definitions, so re-apply the scope to each affected chart. | ||
| * | ||
| * <p>Only the two scope-defining properties are rewritten. The metrics' formulas and the rest of | ||
| * each chart are left as stored, so a definition changed by a later migration survives. | ||
| */ | ||
| @Slf4j | ||
| public class DataInsightChartMigration { | ||
|
|
||
| private static final String METRICS_KEY = "metrics"; | ||
| private static final String FILTER_KEY = "filter"; | ||
| private static final String GROUP_BY_KEY = "groupBy"; | ||
| private static final String EXCLUDE_GROUPS_KEY = "excludeGroups"; | ||
| private static final String ENTITY_TYPE_GROUP_BY = "entityType.keyword"; | ||
|
|
||
| /** System charts that report on data assets and must therefore share one scope. */ | ||
| private static final List<String> DATA_ASSET_CHARTS = | ||
| List.of( | ||
| "total_data_assets", | ||
| "total_data_assets_by_tier", | ||
| "total_data_assets_summary_card", | ||
| "total_data_assets_with_tier_summary_card", | ||
| "percentage_of_data_asset_with_description", | ||
| "percentage_of_data_asset_with_owner", | ||
| "percentage_of_service_with_description", | ||
| "percentage_of_service_with_owner", | ||
| "data_assets_with_description_summary_card", | ||
| "data_assets_with_owner_summary_card", | ||
| "percentage_of_data_asset_with_description_kpi", | ||
| "percentage_of_data_asset_with_owner_kpi", | ||
| "number_of_data_asset_with_description_kpi", | ||
| "number_of_data_asset_with_owner_kpi"); | ||
|
|
||
| private DataInsightChartMigration() { | ||
| /* Static migration entry point only */ | ||
| } | ||
|
|
||
| public static void alignDataAssetChartScope() { | ||
| DataInsightSystemChartRepository repository = new DataInsightSystemChartRepository(); | ||
| for (String chartName : DATA_ASSET_CHARTS) { | ||
| applyDataAssetScope(repository, chartName); | ||
| } | ||
| } | ||
|
|
||
| private static void applyDataAssetScope( | ||
| DataInsightSystemChartRepository repository, String chartName) { | ||
| try { | ||
| DataInsightCustomChart chart = | ||
| repository.getByName(null, chartName, EntityUtil.Fields.EMPTY_FIELDS); | ||
| Map<String, Object> chartDetails = asChartDetails(chart); | ||
| if (chartDetails == null) { | ||
| LOG.warn("Chart {} has no chart details, skipping data asset scope alignment", chartName); | ||
| } else { | ||
| scopeToDataAssets(chartDetails); | ||
| chart.setChartDetails(chartDetails); | ||
| repository.prepareInternal(chart, false); | ||
| repository.getDao().update(chart); | ||
| } | ||
| } catch (Exception ex) { | ||
| LOG.warn("Failed to align data asset scope for chart {}: {}", chartName, ex.getMessage()); | ||
| } | ||
|
ulixius9 marked this conversation as resolved.
Resolved
ulixius9 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| static void scopeToDataAssets(Map<String, Object> chartDetails) { | ||
| List<Map<String, Object>> metrics = asMetrics(chartDetails.get(METRICS_KEY)); | ||
| if (metrics != null) { | ||
| for (Map<String, Object> metric : metrics) { | ||
| metric.put(FILTER_KEY, DataInsightSystemChartRepository.DATA_ASSET_FILTER); | ||
| } | ||
| } | ||
| if (ENTITY_TYPE_GROUP_BY.equals(chartDetails.get(GROUP_BY_KEY))) { | ||
| chartDetails.put( | ||
| EXCLUDE_GROUPS_KEY, DataInsightSystemChartRepository.NON_DATA_ASSET_ENTITY_TYPES); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static Map<String, Object> asChartDetails(DataInsightCustomChart chart) { | ||
| Map<String, Object> chartDetails = null; | ||
| if (chart.getChartDetails() instanceof Map<?, ?> details) { | ||
| chartDetails = (Map<String, Object>) details; | ||
| } | ||
| return chartDetails; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static List<Map<String, Object>> asMetrics(Object metrics) { | ||
| List<Map<String, Object>> typedMetrics = null; | ||
| if (metrics instanceof List<?> metricList) { | ||
| typedMetrics = (List<Map<String, Object>>) metricList; | ||
| } | ||
| return typedMetrics; | ||
| } | ||
| } | ||
133 changes: 133 additions & 0 deletions
133
...st/java/org/openmetadata/service/migration/utils/v1135/DataInsightChartMigrationTest.java
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 |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Copyright 2024 Collate. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.openmetadata.service.migration.utils.v1135; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openmetadata.service.jdbi3.DataInsightSystemChartRepository; | ||
|
|
||
| /** | ||
| * Covers the transform the 1.13.5 migration applies to a stored chart definition. The definitions | ||
| * arrive as the maps they deserialize to out of the chart table, so the transform has to work on | ||
| * maps rather than the typed builders (issue #31478). | ||
| */ | ||
| class DataInsightChartMigrationTest { | ||
|
|
||
| @Test | ||
| void everyMetricGetsTheDataAssetFilter() { | ||
| Map<String, Object> chartDetails = chartDetails("entityType.keyword", 2); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| for (Map<String, Object> metric : metricsOf(chartDetails)) { | ||
| assertEquals(DataInsightSystemChartRepository.DATA_ASSET_FILTER, metric.get("filter")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void anExistingFilterIsReplacedRatherThanLeftStale() { | ||
| Map<String, Object> chartDetails = chartDetails("entityType.keyword", 1); | ||
| metricsOf(chartDetails).getFirst().put("filter", "{\"query\":{\"match_all\":{}}}"); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| assertEquals( | ||
| DataInsightSystemChartRepository.DATA_ASSET_FILTER, | ||
| metricsOf(chartDetails).getFirst().get("filter")); | ||
| } | ||
|
|
||
| @Test | ||
| void groupingOnEntityTypeAlsoExcludesGovernanceArtifacts() { | ||
| Map<String, Object> chartDetails = chartDetails("entityType.keyword", 1); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| assertEquals( | ||
| DataInsightSystemChartRepository.NON_DATA_ASSET_ENTITY_TYPES, | ||
| chartDetails.get("excludeGroups")); | ||
| } | ||
|
|
||
| @Test | ||
| void groupingOnAnotherFieldKeepsItsOwnGroups() { | ||
| Map<String, Object> chartDetails = chartDetails("tier.keyword", 1); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| assertFalse( | ||
| chartDetails.containsKey("excludeGroups"), | ||
| "excludeGroups lists entity types, so it must not be forced onto a tier breakdown"); | ||
| assertEquals( | ||
| DataInsightSystemChartRepository.DATA_ASSET_FILTER, | ||
| metricsOf(chartDetails).getFirst().get("filter")); | ||
| } | ||
|
|
||
| @Test | ||
| void aSummaryCardWithoutAGroupByIsStillScoped() { | ||
| Map<String, Object> chartDetails = chartDetails(null, 1); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| assertFalse(chartDetails.containsKey("excludeGroups")); | ||
| assertEquals( | ||
| DataInsightSystemChartRepository.DATA_ASSET_FILTER, | ||
| metricsOf(chartDetails).getFirst().get("filter")); | ||
| } | ||
|
|
||
| @Test | ||
| void aDefinitionWithNoMetricsIsLeftAlone() { | ||
| Map<String, Object> chartDetails = new LinkedHashMap<>(); | ||
| chartDetails.put("type", "SummaryCard"); | ||
|
|
||
| DataInsightChartMigration.scopeToDataAssets(chartDetails); | ||
|
|
||
| assertEquals(Map.of("type", "SummaryCard"), chartDetails); | ||
| } | ||
|
|
||
| @Test | ||
| void theFilterExcludesDocumentsWithoutAnEntityType() { | ||
| String filter = DataInsightSystemChartRepository.DATA_ASSET_FILTER; | ||
|
|
||
| assertTrue( | ||
| filter.contains("{\"exists\":{\"field\":\"entityType\"}}"), | ||
| "A must_not list alone cannot drop the data-quality documents: they have no entityType, " | ||
| + "so they satisfy every must_not clause"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static List<Map<String, Object>> metricsOf(Map<String, Object> chartDetails) { | ||
| return (List<Map<String, Object>>) chartDetails.get("metrics"); | ||
| } | ||
|
|
||
| private static Map<String, Object> chartDetails(String groupBy, int metricCount) { | ||
| List<Map<String, Object>> metrics = new ArrayList<>(); | ||
| for (int i = 0; i < metricCount; i++) { | ||
| Map<String, Object> metric = new HashMap<>(); | ||
| metric.put("formula", "count(k='id.keyword')"); | ||
| metrics.add(metric); | ||
| } | ||
| Map<String, Object> chartDetails = new LinkedHashMap<>(); | ||
| chartDetails.put("metrics", metrics); | ||
| if (groupBy != null) { | ||
| chartDetails.put("groupBy", groupBy); | ||
| } | ||
| return chartDetails; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.