Skip to content

[Metrics][Discover] Render legacy histograms with a warning#253044

Merged
kpatticha merged 8 commits intoelastic:mainfrom
kpatticha:244194-legacy-histograms-with-warning
Feb 20, 2026
Merged

[Metrics][Discover] Render legacy histograms with a warning#253044
kpatticha merged 8 commits intoelastic:mainfrom
kpatticha:244194-legacy-histograms-with-warning

Conversation

@kpatticha
Copy link
Copy Markdown
Contributor

closes #244194

Summary

  • Support legacy histograms in the metrics experience (include them in the grid and render as 95th percentile via TO_TDIGEST in ES|QL).
  • Add a generic user messages module and use it for legacy histogram messaging.

Changes

Legacy histogram support

  • isLegacyHistogram helper (src/common/utils/legacy_histogram.ts): Returns true when both field type and instrument are 'histogram' (legacy histogram). Used for filtering, aggregation choice, and when to show user messages.
  • use_metric_fields (src/components/observability/metrics/hooks/use_metric_fields.ts): Skips a metric only when it is a histogram field but not a legacy histogram (metricField.type === 'histogram' && !isLegacyHistogram(metricField)). Legacy histograms are now included in the grid.
  • ES|QL aggregation (src/common/utils/esql/create_aggregation.ts): For legacy histogram, getAggregationTemplate returns PERCENTILE(TO_TDIGEST(??placeholder), 95) so the chart renders the 95th percentile. Other types (exponential_histogram, tdigest, counter, default) are unchanged.

Consumer-controlled user messages

  • MetricsGrid (src/components/observability/metrics/metrics_grid.tsx): Accepts only getUserMessages?: (metric: MetricField) => UserMessage[] | undefined. No userMessages prop. For each chart it passes userMessages={getUserMessages ? getUserMessages(metric) : undefined}. The shared component no longer branches on metric type; the consumer decides what to pass.
  • Metrics experience consumer (src/components/observability/metrics/metrics_experience_grid_content.tsx): Passes getUserMessages that returns LEGACY_HISTOGRAM_USER_MESSAGES when isLegacyHistogram(metric) is true, otherwise undefined. So messages are shown only for legacy histogram metrics, and the decision lives in the consumer.

User messages module

  • Generic user messages (src/common/utils/user_messages.ts): New module that exports LEGACY_HISTOGRAM_USER_MESSAGES (warning about T-Digest encoding). Re-exported from src/common/utils/index.ts. Other message sets can be added to this module later.

Tests

  • legacy_histogram.test.ts: Unit tests for isLegacyHistogram (true when type + instrument both histogram; false for histogram + other instrument, histogram + undefined, non-histogram type).
  • create_aggregation.test.ts: Tests for getAggregationTemplate including legacy histogram (returns PERCENTILE(TO_TDIGEST(...), 95)) and non-legacy histogram (returns AVG(...)). Existing tests for replaceFunctionParams and createTimeBucketAggregation remain.
  • metrics_grid.test.tsx: Removed the test that expected a userMessages prop. Kept the test that verifies getUserMessages(metric) is called per chart and its return value is passed to each chart.

How to test

  • ./forge --dataset histograms --count 5 --interval 10s --purge
  • check discover
Screen.Recording.2026-02-13.at.1.50.14.PM.mov

@kpatticha kpatticha marked this pull request as ready for review February 20, 2026 13:06
@kpatticha kpatticha requested a review from a team as a code owner February 20, 2026 13:06
@kpatticha kpatticha added backport:skip This PR does not require backporting v9.4.0 release_note:skip Skip the PR/issue when compiling release notes labels Feb 20, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 2081 2083 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 1.6MB 1.6MB +816.0B

History

Copy link
Copy Markdown
Contributor

@lucaslopezf lucaslopezf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! Could we add a test here for the legacy histogram, since we have for the other ones?

@kpatticha
Copy link
Copy Markdown
Contributor Author

Nice!! Could we add a test here for the legacy histogram, since we have for the other ones?

done: 326b36c

@kpatticha kpatticha enabled auto-merge (squash) February 20, 2026 16:04
@kpatticha kpatticha merged commit 6d945d9 into elastic:main Feb 20, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metrics][Discover] Support legacy histogram

3 participants