-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAC] Link inventory alerts to the right inventory view #113553
[RAC] Link inventory alerts to the right inventory view #113553
Conversation
a857bf4
to
3a49cd8
Compare
6da0f21
to
269f813
Compare
Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui) |
import { parse } from 'query-string'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
// FIXME what would be the right way to build this query string? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we cannot find a good way in this PR we can address this later.
If I recall correctly Kibana provides a service already to create good URLs? Maybe it's worth leaving this as is and wait until that service is used in Metrics to update this code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to use the useKibana
hook to get ahold of the application
service like this:
const kibana = useKibana<InfraClientSetupDeps>();
const link = kibana.services.application?.getUrlForApp('infra', { path: `/inventory${inventoryQueryString}` });
As for the QUERY_STRING_TEMPLATE
what you're doing is probably fine BUT if we wanted to make sure the Rison is serialized correctly, we could use the Rison library to encode
the objects (like you did for the custom metric).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more concerned about what happens if/when the parameters in the URL change. It feels I'm duplicating things here and it's just a matter of time until it gets changed somewhere else and this breaks.
Is there something in metrics to generate valid URLs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, apparently the <Redirect />
component where this link is used is handling already the app prefix. When I use getUrlForApp
the end result is /guk/app/metrics/guk/app/infra/inventory
(when using infra
as an app).
I think moving forward it's better to leave the code as it is now (revisiting how the query string is constructed). What do you think @simianhacker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
|
||
const condition = schema.object({ | ||
threshold: schema.arrayOf(schema.number()), | ||
comparator: oneOfLiterals(Object.values(Comparator)), | ||
timeUnit: schema.string(), | ||
comparator: oneOfLiterals(Object.values(Comparator)) as Type<Comparator>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these type assertions are necessary to make the kibana schema play nicely with the io-ts generated types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me. I added some inline comments about using getUrlForApp
to generate the URLs.
import { parse } from 'query-string'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
// FIXME what would be the right way to build this query string? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to use the useKibana
hook to get ahold of the application
service like this:
const kibana = useKibana<InfraClientSetupDeps>();
const link = kibana.services.application?.getUrlForApp('infra', { path: `/inventory${inventoryQueryString}` });
As for the QUERY_STRING_TEMPLATE
what you're doing is probably fine BUT if we wanted to make sure the Rison is serialized correctly, we could use the Rison library to encode
the objects (like you did for the custom metric).
const link = '/app/metrics/inventory'; // TODO https://github.com/elastic/kibana/issues/106497 | ||
const ruleParams = parseRuleParams(fields[ALERT_RULE_PARAMS]); | ||
|
||
let link = '/app/metrics/link-to/inventory?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use getUrlForApp
here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used within a React context so calling useKibana
is not possible. I'm looking how easy is to inject the kibana services and it's not that straightforward.
The link is correctly prefixed when used (the prepend()
call in the linked code), so I wonder if that's good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shakes fist at sky "Damn you hooks!"
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ _____ _______ __ __
| | / ____|__ __| \/ |
| | | | __ | | | \ / |
| | | | |_ | | | | |\/| |
| |___| |__| | | | | | | |
|______\_____| |_| |_| |_|
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
Co-authored-by: Kibana Machine <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…-link-to-kibana-app * 'master' of github.com:elastic/kibana: (287 commits) [Security Solution][Endpoint] Change `trustedAppByPolicyEnabled` flag to `true` by default (elastic#115264) [APM] generator: support error events and application metrics (elastic#115311) [kibanaUtils] Don't import full `semver` client side (elastic#114986) [RAC] Link inventory alerts to the right inventory view (elastic#113553) [Uptime] Added uptime query inspector panel (elastic#115170) [Osquery] Add packs (elastic#107345) [App Search] Allow for query parameter to indicate ingestion mechanism for new engines (elastic#115188) [Alerting] Active alerts do not recover after re-enabling a rule (elastic#111671) skip flaky tests. elastic#115308, elastic#115313 [Breaking] Remove deprecated `enabled` settings from plugins. (elastic#113495) skip flaky suite. elastic#107057 skip flaky tests. elastic#89052, elastic#113418, elastic#115304 skip flaky test. elastic#113892 Bump node to 16.11.1 (elastic#110684) [Security Solution] Restores Alerts table local storage persistence and the Remove Column action (elastic#114742) skip flaky suite. elastic#115130 one line remove assert (elastic#115127) Fixes migration bug where I was deleting attributes (elastic#115098) [Security Solutions] Fixes the newer notification system throttle resets and enabling immediate execution on first detection of a signal (elastic#114214) [build] Dockerfile update (elastic#115237) ... # Conflicts: # x-pack/plugins/reporting/public/management/__snapshots__/report_listing.test.tsx.snap
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…15332) Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Alejandro Fernández Gómez <[email protected]>
Closes #106497.
For @elastic/metrics-ui, what would be the right way to generate the URL for the inventory view?