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

Remove comparisonStart and comparisonEnd from API endpoints #127812

Merged
merged 11 commits into from
Mar 28, 2022

Conversation

gbamparop
Copy link
Contributor

@gbamparop gbamparop commented Mar 15, 2022

Summary

  • Replace comparisonStart and comparisonEnd with offset in all the API endpoints
  • Replace comparisonType url param with offset so the helper is no longer used

Closes #127307

@gbamparop gbamparop added Team:APM All issues that need APM UI Team support release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.2.0 labels Mar 15, 2022
@gbamparop gbamparop force-pushed the comparison-date-improvements branch from 26f4c25 to a585624 Compare March 16, 2022 09:14
@gbamparop
Copy link
Contributor Author

Buildkite, test this

@gbamparop
Copy link
Contributor Author

@elasticmachine merge upstream

@gbamparop gbamparop force-pushed the comparison-date-improvements branch 2 times, most recently from 682a2c8 to 80f5d27 Compare March 17, 2022 16:26
@ogupte
Copy link
Contributor

ogupte commented Mar 17, 2022

I wonder if it makes sense to remove comparisonEnabled as well...It seems like we could just assume that if offset has a value, then comparisons are enabled. What do you think?

@gbamparop
Copy link
Contributor Author

gbamparop commented Mar 18, 2022

I wonder if it makes sense to remove comparisonEnabled as well...It seems like we could just assume that if offset has a value, then comparisons are enabled. What do you think?

@ogupte That's a good point, we've discussed it with @sqren before. In this case we'll need to store the selected option somewhere. I could do it with local state but we'll lose the previously selected option when navigating away e.g.

  • Select an option (other than default) from the comparison select
  • Disable comparison
  • Navigate to a page that doesn't have the comparison select
  • Navigate to a page that has the comparison select
  • Comparison is still disabled but the default option is selected

Created #128146

@gbamparop gbamparop marked this pull request as ready for review March 21, 2022 11:55
@gbamparop gbamparop requested a review from a team as a code owner March 21, 2022 11:55
@elasticmachine
Copy link
Contributor

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

@gbamparop
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@dgieselaar dgieselaar left a comment

Choose a reason for hiding this comment

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

I think this is a great change! Makes things simpler. I see that we (probably me) implemented offset as "time difference moving backwards", but I think it should be the other way around, e.g. 1d should be one day in the future, and -1d should be one day into the past. What do you think? I haven't reviewed all of it, would like to wait until we have figured that question out, and the redirects.

rangeTo: rangeTo as string,
});

const momentStart = moment(start);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of getting rangeFrom / rangeTo and calculating the diff I can just map TimeRangeComparisonEnum.DayBefore to 1d and TimeRangeComparisonEnum.WeekBefore to 1w. Then the value is PeriodBefore we don't have any other options which means even without redirects we will still get the default value. @dgieselaar WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

sgtm, although I'm not sure how that helps with redirect - if users have bookmarks or whatever it will still include the literal string no? am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would still calculate the right offset because it'll be the default option, but comparisonType=period will remain in the url. I only mentioned it as it'll simplified the redirect a bit. I'm find to leave it as is if you think it looks ok.

Copy link
Member

Choose a reason for hiding this comment

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

oh I see now I think, I assumed you were talking about changing the value of the enum. You're talking about mapping it here? would that also remove the need to call getSelectOptions below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would be removed. It'll be like if (comparisonType === 'day') offset = '1d') (same for the week). For period we just leave it continue and the time comparison component will calculate the default.

Copy link
Member

Choose a reason for hiding this comment

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

sgtm 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in de4d405

@gbamparop
Copy link
Contributor Author

I think it should be the other way around, e.g. 1d should be one day in the future, and -1d should be one day into the past. What do you think?

That could be an improvement, although I don't necessarily think there's a big issue with what we have right now. Do you think that's something we could raise and address in a follow up?

@dgieselaar
Copy link
Member

That could be an improvement, although I don't necessarily think there's a big issue with what we have right now. Do you think that's something we could raise and address in a follow up?

Sounds good to me, I don't think it's that much of an issue and there's some work involved flipping all the offsets around. No need to make an issue AFAIC either.

Comment on lines 31 to 40
return (
route.path === '/services' ||
route.path === '/traces' ||
route.path === '/service-map' ||
route.path === '/backends' ||
route.path === '/services/{serviceName}' ||
route.path === '/service-groups' ||
location.pathname === '/' ||
location.pathname === ''
);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should extract this into a function, something like isRouteWithTimeRange()? I think we're using it somewhere else too. I'm not a fan (I can say that because I wrote it) but I don't really have a better way of doing this right now.

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 shout, indeed it's being used here as well. I can extract it to a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 9337e5d

const momentStart = moment(start);
const momentEnd = moment(end);

const offset = getSelectOptions({
Copy link
Member

Choose a reason for hiding this comment

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

nit: perhaps the relevant part should be abstracted out of the getSelectOptions function, calling this here seems kind of odd.

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 another option in #127812 (comment)

@@ -41,13 +41,13 @@ export function TimeComparison() {
const { start, end } = useTimeRange({ rangeFrom, rangeTo });

const {
urlParams: { comparisonEnabled, comparisonType },
urlParams: { comparisonEnabled, offset },
Copy link
Member

Choose a reason for hiding this comment

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

any reason why we're still getting this from useLegacyUrlParams()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've discussed this previously here #126567 (comment). Basically if we get it from apm params it'll be false the first time instead of undefined and we wouldn't know if it was actually in the url or we should query the advanced settings. Will the redirect you've suggested overcome this issue?

Copy link
Member

@dgieselaar dgieselaar Mar 24, 2022

Choose a reason for hiding this comment

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

Are you referring to comparisonEnabled or offset? I was referring to the latter. I'm hoping we can make comparisonEnabled required and redirect in RedirectWithOffset when taking the value of the Kibana Advanced Setting into account - would that 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.

I was referring to comparisonEnabled. Removed the call to useLegacyUrlParams, made comparisonEnabled required and added redirect in f0c8d72.

Comment on lines 50 to 51
if (comparisonEnabled === undefined || offset === undefined) {
urlHelpers.replace(history, {
Copy link
Member

Choose a reason for hiding this comment

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

do we still need this redirect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it in f0c8d72 as we now redirect from RedirectWithOffset

@gbamparop gbamparop force-pushed the comparison-date-improvements branch from 6adb314 to 9337e5d Compare March 24, 2022 11:59

if (
matchesRoute &&
('comparisonType' in query || !('comparisonEnabled' in query))
Copy link
Member

Choose a reason for hiding this comment

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

this is a little hard for me to parse, do you mind leaving a comment why we're redirecting in this scenario? (IIRC, we redirect if comparisonType is set, because we no longer support it, and we redirect if comparisonEnabled is not set, because it is now required)

url: location.pathname,
query: {
comparisonEnabled,
offset: dayAndWeekBeforeToOffsetMap[comparisonTypeEnumValue] ?? '',
Copy link
Member

Choose a reason for hiding this comment

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

what happens if we set offset to an empty string? is offset optional? (if it is required I don't think we should set it to an empty string)

Copy link
Contributor Author

@gbamparop gbamparop Mar 28, 2022

Choose a reason for hiding this comment

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

Offset is optional, we set it to empty string if comparisonType is not day or week. TimeComparison component then switches to the default offset for the current time range.

Copy link
Member

Choose a reason for hiding this comment

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

ok, should we maybe remove it then from the query entirely? either way this looks fine to me then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated so we add it to the query only if it's day or week.

}

export const dayAndWeekBeforeToOffsetMap = {
Copy link
Member

Choose a reason for hiding this comment

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

maybe a little verbose? just a nit though.

Copy link
Member

@dgieselaar dgieselaar left a comment

Choose a reason for hiding this comment

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

Thanks! I think this cleans up nicely. I left a couple of comments, perhaps the one about offset being an empty string requires a good look, but looks good other than that.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1182 1185 +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.9MB 2.9MB -1.7KB

History

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

@gbamparop gbamparop merged commit c059ead into elastic:main Mar 28, 2022
@gbamparop gbamparop added apm:test-plan-done Pull request that was successfully tested during the test plan and removed apm:test-plan-done Pull request that was successfully tested during the test plan labels Apr 4, 2022
@gbamparop gbamparop deleted the comparison-date-improvements branch April 12, 2022 09:44
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:APM All issues that need APM UI Team support v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Simplify the use of comparison dates by the API endpoints
5 participants