-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Infra] Replace infra aggregation runtime types with the types in estypes
#192059
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
e529ea7
to
7b7fd57
Compare
estypes
There was a problem hiding this 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.
x-pack/plugins/observability_solution/metrics_data_access/common/inventory_models/types.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/observability_solution/metrics_data_access/common/inventory_models/types.ts
Outdated
Show resolved
Hide resolved
db8c5da
to
7b7fd57
Compare
Hey @crespocarlos I see you had some good comments in similar PR #190495 therefore could you please take a look at this one? Questions:
|
There was a problem hiding this 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.
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 | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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?
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'; |
There was a problem hiding this comment.
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?
isDerivativeAgg, | ||
isBasicMetricAgg, | ||
isSumBucketAgg, | ||
} from './inventory_models/types'; |
There was a problem hiding this comment.
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)) && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Hey! I had reviewed it before reading this:
I agree with moving the type guards to another file, I've even left a comment about it already :).
From what I've seen, there is only |
return !!( | ||
(agg as estypes.AggregationsAggregationContainer).aggregations && | ||
(agg as estypes.AggregationsAggregationContainer).terms | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit to avoid repetition
return !!( | |
(agg as estypes.AggregationsAggregationContainer).aggregations && | |
(agg as estypes.AggregationsAggregationContainer).terms | |
); | |
const container = agg as estypes.AggregationsAggregationContainer; | |
return !!(container?.terms && container?.aggregations); |
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
There was a problem hiding this 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? |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 @@ | |||
/* |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
20bb82a
to
7aa5f38
Compare
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Public APIs missing comments
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.