-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Infra] Replace infra aggregation runtime types with the types in estypes
#192059
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
Merged
miloszmarcinkowski
merged 7 commits into
elastic:main
from
miloszmarcinkowski:190497-replace-infra-aggregation-runtime-types-with-the-types-in-estypes
Sep 5, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca5acbd
replace 'ESBasicMetricAggRT' and 'ESDerivativeAggRT' with 'estypes'
miloszmarcinkowski 5d02dcc
replace 'ESSumBucketAggRT' with 'estypes'
miloszmarcinkowski 9838fdf
improve `isBasicMetricAgg` method
miloszmarcinkowski a6ea051
move type guards from types.ts to index.ts (serves as utils folder)
miloszmarcinkowski 19b6ada
replace 'ESTermsWithAggregationRT' with 'estype'
miloszmarcinkowski 5a72aa0
avoid repetition in `isTermsWithAggregation` (improvement)
miloszmarcinkowski 7aa5f38
cover 'is_rate' with unit tests
miloszmarcinkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...ability_solution/infra/server/lib/alerting/inventory_metric_threshold/lib/is_rate.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { MetricsUIAggregation } from '@kbn/metrics-data-access-plugin/common'; | ||
| import { isCustomMetricRate, isInterfaceRateAgg, isMetricRate, isRate } from './is_rate'; | ||
| import { SnapshotCustomMetricInput } from '../../../../../common/http_api'; | ||
|
|
||
| const customMaxMetricMock: SnapshotCustomMetricInput = { | ||
| type: 'custom', | ||
| aggregation: 'max', | ||
| field: '', | ||
| id: '', | ||
| }; | ||
|
|
||
| const customRateMetricMock: SnapshotCustomMetricInput = { | ||
| type: 'custom', | ||
| aggregation: 'rate', | ||
| field: '', | ||
| id: '', | ||
| }; | ||
|
|
||
| const metricMock: MetricsUIAggregation = { | ||
| mock1: { derivative: {} }, | ||
| mock2: { max: null, mock: { field: '' } }, | ||
| mock3: { | ||
| aggregations: {}, | ||
| terms: {}, | ||
| sum_bucket: {}, | ||
| }, | ||
| }; | ||
|
|
||
| describe('isRate', () => { | ||
| describe('isMetricRate', () => { | ||
| it('should return false when metric is undefined', () => { | ||
| expect(isMetricRate(undefined)).toEqual(false); | ||
| }); | ||
| it('should return true when correct metric is passed', () => { | ||
| expect(isMetricRate(metricMock)).toEqual(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isCustomMetricRate', () => { | ||
| it("should return false when aggregation isn't 'rate'", () => { | ||
| expect(isCustomMetricRate(customMaxMetricMock)).toEqual(false); | ||
| }); | ||
| it("should return true when aggregation is equal to 'rate'", () => { | ||
| expect(isCustomMetricRate(customRateMetricMock)).toEqual(true); | ||
| }); | ||
|
|
||
| describe('isInterfaceRateAgg', () => { | ||
| it('should return false if metric is undefined', () => { | ||
| expect(isInterfaceRateAgg(undefined)).toEqual(false); | ||
| }); | ||
| it('should return true when correct metric is passed', () => { | ||
| expect(isInterfaceRateAgg(metricMock)).toEqual(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isRate', () => { | ||
| it('should return false when incorrect metrics are provided', () => { | ||
| expect(isRate({} as MetricsUIAggregation, {} as SnapshotCustomMetricInput)).toEqual(false); | ||
| }); | ||
|
|
||
| it('should return true when proper metric are provided', () => { | ||
| expect(isRate(metricMock, customRateMetricMock)).toEqual(true); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,10 @@ | |
| import { has } from 'lodash'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add tests for the functions here? |
||
| import { | ||
| MetricsUIAggregation, | ||
| ESSumBucketAggRT, | ||
| ESDerivativeAggRT, | ||
| ESBasicMetricAggRT, | ||
| ESTermsWithAggregationRT, | ||
| isBasicMetricAgg, | ||
| isDerivativeAgg, | ||
| isSumBucketAgg, | ||
| isTermsWithAggregation, | ||
| } from '@kbn/metrics-data-access-plugin/common'; | ||
| import { SnapshotCustomMetricInput } from '../../../../../common/http_api'; | ||
|
|
||
|
|
@@ -21,8 +21,8 @@ export const isMetricRate = (metric: MetricsUIAggregation | undefined): boolean | |
| } | ||
| const values = Object.values(metric); | ||
| return ( | ||
| values.some((agg) => ESDerivativeAggRT.is(agg)) && | ||
| values.some((agg) => ESBasicMetricAggRT.is(agg) && has(agg, 'max')) | ||
| values.some((agg) => isDerivativeAgg(agg)) && | ||
| values.some((agg) => isBasicMetricAgg(agg) && has(agg, 'max')) | ||
| ); | ||
| }; | ||
|
|
||
|
|
@@ -36,8 +36,7 @@ export const isInterfaceRateAgg = (metric: MetricsUIAggregation | undefined) => | |
| } | ||
| const values = Object.values(metric); | ||
| return ( | ||
| values.some((agg) => ESTermsWithAggregationRT.is(agg)) && | ||
| values.some((agg) => ESSumBucketAggRT.is(agg)) | ||
| values.some((agg) => isTermsWithAggregation(agg)) && values.some((agg) => isSumBucketAgg(agg)) | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.