Skip to content

fix(data-insights): declare the data asset types once and make the field catalog deterministic - #32115

Merged
manerow merged 8 commits into
mainfrom
fix/di-data-asset-types-single-declaration
Sep 2, 2026
Merged

manerow merged 8 commits into
mainfrom
fix/di-data-asset-types-single-declaration

Conversation

@manerow

@manerow manerow commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #31963

Four Data Insights bugs. The first three return a number that looks fine and is wrong, with nothing thrown and nothing logged. The fourth returns HTTP 500.

1. metric fields never reach the chart builder

The set of entity types Data Insights covers was hand-written in three places: the chart field catalog, the ingestion app, and the keys of dataInsights/config.json. The last two stay in sync only because a mismatch throws. Nothing checked the first.

#26260 added metric to the last two in March. It was never added to the first. So di-data-assets-metric has been created and filled daily ever since, while metricType, unitOfMeasurement and granularity have never appeared in the chart builder.

Fix: one enum, dataAssetType.json, that all three derive from. Ingestion still excludes the two data-quality types, which reach the wildcard through a live-index alias, so its set is the same 16 as before and ingestion is unchanged.

2. The field catalog changes on every server restart

getFieldNames deduplicated field names globally, so the first entity type iterated claimed a shared name permanently. The iteration order came from a Set.of, which Java salts per JVM start.

Measured on a seeded instance: 277 records covering 14 of 17 types. topic shares all 28 of its field names with table, so it advertised zero fields despite holding 47,766 documents. Picking "Topic" in the field picker returned an empty list on roughly a coin flip.

Fix: deduplicate by (entityType, name) instead of name, and iterate the enum in order so record order is stable too.

3. Charts pick categories from data they don't count

A terms x-axis picks its 100 buckets first, then counts inside them with the metric filter applied. Picking ignored the filter.

So a "tables per service" chart ranked services by their total document count. A BI service with 5,000 dashboards and 3 tables took a slot and rendered as 3. A warehouse service with 800 tables was missing from the chart entirely.

Fix: order the axis by the filter aggregation each metric is already wrapped in, so a category is ranked by how much it contributed to the metric.

Two details carry the weight:

  • The order key comes from the same pass that builds the wrapper, not from re-reading the chart definition. The Elasticsearch client silently drops a filter it cannot map, so a key chosen from the definition can name an aggregation the request never built, and the engine rejects the whole search with a 400.
  • Ranking uses the wrapper's document count, never the metric's value. An empty min outranks every real minimum, and an empty sum of 0 outranks a negative total, so ordering by value floats the empty categories to the top and pushes real data past size. A document count is never negative and is zero exactly when nothing matched, so empty categories sort last and stay in the response.

The request itself is left wide. Narrowing it to the metric filter would align picking too, but terms uses min_doc_count: 1, so every category the filter emptied would lose its bucket and the chart could no longer say that a service holds none.

Measured through the server, 120 services of which 10 hold tables, axis size 100:

services with tables shown zero rows
before 0 of 10 100
after 10 of 10 90

Identical on Elasticsearch 9.3 and OpenSearch 3.4. @timestamp charts are untouched: a date histogram has no top-N to align.

4. An empty category returns HTTP 500

avg, min and max over a bucket the metric filter emptied return null, not 0. There is no average of nothing. Both aggregators unbox that straight into a primitive:

double value = aggregation.value();   // null -> NullPointerException

Nothing catches it, so the request dies and the user gets a 500 rather than a chart. sum and count return 0.0, which is why only those three functions are affected.

This exists on main today and is not caused by this PR. §3 makes it reachable, because keeping the empty categories is what produces the null buckets.

Fix: null-check before unboxing, on both engines. A category with no value is skipped rather than drawn as 0, since 0 is a legitimate average and would be a wrong answer. Elasticsearch had split the same job across three overloads, so the redundant ValueCountAggregate one is gone and value_count now binds to the guarded path. It never returns null, so nothing changes for it.

Tests

Each verified to fail against the bug it guards:

Revert Fails with
metric removed from config.json coverage test names metric
dedup back to global expected: <[table, topic]> but was: <[table]>
type set back to toUnmodifiableSet() three runs, three different orders, all caught
shared common list mutated in place again expected: <[id, service]> but was: <[id, columns, service]>
ordering removed real-engine test, both engines: data-000 must be selected
order key read from the chart definition aFilterTheClientCannotMapLeavesTheAxisUnranked
a dot allowed into the order path engine 400: Invalid aggregation order path [filter>id.keyword0]
narrowed wrapper allowed to lead the order expected: <[filter1, filter0]> but was: <[filter0, filter1]>
a bare q= wrapper allowed to rank the axis aPerTermQueryAloneDoesNotRankTheAxis
null guard removed the exact Double.doubleValue() NPE, per engine

ElasticSearchCategoricalAxisRealEngineTest and OpenSearchCategoricalAxisRealEngineTest are new. They run the request prepareSearchRequest actually builds against a real Elasticsearch 9.3 and OpenSearch 3.4 via testcontainers, about 12s each. Every defect in §3 was invisible at the serialization level, because a request that looks correct can still be rejected or silently mis-ordered by the engine. Both classes also assert the control, main's shape picking 0 of 10, so the fixture cannot quietly stop discriminating.

Greptile Summary

This PR centralizes Data Insights asset types, makes field-catalog generation deterministic, aligns categorical bucket selection with metric filters, and safely skips null aggregate values.

  • Introduces a schema-backed DataAssetType enum shared by ingestion and chart-field discovery.
  • Deduplicates chart fields by entity type and field name while preserving stable iteration order.
  • Orders categorical axes by the filter-wrapper document count built for each metric.
  • Adds equivalent Elasticsearch and OpenSearch coverage, including real-engine categorical-axis tests.

Confidence Score: 3/5

The PR is not yet safe to merge because malformed empty filters still crash parsing and unmappable Elasticsearch filters can escape single-KPI result requests.

The bulk KPI recovery now handles conversion failures, but the same runtime exception remains uncaught in getKpiResult; additionally, the previously reported null dereference for empty filter text is still present.

Files Needing Attention: openmetadata-service/src/main/java/org/openmetadata/service/search/DataInsightMetricFilter.java; openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/dataInsightAggregators/ElasticSearchDynamicChartAggregatorInterface.java; openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/dataInsightAggregators/ElasticSearchDynamicChartAggregatorInterface.java Builds filter-aware metric aggregations and guards null values, but its new conversion exception still escapes the single-KPI result path.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java Isolates runtime failures during bulk KPI enrichment, while the separate single-result method remains incompatible with the new Elasticsearch exception behavior.
openmetadata-service/src/main/java/org/openmetadata/service/search/DataInsightMetricFilter.java Centralizes filter extraction, but the previously reported empty-input null dereference remains at current HEAD.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/dataInsightAggregators/ElasticSearchLineChartAggregator.java Attaches metric sub-aggregations directly and ranks categorical buckets using the corresponding filter-wrapper counts.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/dataInsightAggregator/OpenSearchLineChartAggregator.java Mirrors the Elasticsearch categorical-axis ordering and aggregation construction for OpenSearch.
openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/DataInsightsApp.java Derives managed Data Insights streams from the shared asset-type enum while excluding types supplied by live-index aliases.
openmetadata-spec/src/main/resources/json/schema/dataInsight/custom/dataAssetType.json Establishes the schema-first canonical enumeration of Data Insights asset types.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C[Data Insights chart definition] --> P[Parse metric filter]
  P --> B[Build metric wrapper aggregation]
  B --> T[Terms axis ordered by wrapper document count]
  T --> E[Elasticsearch or OpenSearch]
  E --> R[Skip null metric values and return chart rows]
  K[KPI result request] --> C
Loading

Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/di-data-ass..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit e6ede9c812d9a1897d976635d43c2c90f1198cde in Playwright run 33478467697, attempt 1.

✅ 1146 passed · ❌ 0 failed · 🟡 4 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 52m 15s

⏱️ Max setup 5m 37s · max shard execution 18m 5s · max shard-job elapsed before upload 21m 9s · reporting 9s

🌐 205.62 requests/attempt · 2.25 app boots/UI scenario · 35.48% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 35.48% (convergence target: at most 15%).
  • Browser traffic was 205.62 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.25 per UI scenario (2648 boots / 1176 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 133 0 0 0 0 0
✅ Shard chromium-02 169 0 0 0 0 0
🟡 Shard chromium-03 161 0 2 0 0 0
🟡 Shard chromium-04 153 0 1 0 0 0
✅ Shard chromium-05 160 0 0 0 0 0
🟡 Shard chromium-06 180 0 1 0 0 0
✅ Shard data-asset-rules-01 63 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 33 0 0 0 0 0
✅ Shard import-export-01 7 0 0 0 0 0
✅ Shard ingestion-01 2 0 0 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 4 flaky test(s) (passed on retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should perform CRUD and Removal operations for database (shard chromium-03, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should verify deleted glossary term not visible in selection for dashboard (shard chromium-03, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-04, 1 retry)
  • Features/Table.spec.ts › should persist page size (shard chromium-06, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 68%
68.59% (90864/132462) 53.05% (57172/107768) 54.69% (17335/31696)

@manerow
manerow force-pushed the fix/di-data-asset-types-single-declaration branch from 563a212 to 4c941ef Compare August 27, 2026 07:00
@gitar-bot

gitar-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Centralizes Data Insights asset types into a shared enum, makes field-catalog generation deterministic by deduplicating per entity type and stabilizing iteration order, aligns categorical axis bucket selection with metric filters, and safely skips null aggregate values. Four bugs fixed: metric fields now reach the chart builder, field catalog no longer changes on server restart, charts rank categories by filtered data instead of total counts, and empty categories no longer crash with HTTP 500. Includes real-engine tests against Elasticsearch 9.3 and OpenSearch 3.4 confirming all defects are resolved.

✅ 1 resolved
✅ Quality: Broad RuntimeException catch may mask unrelated bugs

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/KpiRepository.java:150-152
Catching RuntimeException isolates the intended IllegalArgumentException from filter conversion, but it also silently swallows genuine programming errors (e.g., NullPointerException, IllegalStateException) as a WARN, which can hide real defects behind a per-chart log line. Since the stated goal is to tolerate an unmappable filter, consider catching the narrower IllegalArgumentException (alongside IOException) so unexpected runtime failures still surface.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Sep 1, 2026

Copy link
Copy Markdown

@manerow
manerow added this pull request to the merge queue Sep 2, 2026
Merged via the queue into main with commit 72f02a2 Sep 2, 2026
143 checks passed
@manerow
manerow deleted the fix/di-data-asset-types-single-declaration branch September 2, 2026 11:10
Rohit0301 pushed a commit that referenced this pull request Sep 3, 2026
…eld catalog deterministic (#32115)

* fix(data-insights): declare the data asset types once and make the field catalog deterministic

* perf(data-insights): dedupe chart fields through a seen-set instead of rescanning

* refactor(data-insights): read a chart metric filter through one parser

* fix(data-insights): rank a categorical axis by the wrappers the request builds

* fix(data-insights): catch only a parse failure when reading a chart metric filter

* fix(data-insights): fail a chart metric filter the client cannot map instead of dropping it
shrabantipaul-collate pushed a commit to PRADDZY/OpenMetadata that referenced this pull request Sep 3, 2026
…eld catalog deterministic (open-metadata#32115)

* fix(data-insights): declare the data asset types once and make the field catalog deterministic

* perf(data-insights): dedupe chart fields through a seen-set instead of rescanning

* refactor(data-insights): read a chart metric filter through one parser

* fix(data-insights): rank a categorical axis by the wrappers the request builds

* fix(data-insights): catch only a parse failure when reading a chart metric filter

* fix(data-insights): fail a chart metric filter the client cannot map instead of dropping it
manerow added a commit that referenced this pull request Sep 7, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data Insights /charts/fields omits metric and changes its contents on every restart

2 participants