Skip to content

[APM] Ensure refresh button works#112652

Merged
dgieselaar merged 15 commits intoelastic:masterfrom
dgieselaar:time-range-refresh
Oct 6, 2021
Merged

[APM] Ensure refresh button works#112652
dgieselaar merged 15 commits intoelastic:masterfrom
dgieselaar:time-range-refresh

Conversation

@dgieselaar
Copy link
Contributor

@dgieselaar dgieselaar commented Sep 21, 2021

Closes #110465.

After some routing changes, the refresh button no longer works, due to the DatePicker component and useFetcher using different ways to invalidate the current time range. This PR addresses that issue by:

  • Separating the date pickers for the APM app and the UX dashboard, as the former uses the new router, and the latter uses URLParamsContext
  • Create a useDateRangeRedirect which returns a redirect function and a isDateRangeSet property
  • For the APM date picker, when refresh is clicked, call incrementTimeRangeId from the useTimeRangeId hook, which is also used by useFetcher to refresh data
  • For the UX dashboard date picker, use refreshTimeRange from useUxUrlParams, and useDateRangeRedirect
  • wrap the APM app in a RedirectWithDefaultDateRange component, which uses a newly implemented getRoutesToMatch function, that returns the routes that are expected to match, without validating the query parameters. This enables us to intercept invalid routes before they are rendered, and redirect, without rendering child components that expect valid & parsed routing parameters

@dgieselaar dgieselaar added Team:APM - DEPRECATED Use Team:obs-ux-infra_services. release_note:skip Skip the PR/issue when compiling release notes v7.16.0 labels Sep 21, 2021
Comment on lines +27 to +35
return (
route.path === '/services' ||
route.path === '/traces' ||
route.path === '/service-map' ||
route.path === '/backends' ||
route.path === '/services/{serviceName}' ||
location.pathname === '/' ||
location.pathname === ''
);
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 isn't great. Ideally this would be a property of the route, as the route itself is disconnected from setting the default parameters. I've considered some alternatives, but they come at a cost. One issue is that the date range defaults are (AFAIK) only available via a hook, so we have to render a React element to get the appropriate defaults. We can't easily use a middleware layer for that reason (e.g. onRouteActivate). One option would be to allow the route to specify a pre element that gets rendered as an immediate child of RouterProvider, before any other elements, that can block rendering of child routes. That's a little bit of a weird API though, and I think we should wait for more use cases before implementing it.

@dgieselaar dgieselaar marked this pull request as ready for review September 22, 2021 09:20
@dgieselaar dgieselaar requested a review from a team September 22, 2021 09:20
@dgieselaar dgieselaar requested a review from a team as a code owner September 22, 2021 09:20
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

Copy link
Contributor

@justinkambic justinkambic left a comment

Choose a reason for hiding this comment

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

UX changes LGTM

@botelastic botelastic bot added the Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability label Sep 22, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

@dgieselaar
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

a few suggestions

Comment on lines +48 to +50
const refreshPaused = refreshPausedFromUrl
? toBoolean(refreshPausedFromUrl)
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

do you really need this check? you're adding a default value to refreshPausedFromUrl o line 44, so it'll never be undefined, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks!

Comment on lines +51 to +53
const refreshInterval = refreshIntervalFromUrl
? toNumber(refreshIntervalFromUrl)
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks!

refreshPaused={refreshPaused}
refreshInterval={refreshInterval}
onTimeRangeRefresh={() => {
incrementTimeRangeId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really the responsibility of who calls DatePicker to call incrementTimeRangeId? I would expect that the DatePicker component to handle it automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DatePicker component itself is being used by the UX app as well, and they're using urlParams still. So we have APMDatePicker and RUMDatePicker that each deal with date picker state differently.

import { TimePickerTimeDefaults } from '../components/shared/DatePicker/typings';
import { useApmPluginContext } from '../context/apm_plugin/use_apm_plugin_context';

export function useDateRangeRedirect() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a hook that handles time range useTimeRange do you think we could centralize this change in one single hook? does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They serve different purposes, useTimeRange gets the (parsed) range parameters from the url and expects the apm client router to be used, this one checks whether the date range is set in the URL, and can be used by both the APM app and the UX app.

Copy link
Member

@sorenlouv sorenlouv Oct 5, 2021

Choose a reason for hiding this comment

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

Why is it necessary for the date range to be set in the url - as @cauemarcondes says, can't we just get the date from useTimeRange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed with @sqren in AON, we agreed this is ok for now but we will look into whether we can make these query parameters optional and use the kibana date store as the single source of truth.

import { useApmRouter } from '../../../hooks/use_apm_router';
import { useDateRangeRedirect } from '../../../hooks/use_date_range_redirect';

export function RedirectWithDefaultDateRange({
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a description to this. The purpose of this function was not clear to me until I read the PR description.

Perhaps some like:

// intercept invalid routes before they are rendered, and redirect, without rendering child components that expect valid & parsed routing parameters

Copy link
Member

Choose a reason for hiding this comment

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

I'm also wondering what an "invalid route" is in this context. Are we specifically referring to routes that require date range and don't have it? And isn't this something io-ts can handle for us?

Comment on lines +98 to +100
onRefresh={() => {
onRefreshTimeRange();
}}
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit (just to keep in consistent with the other handlers)

Suggested change
onRefresh={() => {
onRefreshTimeRange();
}}
onRefresh={onRefreshTimeRange}

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1174 1177 +3

Async chunks

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

id before after diff
apm 2.7MB 2.7MB +1.6KB
observability 355.2KB 355.2KB -7.0B
total +1.6KB

History

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

@dgieselaar dgieselaar dismissed cauemarcondes’s stale review October 6, 2021 11:02

feedback addressed

@dgieselaar dgieselaar added the auto-backport Deprecated - use backport:version if exact versions are needed label Oct 6, 2021
@dgieselaar dgieselaar merged commit 6aade8f into elastic:master Oct 6, 2021
@dgieselaar dgieselaar deleted the time-range-refresh branch October 6, 2021 11:03
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Oct 6, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 6, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co>
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 release_note:skip Skip the PR/issue when compiling release notes Team:APM - DEPRECATED Use Team:obs-ux-infra_services. Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v7.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[APM] Refresh no longer works

6 participants