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.
[Monitoring] Add tests to ensure mappings exist on metric fields (ela…
…stic#23958) * Ensure mappings exist * Add APM * Remove unnecessary eslint disable comment * Update snapshots
- Loading branch information
1 parent
8c6f1e6
commit 25f4843
Showing
7 changed files
with
103 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
x-pack/test/api_integration/apis/monitoring/common/index.js
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,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export default function ({ loadTestFile }) { | ||
describe('common', () => { | ||
loadTestFile(require.resolve('./mappings_exist')); | ||
}); | ||
} |
73 changes: 73 additions & 0 deletions
73
x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js
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,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from 'expect.js'; | ||
import { get } from 'lodash'; | ||
import * as esMetrics from '../../../../../plugins/monitoring/server/lib/metrics/elasticsearch/metrics'; | ||
import * as kibanaMetrics from '../../../../../plugins/monitoring/server/lib/metrics/kibana/metrics'; | ||
import * as logstashMetrics from '../../../../../plugins/monitoring/server/lib/metrics/logstash/metrics'; | ||
import * as beatsMetrics from '../../../../../plugins/monitoring/server/lib/metrics/beats/metrics'; | ||
import * as apmMetrics from '../../../../../plugins/monitoring/server/lib/metrics/apm/metrics'; | ||
|
||
export default function ({ getService }) { | ||
const es = getService('es'); | ||
|
||
const metricSets = [ | ||
{ | ||
metrics: esMetrics.metrics, | ||
name: 'es metrics', | ||
indexTemplate: '.monitoring-es' | ||
}, | ||
{ | ||
metrics: kibanaMetrics.metrics, | ||
name: 'kibana metrics', | ||
indexTemplate: '.monitoring-kibana' | ||
}, | ||
{ | ||
metrics: logstashMetrics.metrics, | ||
name: 'logstash metrics', | ||
indexTemplate: '.monitoring-logstash' | ||
}, | ||
{ | ||
metrics: beatsMetrics.metrics, | ||
name: 'beats metrics', | ||
indexTemplate: '.monitoring-beats' | ||
}, | ||
{ | ||
metrics: apmMetrics.metrics, | ||
name: 'apm metrics', | ||
indexTemplate: '.monitoring-beats' // apm uses the same as beats | ||
}, | ||
]; | ||
|
||
describe('mappings', () => { | ||
for (const { indexTemplate, metrics, name } of metricSets) { | ||
let mappings; | ||
|
||
before('load mappings', async () => { | ||
const template = await es.indices.getTemplate({ name: indexTemplate }); | ||
mappings = get(template, [indexTemplate, 'mappings', 'doc', 'properties']); | ||
}); | ||
|
||
describe(`for ${name}`, () => { // eslint-disable-line no-loop-func | ||
for (const metric of Object.values(metrics)) { | ||
for (const field of metric.getFields()) { | ||
it(`${field} should exist in the mappings`, () => { // eslint-disable-line no-loop-func | ||
const propertyGetter = field.split('.').reduce((list, field) => { | ||
list.push(field); | ||
list.push('properties'); | ||
return list; | ||
}, []).slice(0, -1); // Remove the trailing 'properties' | ||
|
||
const foundMapping = get(mappings, propertyGetter, null); | ||
expect(foundMapping).to.not.equal(null); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} |
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