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

[Infra] Replace infra aggregation runtime types with the types in estypes #192059

Conversation

miloszmarcinkowski
Copy link
Contributor

@miloszmarcinkowski miloszmarcinkowski commented Sep 4, 2024

Closes #190497

Summary

This PR replaces infra aggregation types with types provided by the Elasticsearch client.

Testing

Alerting tested manually.

Checklist

Delete any items that are not applicable to this PR.

@obltmachine
Copy link

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@miloszmarcinkowski miloszmarcinkowski force-pushed the 190497-replace-infra-aggregation-runtime-types-with-the-types-in-estypes branch from e529ea7 to 7b7fd57 Compare September 4, 2024 10:29
@miloszmarcinkowski miloszmarcinkowski changed the title replace 'ESBasicMetricAggRT' and 'ESDerivativeAggRT' with 'estypes' [Infra] Replace infra aggregation runtime types with the types in estypes Sep 4, 2024
Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

I know it's still a draft, I am just adding some questions.

@miloszmarcinkowski miloszmarcinkowski force-pushed the 190497-replace-infra-aggregation-runtime-types-with-the-types-in-estypes branch from db8c5da to 7b7fd57 Compare September 4, 2024 11:23
@miloszmarcinkowski
Copy link
Contributor Author

Hey @crespocarlos

I see you had some good comments in similar PR #190495 therefore could you please take a look at this one?

Questions:

  • I have been thinking about moving type guards (isBasicMetricAgg, isDerivativeAgg, isSumBucketAgg) outside types.ts and putting them in a new file type_guards.ts. Wdyt?

  • Is there anything left to replace with estypes?

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

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

Nice one! Left a few comments.

Comment on lines 241 to 250
if (agg && typeof agg === 'object' && Object.keys(agg).length !== 0) {
for (const key in agg) {
if (Object.hasOwn(agg, key)) {
return !!(
agg[key as keyof typeof agg] === undefined ||
(agg[key as keyof typeof agg] as estypes.AggregationsMetricAggregationBase).field
);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Maybe this can be simplified?

Suggested change
if (agg && typeof agg === 'object' && Object.keys(agg).length !== 0) {
for (const key in agg) {
if (Object.hasOwn(agg, key)) {
return !!(
agg[key as keyof typeof agg] === undefined ||
(agg[key as keyof typeof agg] as estypes.AggregationsMetricAggregationBase).field
);
}
}
}
if (typeof agg !== 'object' || agg === null) {
return false;
}
return Object.values(agg).some(
value => value === undefined || 'field' in (value as estypes.AggregationsMetricAggregationBase)
);

@@ -8,10 +8,10 @@
import { has } from 'lodash';
Copy link
Contributor

@crespocarlos crespocarlos Sep 4, 2024

Choose a reason for hiding this comment

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

Should we add tests for the functions here?

Comment on lines 33 to 36
isDerivativeAgg,
isBasicMetricAgg,
isSumBucketAgg,
} from './inventory_models/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be in the types file? I wonder if it would be better if we created a utils file or something like that. wdyt?

@@ -37,7 +37,7 @@ export const isInterfaceRateAgg = (metric: MetricsUIAggregation | undefined) =>
const values = Object.values(metric);
return (
values.some((agg) => ESTermsWithAggregationRT.is(agg)) &&
Copy link
Contributor

@crespocarlos crespocarlos Sep 4, 2024

Choose a reason for hiding this comment

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

I forgot this one. Let's try to replace this too.

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 had a chat with Jenny earlier today, and we weren't sure about replacing ESTermsWithAggregationRT. I'll do it then. Thanks

@crespocarlos
Copy link
Contributor

crespocarlos commented Sep 4, 2024

Hey! I had reviewed it before reading this:

Questions:

  • I have been thinking about moving type guards (isBasicMetricAgg, isDerivativeAgg, isSumBucketAgg) outside types.ts and putting them in a new file type_guards.ts. Wdyt?

I agree with moving the type guards to another file, I've even left a comment about it already :).

  • Is there anything left to replace with estypes?

From what I've seen, there is only ESTermsWithAggregationRT left

Comment on lines 100 to 103
return !!(
(agg as estypes.AggregationsAggregationContainer).aggregations &&
(agg as estypes.AggregationsAggregationContainer).terms
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit to avoid repetition

Suggested change
return !!(
(agg as estypes.AggregationsAggregationContainer).aggregations &&
(agg as estypes.AggregationsAggregationContainer).terms
);
const container = agg as estypes.AggregationsAggregationContainer;
return !!(container?.terms && container?.aggregations);

@miloszmarcinkowski miloszmarcinkowski marked this pull request as ready for review September 5, 2024 09:27
@miloszmarcinkowski miloszmarcinkowski requested review from a team as code owners September 5, 2024 09:27
@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Sep 5, 2024
@miloszmarcinkowski miloszmarcinkowski added v8.16.0 release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team labels Sep 5, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this PR. Left just one nit.


describe('isRate', () => {
describe('isMetricRate', () => {
// todo: do we mock outside of file?
Copy link
Contributor

Choose a reason for hiding this comment

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

it's fine to leave these mocks on this file. do we still need this todo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ops. I committed it unintentionally. It was a reminder for me to clarify it with you guys. Updated, thanks!

@@ -0,0 +1,74 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for add the test.

Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

LGTM 💯 Thank you for changing those types, it looks better and we don't need to maintain those types anymore!

@miloszmarcinkowski miloszmarcinkowski force-pushed the 190497-replace-infra-aggregation-runtime-types-with-the-types-in-estypes branch from 20bb82a to 7aa5f38 Compare September 5, 2024 10:23
@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 5, 2024

💛 Build succeeded, but was flaky

  • Buildkite Build
  • Commit: 7aa5f38
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-192059-7aa5f3898d1e

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
metricsDataAccess 133 137 +4

Page load bundle

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

id before after diff
metricsDataAccess 62.2KB 62.0KB -157.0B
Unknown metric groups

API count

id before after diff
metricsDataAccess 133 137 +4

History

  • 💔 Build #232163 failed 6fa3c47b9ae49a8249acf3ca36b70a0a954a2028
  • 💔 Build #231917 failed 7b7fd57ce4f6847a50019429ec7f3072866a1e64

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

@miloszmarcinkowski miloszmarcinkowski merged commit 8afac4d into elastic:main Sep 5, 2024
23 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 5, 2024
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 ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Infra] Replace infra aggregation runtime types with the types in estypes
8 participants