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

[RAC] Link inventory alerts to the right inventory view #113553

Merged
merged 6 commits into from
Oct 18, 2021

Conversation

afgomez
Copy link
Contributor

@afgomez afgomez commented Sep 30, 2021

Closes #106497.

For @elastic/metrics-ui, what would be the right way to generate the URL for the inventory view?

@afgomez afgomez added v8.0.0 Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed v7.16.0 Feature:Observability RAC labels Sep 30, 2021
@afgomez afgomez force-pushed the 106497-inventory-alert-link-to-app branch 4 times, most recently from a857bf4 to 3a49cd8 Compare October 7, 2021 12:45
@afgomez afgomez force-pushed the 106497-inventory-alert-link-to-app branch from 6da0f21 to 269f813 Compare October 11, 2021 08:53
@afgomez afgomez marked this pull request as ready for review October 11, 2021 09:39
@afgomez afgomez requested a review from a team as a code owner October 11, 2021 09:39
@elasticmachine
Copy link
Contributor

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?
Copy link
Contributor Author

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

Copy link
Member

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).

Copy link
Contributor Author

@afgomez afgomez Oct 14, 2021

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?

Copy link
Contributor Author

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?

Copy link
Member

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>,
Copy link
Contributor Author

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.

@simianhacker simianhacker self-requested a review October 12, 2021 16:21
Copy link
Member

@simianhacker simianhacker left a 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?
Copy link
Member

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?';
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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!"

@afgomez afgomez requested a review from simianhacker October 14, 2021 11:46
@afgomez
Copy link
Contributor Author

afgomez commented Oct 14, 2021

@elasticmachine merge upstream

Copy link
Member

@simianhacker simianhacker left a comment

Choose a reason for hiding this comment

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

  _      _____ _______ __  __ 
 | |    / ____|__   __|  \/  |
 | |   | |  __   | |  | \  / |
 | |   | | |_ |  | |  | |\/| |
 | |___| |__| |  | |  | |  | |
 |______\_____|  |_|  |_|  |_|
                              
                              

@afgomez
Copy link
Contributor Author

afgomez commented Oct 18, 2021

@elasticmachine merge upstream

@afgomez afgomez enabled auto-merge (squash) October 18, 2021 07:58
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 964 965 +1

Async chunks

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

id before after diff
infra 938.5KB 939.3KB +819.0B

Page load bundle

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

id before after diff
infra 90.2KB 90.6KB +451.0B

History

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

@afgomez afgomez merged commit 27c7c6f into elastic:master Oct 18, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Oct 18, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

jloleysens added a commit to jloleysens/kibana that referenced this pull request Oct 18, 2021
…-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
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Oct 20, 2021
@kibanamachine
Copy link
Contributor

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.

kibanamachine added a commit that referenced this pull request Oct 20, 2021
…15332)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Alejandro Fernández Gómez <[email protected]>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Observability RAC 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAC][Metrics UI] Link to an inventory item with the flyout open at a certain point in time
4 participants