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

[APM] Immediately return terms for unbound queries #74543

Merged
merged 7 commits into from
Sep 2, 2020

Conversation

dgieselaar
Copy link
Member

@dgieselaar dgieselaar commented Aug 6, 2020

Closes #73787 and #58591.

I'm not entirely sold. It will for instance return terms for deleted services. I'll look at some telemetry to get a feeling of whether it's necessary.

@dgieselaar dgieselaar added release_note:enhancement Team:APM All issues that need APM UI Team support v7.10.0 labels Aug 6, 2020
@dgieselaar dgieselaar requested a review from a team as a code owner August 6, 2020 15:10
@elasticmachine
Copy link
Contributor

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

@dgieselaar
Copy link
Member Author

@elasticmachine merge upstream

@dgieselaar
Copy link
Member Author

@elasticmachine merge upstream

@dgieselaar
Copy link
Member Author

I'll leave this open until @sqren is back next week. As said before, I'm not sold on whether this is the right approach.

@dgieselaar
Copy link
Member Author

@elasticmachine merge upstream

@@ -48,6 +49,7 @@ export async function getAllEnvironments({
terms: {
field: SERVICE_ENVIRONMENT,
size: 100,
...(!serviceNameFilter.length ? { min_doc_count: 0 } : {}),
Copy link
Member

Choose a reason for hiding this comment

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

Not a comment on the actual feasibility of this approach but a general comment about conditional logic in our ES queries.

I think it's useful to co-locate logic that is meant to go together. For instance, if we add this behaviour but choose to delete it again, it'll be much easier if it's co-located (optimize for deletion).
Similarly, if there is an issue with this implementation and somebody (new) has to debug it, it's much easier if all the related lines are co-located so they don't have to study the es query in detail in case there are other places where we handle this behaviour. Additionally it's easier to write a meaningful comment that applies to all of the lines:

// return results immediately for unbound queries (query without a filter context)
if (!serviceNameFilter) {
 params.body.timeout = '1ms';
 params.aggs.environments.terms.min_doc_count = 0;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree that it's easier to understand. I'll need to look into whether TypeScript likes this though. I may need to look for something that has the same sentiment, but also has type-safety.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sqren this didn't work out for me, TypeScript started complaining. I don't feel it's worth it to add things like @ts-expect-error, so I'll just leave it as is. I did add a comment to explain what it does.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. I still thing it would have been worth co-locating it. It's not a big deal in a small query like this but it all adds up. I also don't like @ts-expect-error but I do like having a single coherent chunk of logic:

  if (!serviceNameFilter) {
    // @ts-expect-error
    params.body.timeout = '1ms';
    // @ts-expect-error
    params.aggs.environments.terms.min_doc_count = 0;
  }

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

If you think the pros outweighs the cons I'm good with this change 👍

(code-wise I still prefer the co-location that I mentioned :) )

@dgieselaar
Copy link
Member Author

@sqren this is a downside:

It will for instance return terms for deleted services.

I'm not sure how often that will happen though. I remember now I can look at telemetry to see how long a query like this will take. Let me get back about that.

@dgieselaar
Copy link
Member Author

@elasticmachine merge upstream

@dgieselaar
Copy link
Member Author

FWIW, couldn't really tell anything from the telemetry unfortunately.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@dgieselaar dgieselaar merged commit 3e07797 into elastic:master Sep 2, 2020
@dgieselaar dgieselaar deleted the faster-suggestions branch September 2, 2020 14:11
dgieselaar added a commit that referenced this pull request Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:enhancement Team:APM All issues that need APM UI Team support v7.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Loading environments in ML wizard is slow
4 participants