-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
- Loading branch information
Showing
15 changed files
with
227 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
9 changes: 9 additions & 0 deletions
9
src/plugins/vis_builder/public/application/utils/validations/types.ts
This file contains 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,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export interface ValidationResult<T = boolean> { | ||
errorMsg?: string; | ||
valid: T; | ||
} |
99 changes: 99 additions & 0 deletions
99
src/plugins/vis_builder/public/application/utils/validations/validate_aggregations.test.ts
This file contains 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,99 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { BUCKET_TYPES, IndexPattern, METRIC_TYPES } from '../../../../../data/public'; | ||
import { dataPluginMock } from '../../../../../data/public/mocks'; | ||
import { validateAggregations } from './validate_aggregations'; | ||
|
||
describe('validateAggregations', () => { | ||
const fields = [ | ||
{ | ||
name: '@timestamp', | ||
}, | ||
{ | ||
name: 'bytes', | ||
}, | ||
]; | ||
|
||
const indexPattern = { | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields: { | ||
getByName: (name: string) => fields.find((f) => f.name === name), | ||
filter: () => fields, | ||
}, | ||
} as any; | ||
|
||
const dataStart = dataPluginMock.createStartContract(); | ||
|
||
test('Pipeline aggs should have a bucket agg as the last agg', () => { | ||
const aggConfigs = dataStart.search.aggs.createAggConfigs(indexPattern as IndexPattern, [ | ||
{ | ||
id: '1', | ||
enabled: true, | ||
type: METRIC_TYPES.CUMULATIVE_SUM, | ||
schema: 'metric', | ||
params: {}, | ||
}, | ||
]); | ||
|
||
const { valid, errorMsg } = validateAggregations(aggConfigs.aggs); | ||
|
||
expect(valid).toBe(false); | ||
expect(errorMsg).toMatchInlineSnapshot( | ||
`"Add a bucket with \\"Date Histogram\\" or \\"Histogram\\" aggregation."` | ||
); | ||
}); | ||
|
||
test('Pipeline aggs should have a valid bucket agg', () => { | ||
const aggConfigs = dataStart.search.aggs.createAggConfigs(indexPattern as IndexPattern, [ | ||
{ | ||
id: '0', | ||
enabled: true, | ||
type: BUCKET_TYPES.SIGNIFICANT_TERMS, | ||
schema: 'segment', | ||
params: {}, | ||
}, | ||
{ | ||
id: '1', | ||
enabled: true, | ||
type: METRIC_TYPES.CUMULATIVE_SUM, | ||
schema: 'metric', | ||
params: {}, | ||
}, | ||
]); | ||
|
||
const { valid, errorMsg } = validateAggregations(aggConfigs.aggs); | ||
|
||
expect(valid).toBe(false); | ||
expect(errorMsg).toMatchInlineSnapshot( | ||
`"Last bucket aggregation must be \\"Date Histogram\\" or \\"Histogram\\" when using \\"Cumulative Sum\\" metric aggregation."` | ||
); | ||
}); | ||
|
||
test('Valid pipeline aggconfigs', () => { | ||
const aggConfigs = dataStart.search.aggs.createAggConfigs(indexPattern as IndexPattern, [ | ||
{ | ||
id: '0', | ||
enabled: true, | ||
type: BUCKET_TYPES.DATE_HISTOGRAM, | ||
schema: 'segment', | ||
params: {}, | ||
}, | ||
{ | ||
id: '1', | ||
enabled: true, | ||
type: METRIC_TYPES.CUMULATIVE_SUM, | ||
schema: 'metric', | ||
params: {}, | ||
}, | ||
]); | ||
|
||
const { valid, errorMsg } = validateAggregations(aggConfigs.aggs); | ||
|
||
expect(valid).toBe(true); | ||
expect(errorMsg).not.toBeDefined(); | ||
}); | ||
}); |
This file contains 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
59 changes: 59 additions & 0 deletions
59
src/plugins/vis_builder/public/application/utils/validations/validate_schema_state.test.ts
This file contains 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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Schemas } from '../../../../../vis_default_editor/public'; | ||
import { VisualizationState } from '../state_management'; | ||
import { validateSchemaState } from './validate_schema_state'; | ||
|
||
describe('validateSchemaState', () => { | ||
const schemas = new Schemas([ | ||
{ | ||
name: 'metrics', | ||
group: 'metrics', | ||
min: 1, | ||
}, | ||
{ | ||
name: 'buckets', | ||
group: 'buckets', | ||
}, | ||
]); | ||
|
||
test('should error if schema min agg requirement not met', () => { | ||
const visState: VisualizationState = { | ||
searchField: '', | ||
activeVisualization: { | ||
name: 'Test vis', | ||
aggConfigParams: [], | ||
}, | ||
}; | ||
|
||
const { valid, errorMsg } = validateSchemaState(schemas, visState); | ||
|
||
expect(valid).toBe(false); | ||
expect(errorMsg).toMatchInlineSnapshot( | ||
`"The Test vis visualization needs at least 1 field(s) in the agg type \\"metrics\\""` | ||
); | ||
}); | ||
|
||
test('should be valid if schema requirements are met', () => { | ||
const visState: VisualizationState = { | ||
searchField: '', | ||
activeVisualization: { | ||
name: 'Test vis', | ||
aggConfigParams: [ | ||
{ | ||
type: 'count', | ||
schema: 'metrics', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const { valid, errorMsg } = validateSchemaState(schemas, visState); | ||
|
||
expect(valid).toBe(true); | ||
expect(errorMsg).not.toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.