-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EEM] Fallback to source for metadata if no destination defined (#188515
) This PR closes elastic/elastic-entity-model#116 by ensuring that `destination` is always set when the schema is parsed along with ensuring that if for some reason desitnation is not set, we fallback in the actual metadata code as well. I also added a unit test for each of the different `metadata` formats: - String - Object with only `source` - Object with `source` and `limit` - Object with `source`, `limit`, and `destination` --------- Co-authored-by: Chris Cowan <[email protected]> Co-authored-by: Chris Cowan <[email protected]> Co-authored-by: Nathan L Smith <[email protected]>
- Loading branch information
1 parent
2ebb171
commit d5d3f42
Showing
4 changed files
with
192 additions
and
3 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
183 changes: 183 additions & 0 deletions
183
...ution/entity_manager/server/lib/entities/transform/generate_metadata_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,183 @@ | ||
/* | ||
* 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 { entityDefinitionSchema } from '@kbn/entities-schema'; | ||
import { rawEntityDefinition } from '../helpers/fixtures/entity_definition'; | ||
import { | ||
generateHistoryMetadataAggregations, | ||
generateLatestMetadataAggregations, | ||
} from './generate_metadata_aggregations'; | ||
|
||
describe('Generate Metadata Aggregations for history and latest', () => { | ||
describe('generateHistoryMetadataAggregations()', () => { | ||
it('should generate metadata aggregations for string format', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: ['host.name'], | ||
}); | ||
expect(generateHistoryMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
terms: { | ||
field: 'host.name', | ||
size: 1000, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with only source', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name' }], | ||
}); | ||
expect(generateHistoryMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
terms: { | ||
field: 'host.name', | ||
size: 1000, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with source and limit', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name', limit: 10 }], | ||
}); | ||
expect(generateHistoryMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
terms: { | ||
field: 'host.name', | ||
size: 10, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with source, limit, and destination', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name', limit: 10, destination: 'hostName' }], | ||
}); | ||
expect(generateHistoryMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.hostName': { | ||
terms: { | ||
field: 'host.name', | ||
size: 10, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('generateLatestMetadataAggregations()', () => { | ||
it('should generate metadata aggregations for string format', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: ['host.name'], | ||
}); | ||
expect(generateLatestMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
filter: { | ||
range: { | ||
'event.ingested': { | ||
gte: 'now-1m', | ||
}, | ||
}, | ||
}, | ||
aggs: { | ||
data: { | ||
terms: { | ||
field: 'host.name', | ||
size: 1000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with only source', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name' }], | ||
}); | ||
expect(generateLatestMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
filter: { | ||
range: { | ||
'event.ingested': { | ||
gte: 'now-1m', | ||
}, | ||
}, | ||
}, | ||
aggs: { | ||
data: { | ||
terms: { | ||
field: 'host.name', | ||
size: 1000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with source and limit', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name', limit: 10 }], | ||
}); | ||
expect(generateLatestMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.host.name': { | ||
filter: { | ||
range: { | ||
'event.ingested': { | ||
gte: 'now-1m', | ||
}, | ||
}, | ||
}, | ||
aggs: { | ||
data: { | ||
terms: { | ||
field: 'host.name', | ||
size: 10, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should generate metadata aggregations for object format with source, limit, and destination', () => { | ||
const definition = entityDefinitionSchema.parse({ | ||
...rawEntityDefinition, | ||
metadata: [{ source: 'host.name', limit: 10, destination: 'hostName' }], | ||
}); | ||
expect(generateLatestMetadataAggregations(definition)).toEqual({ | ||
'entity.metadata.hostName': { | ||
filter: { | ||
range: { | ||
'event.ingested': { | ||
gte: 'now-1m', | ||
}, | ||
}, | ||
}, | ||
aggs: { | ||
data: { | ||
terms: { | ||
field: 'hostName', | ||
size: 10, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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