diff --git a/x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap b/x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap index a3590788367c..d9fc45f77c77 100644 --- a/x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap +++ b/x-pack/plugins/monitoring/server/lib/metrics/__test__/__snapshots__/metrics.test.js.snap @@ -1796,6 +1796,7 @@ Object { "description": "The number of operations the follower index is lagging behind the leader.", "field": "", "format": "0,0.[00]", + "getFields": [Function], "label": "Ops delay", "metricAgg": "sum", "timestampField": "timestamp", @@ -2277,7 +2278,7 @@ Object { "app": "elasticsearch", "derivative": true, "description": "Time spent on Elasticsearch refresh for primary and replica shards.", - "field": "total.refresh.total_time_in_millis", + "field": "index_stats.total.refresh.total_time_in_millis", "format": "0,0.[00]", "label": "Total Refresh Time", "metricAgg": "max", diff --git a/x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js b/x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js index 44d02689b867..a1d334cd035f 100644 --- a/x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js +++ b/x-pack/plugins/monitoring/server/lib/metrics/classes/metric.js @@ -54,6 +54,19 @@ export class Metric { }; } + getFields() { + return [this.field]; + } + + getDocType() { + return this.docType || this.getInferredDocType(); + } + + getInferredDocType() { + const fields = this.getFields(); + return fields && fields.length ? fields[0].split('.')[0] : null; + } + static calculateLatency(timeInMillis, totalEvents) { if (timeInMillis === null || totalEvents === null) { return null; diff --git a/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js index 656465ba841d..244579153867 100644 --- a/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js +++ b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/classes.js @@ -56,6 +56,8 @@ export class DifferenceMetric extends ElasticsearchMetric { }, }; + this.getFields = () => [`${fieldSource}.${metric}`, `${fieldSource}.${metric2}`]; + this.calculation = (bucket) => { return _.get(bucket, 'metric_max.value') - _.get(bucket, 'metric2_max.value'); }; diff --git a/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js index 1a7639f3e097..6dc281b650fb 100644 --- a/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js +++ b/x-pack/plugins/monitoring/server/lib/metrics/elasticsearch/metrics.js @@ -937,7 +937,7 @@ export const metrics = { type: 'index' }), index_refresh_time: new ElasticsearchMetric({ - field: 'total.refresh.total_time_in_millis', + field: 'index_stats.total.refresh.total_time_in_millis', label: 'Total Refresh Time', description: 'Time spent on Elasticsearch refresh for primary and replica shards.', diff --git a/x-pack/test/api_integration/apis/monitoring/common/index.js b/x-pack/test/api_integration/apis/monitoring/common/index.js new file mode 100644 index 000000000000..6d5049f1018c --- /dev/null +++ b/x-pack/test/api_integration/apis/monitoring/common/index.js @@ -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')); + }); +} diff --git a/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js b/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js new file mode 100644 index 000000000000..8d78a150f28c --- /dev/null +++ b/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js @@ -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); + }); + } + } + }); + } + }); +} diff --git a/x-pack/test/api_integration/apis/monitoring/index.js b/x-pack/test/api_integration/apis/monitoring/index.js index d9941b0d7ac7..f413fa4ad94e 100644 --- a/x-pack/test/api_integration/apis/monitoring/index.js +++ b/x-pack/test/api_integration/apis/monitoring/index.js @@ -13,5 +13,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./elasticsearch_settings')); loadTestFile(require.resolve('./kibana')); loadTestFile(require.resolve('./logstash')); + loadTestFile(require.resolve('./common')); }); }