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

[Actionable Observability] save alerts config in different localStorage key for overview and ale… #130538

Merged
merged 6 commits into from
Apr 25, 2022

Conversation

mgiota
Copy link
Contributor

@mgiota mgiota commented Apr 19, 2022

Fixes #126765

@mgiota mgiota requested review from a team as code owners April 19, 2022 09:36
@mgiota mgiota self-assigned this Apr 19, 2022
@mgiota mgiota added Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" v8.3.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 19, 2022
@mgiota mgiota enabled auto-merge (squash) April 19, 2022 12:56
@@ -311,7 +310,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {

const [flyoutAlert, setFlyoutAlert] = useState<TopAlert | undefined>(undefined);
const [tGridState, setTGridState] = useState<Partial<TGridModel> | null>(
JSON.parse(localStorage.getItem(ALERT_TABLE_STATE_STORAGE_KEY) ?? 'null')
JSON.parse(localStorage.getItem(stateStorageKey) ?? 'null')
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't unsafe to parse JSON without a try/catch block? I believe there is a helper/util in Kibana that handles that. /src/plugins/kibana_utils/public/storage/storage.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok let me check it

Copy link
Contributor Author

@mgiota mgiota Apr 21, 2022

Choose a reason for hiding this comment

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

@fkanout I made a quick search in the whole project for imports of kibana_utils/public/storage, but I didn't find anything. So I was wondering how I should properly use Storage from this file. My guess is that it should be part of a kbn pacakge? Do you have any idea? I can simply try to import this file, but I didn't find any other imports of it in the whole project, that's why I am wondering if there is a proper way to do it.

Copy link
Contributor Author

@mgiota mgiota Apr 21, 2022

Choose a reason for hiding this comment

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

Ok I found something. Here's how I can import it import { IStorage, Storage } from '@kbn/kibana-utils-plugin/public';. This is a very recent change from kibana-operations team on how we can import stuff. This change would require a bit more refactoring. Should it be part of this PR?

Copy link
Contributor Author

@mgiota mgiota Apr 21, 2022

Choose a reason for hiding this comment

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

@fkanout In the end I did the refactoring as part of this PR d12eeea.

@estermv Since I had to change one of your files as part of this refactoring, let me know if everything looks fine

@@ -195,6 +195,7 @@ export function OverviewPage({ routeParams }: Props) {
rangeFrom={relativeStart}
rangeTo={relativeEnd}
indexNames={indexNames}
stateStorageKey="xpack.observability.overview.alert.tableState"
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't better to share this hardcoded value in a commonplace then be used here and there https://github.com/elastic/kibana/pull/130538/files#diff-ab4cbe22bf9a1c9bbaf3a3cb32b5aa5b0c8b8e33c34b88ed3c99dbde6fedadb9R333

Copy link
Contributor

Choose a reason for hiding this comment

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

The values are different (unless they are used somewhere else that I missed) so I wouldn't put them in a commonplace until they are duplicated somewhere. The only thing I would suggest is to put that in a constant at the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fkanout Thanks for the feedback. That's the whole point of this fix. Let me explain more. Before my fix the localStorage key was shared between overview and alerts page (xpack.observability.alert.tableState) and this was causing the alerts table columns bug explained in this issue.

With my current change I introduced two different localStorage keys xpack.observability.alert.tableState and xpack.observability.overview.alert.tableState for alerts page and overview page accordingly.

@estermv I can put the keys in a constant at the top of the files.

if (newState !== localStorage.getItem(ALERT_TABLE_STATE_STORAGE_KEY)) {
localStorage.setItem(ALERT_TABLE_STATE_STORAGE_KEY, newState);
if (newState !== localStorage.getItem(stateStorageKey)) {
localStorage.setItem(stateStorageKey, newState);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you help me understand why we keep altering the localStorage value for the alert table? Like this aren't we changing the o11y alerts table settings to match the other TGrid settings which we don't want?

Copy link
Contributor Author

@mgiota mgiota Apr 21, 2022

Choose a reason for hiding this comment

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

@fkanout Sure I'll try to explain. Short answer is we keep altering the localStorage value to reflect the user UI changes (for example visible columns or sorting column).

The only change I did here was to:

So now the two consumers alerts page and old overview page pass the prop to the AlertsTableTGrid component. and a different localStorage key is used for the two pages to keep track of the user specified settings. Nothing else changed in the previous logic, just the parameterization of the localStorage key.

Regarding the existing localStorage functionality (which didn't change in this PR) it works in a way that when the tGridState is changed, it will update the localStorage to the new user settings, if they are of course different from what is currently saved in that localStorage key. tGridState will be changed when any of the following is changed onStateChange (columns, sort, selectedEventIds). You can play around a bit with the UI and change table columns or sorting for example and see what is saved in localStorage.

Does it make sense?

@mgiota
Copy link
Contributor Author

mgiota commented Apr 21, 2022

@elasticmachine merge upstream

@mgiota mgiota requested a review from fkanout April 21, 2022 11:02
@mgiota
Copy link
Contributor Author

mgiota commented Apr 25, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
observability 427.3KB 427.4KB +81.0B

History

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

cc @mgiota

Copy link
Contributor

@fkanout fkanout left a comment

Choose a reason for hiding this comment

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

LGTM

@mgiota mgiota merged commit 20bba8d into elastic:main Apr 25, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 25, 2022
@mgiota mgiota deleted the 126765_reset_fields_fix branch May 10, 2022 08:45
kertal pushed a commit to kertal/kibana that referenced this pull request May 24, 2022
…ge key for overview and ale… (elastic#130538)

* save alerts config in different localStorage key for overview and alerts page

* remove ALERT_TABLE_STATE_STORAGE_KEY
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 release_note:skip Skip the PR/issue when compiling release notes Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alerts table will reset fields to a different table config that the default
5 participants