forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EPM] Conditionally generate ES index pattern name based on dataset_i…
…s_prefix (elastic#89870) * Explicitly generate ES index pattern name. * Adjust tests. * Adjust and reenable tests. * Set template priority based on dataset_is_prefix * Refactor indexPatternName -> templateIndexPattern * Add unit tests. * Use more realistic index pattern in test. * Fix unit test. * Add unit test for installTemplate(). Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
7d220d5
commit a1ff935
Showing
7 changed files
with
268 additions
and
34 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
110 changes: 110 additions & 0 deletions
110
x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.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,110 @@ | ||
/* | ||
* 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 { RegistryDataStream } from '../../../../types'; | ||
import { Field } from '../../fields/field'; | ||
|
||
import { elasticsearchServiceMock } from 'src/core/server/mocks'; | ||
import { installTemplate } from './install'; | ||
|
||
test('tests installPackage to use correct priority and index_patterns for data stream with dataset_is_prefix not set', async () => { | ||
const callCluster = elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser; | ||
const fields: Field[] = []; | ||
const dataStreamDatasetIsPrefixUnset = { | ||
type: 'metrics', | ||
dataset: 'package.dataset', | ||
title: 'test data stream', | ||
release: 'experimental', | ||
package: 'package', | ||
path: 'path', | ||
ingest_pipeline: 'default', | ||
} as RegistryDataStream; | ||
const pkg = { | ||
name: 'package', | ||
version: '0.0.1', | ||
}; | ||
const templateIndexPatternDatasetIsPrefixUnset = 'metrics-package.dataset-*'; | ||
const templatePriorityDatasetIsPrefixUnset = 200; | ||
await installTemplate({ | ||
callCluster, | ||
fields, | ||
dataStream: dataStreamDatasetIsPrefixUnset, | ||
packageVersion: pkg.version, | ||
packageName: pkg.name, | ||
}); | ||
// @ts-ignore | ||
const sentTemplate = callCluster.mock.calls[0][1].body; | ||
expect(sentTemplate).toBeDefined(); | ||
expect(sentTemplate.priority).toBe(templatePriorityDatasetIsPrefixUnset); | ||
expect(sentTemplate.index_patterns).toEqual([templateIndexPatternDatasetIsPrefixUnset]); | ||
}); | ||
|
||
test('tests installPackage to use correct priority and index_patterns for data stream with dataset_is_prefix set to false', async () => { | ||
const callCluster = elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser; | ||
const fields: Field[] = []; | ||
const dataStreamDatasetIsPrefixFalse = { | ||
type: 'metrics', | ||
dataset: 'package.dataset', | ||
title: 'test data stream', | ||
release: 'experimental', | ||
package: 'package', | ||
path: 'path', | ||
ingest_pipeline: 'default', | ||
dataset_is_prefix: false, | ||
} as RegistryDataStream; | ||
const pkg = { | ||
name: 'package', | ||
version: '0.0.1', | ||
}; | ||
const templateIndexPatternDatasetIsPrefixFalse = 'metrics-package.dataset-*'; | ||
const templatePriorityDatasetIsPrefixFalse = 200; | ||
await installTemplate({ | ||
callCluster, | ||
fields, | ||
dataStream: dataStreamDatasetIsPrefixFalse, | ||
packageVersion: pkg.version, | ||
packageName: pkg.name, | ||
}); | ||
// @ts-ignore | ||
const sentTemplate = callCluster.mock.calls[0][1].body; | ||
expect(sentTemplate).toBeDefined(); | ||
expect(sentTemplate.priority).toBe(templatePriorityDatasetIsPrefixFalse); | ||
expect(sentTemplate.index_patterns).toEqual([templateIndexPatternDatasetIsPrefixFalse]); | ||
}); | ||
|
||
test('tests installPackage to use correct priority and index_patterns for data stream with dataset_is_prefix set to true', async () => { | ||
const callCluster = elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser; | ||
const fields: Field[] = []; | ||
const dataStreamDatasetIsPrefixTrue = { | ||
type: 'metrics', | ||
dataset: 'package.dataset', | ||
title: 'test data stream', | ||
release: 'experimental', | ||
package: 'package', | ||
path: 'path', | ||
ingest_pipeline: 'default', | ||
dataset_is_prefix: true, | ||
} as RegistryDataStream; | ||
const pkg = { | ||
name: 'package', | ||
version: '0.0.1', | ||
}; | ||
const templateIndexPatternDatasetIsPrefixTrue = 'metrics-package.dataset.*-*'; | ||
const templatePriorityDatasetIsPrefixTrue = 150; | ||
await installTemplate({ | ||
callCluster, | ||
fields, | ||
dataStream: dataStreamDatasetIsPrefixTrue, | ||
packageVersion: pkg.version, | ||
packageName: pkg.name, | ||
}); | ||
// @ts-ignore | ||
const sentTemplate = callCluster.mock.calls[0][1].body; | ||
expect(sentTemplate).toBeDefined(); | ||
expect(sentTemplate.priority).toBe(templatePriorityDatasetIsPrefixTrue); | ||
expect(sentTemplate.index_patterns).toEqual([templateIndexPatternDatasetIsPrefixTrue]); | ||
}); |
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
Oops, something went wrong.