Skip to content

[8.19] [Lens] "Compare to" badge for Metric chart (#214811)#221709

Merged
nickofthyme merged 7 commits intoelastic:8.19from
nickofthyme:backport/8.19/pr-214811
Jun 3, 2025
Merged

[8.19] [Lens] "Compare to" badge for Metric chart (#214811)#221709
nickofthyme merged 7 commits intoelastic:8.19from
nickofthyme:backport/8.19/pr-214811

Conversation

@nickofthyme
Copy link
Contributor

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

@nickofthyme nickofthyme added the backport This PR is a backport of another PR label May 27, 2025
@nickofthyme nickofthyme enabled auto-merge (squash) May 27, 2025 21:30
Fixes elastic#184907

This PR introduces the Trend badge feature into the Secondary Metric
chart type.
<img width="1318" alt="Screenshot 2025-04-30 at 13 04 36"
src="https://github.com/user-attachments/assets/6b3c599e-304f-4bc0-8ff2-094ed54ea248"
/>
<img width="1503" alt="Screenshot 2025-04-30 at 13 04 03"
src="https://github.com/user-attachments/assets/cb203156-a7a8-4f61-bf30-57f7d1484fed"
/>
<img width="1339" alt="Screenshot 2025-04-30 at 13 03 21"
src="https://github.com/user-attachments/assets/8896af7f-9193-41b5-a4b5-970907b084c5"
/>
<img width="1319" alt="Screenshot 2025-04-30 at 13 05 34"
src="https://github.com/user-attachments/assets/12aa556e-8743-4167-9902-14fa9ef2e85d"
/>

Here's a short list of tasks handled by this PR:

* [x] New Color by value option: `None` | `Static` | `Dynamic`
  * Default `None` option is the default (legacy preserved)
  * [x] `Static` option enables the badge with the picked color
* [x] this is also enforced when the Primary metric is not number based
(or when primary transition from number to text)
  * [x] `Dynamic` option enables both the badge coloring and the icon
* [x] When disabled a tooltip with the explanation of the issue appears
    * [x] Trend palette is enabled by default on enable
* [x] Added other 3 extra palettes (`Reversed`, `Temperature`,
`Complementary`)
* [x] Each palette has been implemented using both EUI tokens AND Vis
tokens
          * [x] Revisited this decision ♻️
        * [x] Remove redundant palettes
          * ~~keep only Vis palettes & hardcode `green` value for now.~~
* ~~Once EUI exposes the green token integrate in a follow up.~~
* Use the `@kbn/palettes` service with the new `compare_to` palette with
hardcoded values
      * [x] Exposes display options: `Icon` | `Value` | `Both`
        * [x] `Both` is the default
* [x] `Icon` or `Both` will show up 3 possible icon options: arrow up,
arrow down and equal sign from unicode
          * [x]  Make sure both text and icon respect breakpoint sizes
* [x] Remove hack for breakpoints ( Lens Embeddable + Secondary metric)
once new Charts upgrade is merged:
elastic/elastic-charts#2627
* [x] Remove `theme` and contrast color computation once the Elastic
Charts PR above is merged
          * [x] Make sure badge is always accessible
        * [x] Exposes Trend options: `Static value` | `Primary metric`
* [x] `Static value` will show up a new `Baseline` control (debounced)
* [x] `Primary metric` is enabled only for numeric primary values
            * [x]  When disabled a tooltip shows up explaining the issue
* [x] Added description text to explain difference with the other
compare mode
            * [x] Show only delta value when in Primary
 * [x] Migrated existing `metric_vis` tests from Enzyme to RTL
 * [x] New tests for the new Secondary metric component in RTL
* [x] Added new smoketest + panel mode caching testing for the metric
feature in FTR

Few aspects of this feature have been discussed and deferred to a follow
up issue: elastic#217992

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Nick Partridge <nick.ryan.partridge@gmail.com>
@nickofthyme nickofthyme force-pushed the backport/8.19/pr-214811 branch from 0a571ba to 94af340 Compare June 2, 2025 17:26
@elastic elastic deleted a comment from elasticmachine Jun 2, 2025
);
}
return formattedValue;
return formattedValue ?? null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason this does not matter in main but here returning undefined triggers this error...

SecondaryMetricValue(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
// Test id is the last resource here as the element will be empty
const el = screen.getByTestId('metric-secondary-element');
expect(el).toBeEmptyDOMElement();
expect(el).toContainHTML('');
Copy link
Contributor Author

@nickofthyme nickofthyme Jun 3, 2025

Choose a reason for hiding this comment

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

This element is returning this...

<span
  data-test-subj="metric-secondary-element"
>
      
      
</span>

Which according to the toBeEmptyDOMElement docs...

It ignores comments but will fail if the element contains white-space.

Replaced with toContainHTML.

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #77 / Actions and Triggers app create alert should create an alert with composite query in filter for conditional action

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
charts 155 156 +1
eventAnnotationListing 600 601 +1
expressionHeatmap 187 188 +1
expressionMetricVis 127 130 +3
expressionPartitionVis 198 199 +1
expressionTagcloud 176 177 +1
expressionXY 247 248 +1
lens 1425 1427 +2
observability 1311 1312 +1
visDefaultEditor 224 225 +1
visTypeTimeseries 403 404 +1
total +14

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressionMetricVis 75 81 +6
lens 556 560 +4
total +10

Async chunks

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

id before after diff
charts 13.3KB 13.5KB +217.0B
expressionMetricVis 5.2KB 8.1KB +2.9KB
expressionPartitionVis 33.1KB 33.3KB +219.0B
expressionTagcloud 17.2KB 17.4KB +217.0B
expressionXY 95.2KB 95.4KB +217.0B
lens 1.5MB 1.5MB +8.9KB
total +12.7KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 60 62 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressionMetricVis 14.6KB 15.5KB +927.0B
lens 59.6KB 59.6KB +14.0B
total +941.0B
Unknown metric groups

API count

id before after diff
expressionMetricVis 75 81 +6
lens 655 659 +4
total +10

History

@nickofthyme nickofthyme merged commit fdf3a43 into elastic:8.19 Jun 3, 2025
8 checks passed
@nickofthyme nickofthyme deleted the backport/8.19/pr-214811 branch June 3, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

5 participants