Skip to content
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

[Observability] Make Alerts page use shared Kibana time range #115192

Conversation

miltonhultgren
Copy link
Contributor

@miltonhultgren miltonhultgren commented Oct 15, 2021

Summary

Closes #111348

This PR does two things:

  1. Migrates the AlertsPage to use a stateContainer (https://github.com/elastic/kibana/tree/master/src/plugins/kibana_utils/docs/state_containers) which sync the state to the URL using URL state storage (https://github.com/elastic/kibana/tree/master/src/plugins/kibana_utils/docs/state_sync)
  2. Changes the AlertsPage to use the time range set in the data plugins timefilter service, and to push the selected time range into the timefilter service

Note: I'm still working on adding new E2E tests to test the new URL state and the timefilter service syncing.
We can consider merging this before FF and I can add those tests in a follow up PR.

Checklist

@miltonhultgren
Copy link
Contributor Author

@elasticmachine merge upstream

@miltonhultgren miltonhultgren self-assigned this Oct 18, 2021
@miltonhultgren miltonhultgren added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.16.0 v8.0.0 Feature:Observability RAC labels Oct 18, 2021
@miltonhultgren miltonhultgren marked this pull request as ready for review October 18, 2021 12:18
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@Kerry350 Kerry350 self-requested a review October 18, 2021 12:37
@miltonhultgren miltonhultgren added release_note:enhancement and removed release_note:skip Skip the PR/issue when compiling release notes labels Oct 18, 2021
@miltonhultgren miltonhultgren changed the title [Observability] Make Alerts page respect timefilter service range [Observability] Make Alerts page use shared Kibana time range Oct 18, 2021
@Kerry350
Copy link
Contributor

Functionality works well and as expected 👌

I'll take a look through the code now.

One question: I see the # are still in the URL, I think at one point you were talking with the Kibana app services team about the stateContainers usage. What was the verdict there?

Copy link
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Hopefully this can serve as a blueprint to using the stateContainer and stateStorage elsewhere (we've talked about it for logs code, for sure).

Comment on lines +114 to +117
timefilterService.setTime(dateRange);
setRangeFrom(dateRange.from);
setRangeTo(dateRange.to);
setKuery(query);
Copy link
Contributor

Choose a reason for hiding this comment

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

Much cleaner 👍


type AlertsPageStateContainer = typeof alertsPageStateContainer;

const { Provider, useContainer } = createStateContainerReactHelpers<AlertsPageStateContainer>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

(It's my first time reviewing the state container in a real world example, so it's nice to see there's some helpers and so on)

const timefilterService = useTimefilterService();

useEffect(() => {
const urlStateStorage = createKbnUrlStateStorage({ history, useHash: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Asked my question before seeing this 😅

So we shouldn't see the hash?

Copy link
Contributor Author

@miltonhultgren miltonhultgren Oct 19, 2021

Choose a reason for hiding this comment

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

This part is a bit confusing. The URL state storage helper offers to options: store the state plainly in the URL (Rison encoded) OR store it into sessionStorage but store the key of the session storage entry in the URL (the key is a hash).

This is still different from the sessionStorage helper which only stores the state into session storage but does not update the URL.

The # (hash) that gets added to the URL is added regardless which is causing issues in the tests and is a blocker right now. We need to decide how to work around that.
This message gives some hints on what might be required to fix that:
https://elastic.slack.com/archives/CFFQ7RP9B/p1634211896180000?thread_ts=1634207518.178700&cid=CFFQ7RP9B

So I see 3 paths:

  • Don't adopt the state container right now and just solve the issue in the ticket with the timefilter service (and create a ticket to follow up on the state containers to support history state as well)
  • Modify the FTR helpers to support this weird mix
  • Modify the state container to support history state

@Kerry350

@miltonhultgren
Copy link
Contributor Author

@Kerry350
After talking to Felix it seems it should be fairly easy to change the URL state storage to not use the hash (#), I'll spend today on that and hopefully have that working and tests passing by EOD :)

@miltonhultgren
Copy link
Contributor Author

@Dosant Can you have a look at the changes I made in src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.ts?

I still need to update the tests for those changes, but pushing this to get feedback from my team on some other things :)

@miltonhultgren miltonhultgren requested a review from a team as a code owner October 19, 2021 13:28
@@ -191,6 +191,25 @@ describe('KbnUrlStateStorage', () => {
});
});

describe('useHashQuery: true', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure which other tests need to be mirrored from the default false case, or if there are some other cases to test, please advice :) @Dosant

Copy link
Contributor

Choose a reason for hiding this comment

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

If it isn't too much burden, let's mirror KbnUrlStateStorage > useHash: false 🙏

Copy link
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

Added a couple of small nitpicks on the tests, feel free to ignore if you want. You mentioned they felt a bit messy, but they look good, great job 👍

I'm still waiting for Kibana to build right now to test the functionality again ⏳

Copy link
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

Screenshot 2021-10-20 at 11 42 58

Beautiful! Hash be gone 🎉

Synchronisation all seems to work as expected.

Thanks for persevering with these changes and getting this over the line with the improved behaviour.

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

I tested, didn't find any issues without # in the URL. thanks for this improvement 👍

@@ -191,6 +191,25 @@ describe('KbnUrlStateStorage', () => {
});
});

describe('useHashQuery: true', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it isn't too much burden, let's mirror KbnUrlStateStorage > useHash: false 🙏

...history.location,
search: nextSearchParams.toString(),
});
timefilterService.setTime(dateRange);
Copy link
Contributor

Choose a reason for hiding this comment

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

it is also possible to subscribe to state container changes and update global time there. This way timefilterService will stay in sync with state container even if dateRange is updated from other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, there are some business requirements around defaults on page load that prevents us from doing that in this case though!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
observability 377 380 +3

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
kibanaUtils 413 414 +1

Async chunks

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

id before after diff
observability 383.9KB 384.8KB +920.0B

Page load bundle

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

id before after diff
kibanaUtils 72.0KB 72.1KB +102.0B
Unknown metric groups

API count

id before after diff
kibanaUtils 606 607 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @miltonhultgren

@miltonhultgren miltonhultgren merged commit 331e76b into elastic:master Oct 21, 2021
@kibanamachine
Copy link
Contributor

💔 Backport failed

The backport operation could not be completed due to the following error:
There are no branches to backport to. Aborting.

The backport PRs will be merged automatically after passing CI.

To backport manually run:
node scripts/backport --pr 115192

@mgiota
Copy link
Contributor

mgiota commented Oct 21, 2021

@miltonhultgren Backport failed for this PR. Could you have a look?

@miltonhultgren miltonhultgren removed the auto-backport Deprecated - use backport:version if exact versions are needed label Oct 21, 2021
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Oct 25, 2021
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 115192 or prevent reminders by adding the backport:skip label.

@weltenwort
Copy link
Member

I think the idea is to not backport this since it's a new feature.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 115192 or prevent reminders by adding the backport:skip label.

1 similar comment
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 115192 or prevent reminders by adding the backport:skip label.

@weltenwort weltenwort added backport:skip This commit does not require backporting and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Oct 27, 2021
@KOTungseth KOTungseth added the Feature:Logs UI Logs UI feature label Oct 27, 2021
hop-dev added a commit to kibanamachine/kibana that referenced this pull request Nov 9, 2021
Backport @miltonhultgren's changes to add the `useHashQuery` param to `createKbnUrlStateStorage`

Co-authored-by: Milton Hultgren <milton.hultgren@elastic.co>
hop-dev added a commit that referenced this pull request Nov 11, 2021
…117568)

* [Fleet] Fix agent logs not reading query from URL (#117286)

* Don't use hash for agent logs url state

* revert core app services change

* Cherrypick changes from PR #115192

Backport @miltonhultgren's changes to add the `useHashQuery` param to `createKbnUrlStateStorage`

Co-authored-by: Milton Hultgren <milton.hultgren@elastic.co>

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
Co-authored-by: Milton Hultgren <milton.hultgren@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Logs UI Logs UI feature Feature:Observability RAC release_note:enhancement Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAC] Observability alerts view: timeframe should be synced across Observability
8 participants