diff --git a/x-pack/plugins/monitoring/common/constants.js b/x-pack/plugins/monitoring/common/constants.js index 372f0bd492d24a..d87bb2c8be8fe0 100644 --- a/x-pack/plugins/monitoring/common/constants.js +++ b/x-pack/plugins/monitoring/common/constants.js @@ -152,3 +152,10 @@ export const DEBOUNCE_FAST_MS = 10; // roughly how long it takes to render a fra export const CLUSTER_ALERTS_ADDRESS_CONFIG_KEY = 'cluster_alerts.email_notifications.email_address'; export const STANDALONE_CLUSTER_CLUSTER_UUID = '__standalone_cluster__'; + +export const INDEX_PATTERN = '.monitoring-*-6-*'; +export const INDEX_PATTERN_KIBANA = '.monitoring-kibana-6-*'; +export const INDEX_PATTERN_LOGSTASH = '.monitoring-logstash-6-*'; +export const INDEX_PATTERN_BEATS = '.monitoring-beats-6-*'; +export const INDEX_ALERTS = '.monitoring-alerts-6'; +export const INDEX_PATTERN_ELASTICSEARCH = '.monitoring-es-6-*'; diff --git a/x-pack/plugins/monitoring/config.js b/x-pack/plugins/monitoring/config.js index 6074b8c34b232c..0775d219c0238c 100644 --- a/x-pack/plugins/monitoring/config.js +++ b/x-pack/plugins/monitoring/config.js @@ -30,23 +30,14 @@ export const config = (Joi) => { }).default() }).default() }).default(), - index_pattern: Joi.string().default('.monitoring-*-6-*'), kibana: Joi.object({ - index_pattern: Joi.string().default('.monitoring-kibana-6-*'), collection: Joi.object({ enabled: Joi.boolean().default(true), interval: Joi.number().default(10000) // op status metrics get buffered at `ops.interval` and flushed to the bulk endpoint at this interval }).default() }).default(), - logstash: Joi.object({ - index_pattern: Joi.string().default('.monitoring-logstash-6-*') - }).default(), - beats: Joi.object({ - index_pattern: Joi.string().default('.monitoring-beats-6-*') - }).default(), cluster_alerts: Joi.object({ enabled: Joi.boolean().default(true), - index: Joi.string().default('.monitoring-alerts-6'), email_notifications: Joi.object({ enabled: Joi.boolean().default(true), email_address: Joi.string().email(), @@ -62,7 +53,6 @@ export const config = (Joi) => { }).default(), elasticsearch: Joi.object({ customHeaders: Joi.object().default({}), - index_pattern: Joi.string().default('.monitoring-es-6-*'), logQueries: Joi.boolean().default(false), requestHeadersWhitelist: Joi.array().items().single().default(DEFAULT_REQUEST_HEADERS), sniffOnStart: Joi.boolean().default(false), diff --git a/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js b/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js index 8b2ae13803782f..e2aa07ad78ee11 100644 --- a/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js +++ b/x-pack/plugins/monitoring/server/lib/__tests__/ccs_utils.js @@ -10,76 +10,65 @@ import { parseCrossClusterPrefix, prefixIndexPattern } from '../ccs_utils'; describe('ccs_utils', () => { describe('prefixIndexPattern', () => { - const indexPatternName = 'xyz'; const indexPattern = '.monitoring-xyz-1-*,.monitoring-xyz-2-*'; it('returns the index pattern if ccs is not enabled', () => { const get = sinon.stub(); const config = { get }; - get.withArgs(indexPatternName).returns(indexPattern); get.withArgs('xpack.monitoring.ccs.enabled').returns(false); // falsy string values should be ignored - const allPattern = prefixIndexPattern(config, indexPatternName, '*'); - const onePattern = prefixIndexPattern(config, indexPatternName, 'do_not_use_me'); + const allPattern = prefixIndexPattern(config, indexPattern, '*'); + const onePattern = prefixIndexPattern(config, indexPattern, 'do_not_use_me'); expect(allPattern).to.be(indexPattern); expect(onePattern).to.be(indexPattern); - // uses the config and indexPatternName supplied - expect(get.callCount).to.eql(4); + expect(get.callCount).to.eql(2); }); it('returns the index pattern if ccs is not used', () => { const get = sinon.stub(); const config = { get }; - get.withArgs(indexPatternName).returns(indexPattern); get.withArgs('xpack.monitoring.ccs.enabled').returns(true); // falsy string values should be ignored - const undefinedPattern = prefixIndexPattern(config, indexPatternName); - const nullPattern = prefixIndexPattern(config, indexPatternName, null); - const blankPattern = prefixIndexPattern(config, indexPatternName, ''); + const undefinedPattern = prefixIndexPattern(config, indexPattern); + const nullPattern = prefixIndexPattern(config, indexPattern, null); + const blankPattern = prefixIndexPattern(config, indexPattern, ''); expect(undefinedPattern).to.be(indexPattern); expect(nullPattern).to.be(indexPattern); expect(blankPattern).to.be(indexPattern); - // uses the config and indexPatternName supplied - expect(get.callCount).to.eql(6); + expect(get.callCount).to.eql(3); }); it('returns the ccs-prefixed index pattern', () => { const get = sinon.stub(); const config = { get }; - get.withArgs(indexPatternName).returns(indexPattern); get.withArgs('xpack.monitoring.ccs.enabled').returns(true); - const abcPattern = prefixIndexPattern(config, indexPatternName, 'aBc'); - const underscorePattern = prefixIndexPattern(config, indexPatternName, 'cluster_one'); + const abcPattern = prefixIndexPattern(config, indexPattern, 'aBc'); + const underscorePattern = prefixIndexPattern(config, indexPattern, 'cluster_one'); expect(abcPattern).to.eql('aBc:.monitoring-xyz-1-*,aBc:.monitoring-xyz-2-*'); expect(underscorePattern).to.eql('cluster_one:.monitoring-xyz-1-*,cluster_one:.monitoring-xyz-2-*'); - - // uses the config and indexPatternName supplied, but only calls once - expect(get.callCount).to.eql(4); + expect(get.callCount).to.eql(2); }); it('returns the ccs-prefixed index pattern when wildcard and the local cluster pattern', () => { const get = sinon.stub(); const config = { get }; - get.withArgs(indexPatternName).returns(indexPattern); get.withArgs('xpack.monitoring.ccs.enabled').returns(true); - const pattern = prefixIndexPattern(config, indexPatternName, '*'); + const pattern = prefixIndexPattern(config, indexPattern, '*'); // it should have BOTH patterns so that it searches all CCS clusters and the local cluster expect(pattern).to.eql('*:.monitoring-xyz-1-*,*:.monitoring-xyz-2-*' + ',' + indexPattern); - - // uses the config and indexPatternName supplied, but only calls once - expect(get.callCount).to.eql(2); + expect(get.callCount).to.eql(1); }); }); diff --git a/x-pack/plugins/monitoring/server/lib/ccs_utils.js b/x-pack/plugins/monitoring/server/lib/ccs_utils.js index d879a8d51c1008..30409960edd9ec 100644 --- a/x-pack/plugins/monitoring/server/lib/ccs_utils.js +++ b/x-pack/plugins/monitoring/server/lib/ccs_utils.js @@ -11,13 +11,12 @@ * which means that the index pattern will be returned without using {@code ccs}. * * @param {Object} config The Kibana configuration object. - * @param {String} indexPatternName The index pattern name (e.g., 'xpack.monitoring.elasticsearch.index_pattern') + * @param {String} indexPattern The index pattern name * @param {String} ccs The optional cluster-prefix to prepend. * @return {String} The index pattern with the {@code cluster} prefix appropriately prepended. */ -export function prefixIndexPattern(config, indexPatternName, ccs) { +export function prefixIndexPattern(config, indexPattern, ccs) { const ccsEnabled = config.get('xpack.monitoring.ccs.enabled'); - const indexPattern = config.get(indexPatternName); if (!ccsEnabled || !ccs) { return indexPattern; diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js index 609fc9d46394a6..5462cd492fbc80 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/verify_monitoring_auth.js @@ -6,6 +6,7 @@ import { get } from 'lodash'; import Boom from 'boom'; +import { INDEX_PATTERN } from '../../../common/constants'; /* * Check the currently logged-in user's privileges for "read" privileges on the @@ -36,7 +37,6 @@ export async function verifyMonitoringAuth(req) { */ async function verifyHasPrivileges(req) { const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - const config = req.server.config(); const response = await callWithRequest(req, 'transport.request', { method: 'POST', @@ -44,7 +44,7 @@ async function verifyHasPrivileges(req) { body: { index: [ { - names: [ config.get('xpack.monitoring.index_pattern') ], // uses wildcard + names: [ INDEX_PATTERN ], // uses wildcard privileges: [ 'read' ] } ] diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js index d9cea7f88b322c..093e71e66ee2d9 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/alerts/index.js @@ -9,6 +9,7 @@ import { alertsClusterSearch } from '../../../../cluster_alerts/alerts_cluster_s import { checkLicense } from '../../../../cluster_alerts/check_license'; import { getClusterLicense } from '../../../../lib/cluster/get_cluster_license'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_ELASTICSEARCH, INDEX_ALERTS } from '../../../../../common/constants'; /* * Cluster Alerts route. @@ -35,8 +36,8 @@ export function clusterAlertsRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); - const alertsIndex = prefixIndexPattern(config, 'xpack.monitoring.cluster_alerts.index', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); + const alertsIndex = prefixIndexPattern(config, INDEX_ALERTS, ccs); const options = { start: req.payload.timeRange.min, end: req.payload.timeRange.max diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js index 7f9a79046d994a..fad9e59902eed9 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instance.js @@ -10,6 +10,7 @@ import { getMetrics } from '../../../../lib/details/get_metrics'; import { metricSet } from './metric_set_overview'; import { handleError } from '../../../../lib/errors'; import { getApmInfo } from '../../../../lib/apm'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function apmInstanceRoute(server) { server.route({ @@ -35,7 +36,7 @@ export function apmInstanceRoute(server) { const config = server.config(); const clusterUuid = req.params.clusterUuid; const ccs = req.payload.ccs; - const apmIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const apmIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); try { const [ metrics, apmSummary ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js index ec8c3cdd8d8612..6a5ab2c45b9dcd 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/instances.js @@ -8,6 +8,7 @@ import Joi from 'joi'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getStats, getApms } from '../../../../lib/apm'; import { handleError } from '../../../../lib/errors'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function apmInstancesRoute(server) { server.route({ @@ -31,7 +32,7 @@ export function apmInstancesRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const apmIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const apmIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); try { diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js index ecad1a444f7b01..66e39ce61ff77e 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/apm/overview.js @@ -10,6 +10,7 @@ import { getMetrics } from '../../../../lib/details/get_metrics'; import { metricSet } from './metric_set_overview'; import { handleError } from '../../../../lib/errors'; import { getApmClusterStatus } from './_get_apm_cluster_status'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function apmOverviewRoute(server) { server.route({ @@ -33,7 +34,7 @@ export function apmOverviewRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const apmIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const apmIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); try { const [ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js index 7bce52319c7e98..b8020fd007ba9b 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beat_detail.js @@ -10,6 +10,7 @@ import { getBeatSummary } from '../../../../lib/beats'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { handleError } from '../../../../lib/errors'; import { metricSet } from './metric_set_detail'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function beatsDetailRoute(server) { server.route({ @@ -36,7 +37,7 @@ export function beatsDetailRoute(server) { const beatUuid = req.params.beatUuid; const config = server.config(); const ccs = req.payload.ccs; - const beatsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const beatsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); const summaryOptions = { clusterUuid, diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js index f2e7a46f0278a2..282bbf7a353a43 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/beats.js @@ -8,6 +8,7 @@ import Joi from 'joi'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getStats, getBeats } from '../../../../lib/beats'; import { handleError } from '../../../../lib/errors'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function beatsListingRoute(server) { server.route({ @@ -32,7 +33,7 @@ export function beatsListingRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const beatsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const beatsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); try { diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js index b2f0267265538a..0fc32f5c3de581 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/beats/overview.js @@ -10,6 +10,7 @@ import { getMetrics } from '../../../../lib/details/get_metrics'; import { getLatestStats, getStats } from '../../../../lib/beats'; import { handleError } from '../../../../lib/errors'; import { metricSet } from './metric_set_overview'; +import { INDEX_PATTERN_BEATS } from '../../../../../common/constants'; export function beatsOverviewRoute(server) { server.route({ @@ -34,7 +35,7 @@ export function beatsOverviewRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const beatsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); + const beatsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); try { const [ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js index 1b0d3d83f13168..7c3344626f852d 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/cluster.js @@ -8,6 +8,13 @@ import Joi from 'joi'; import { getClustersFromRequest } from '../../../../lib/cluster/get_clusters_from_request'; import { handleError } from '../../../../lib/errors'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { + INDEX_PATTERN_KIBANA, + INDEX_PATTERN_ELASTICSEARCH, + INDEX_PATTERN_LOGSTASH, + INDEX_PATTERN_BEATS, + INDEX_ALERTS +} from '../../../../../common/constants'; export function clusterRoute(server) { /* @@ -33,12 +40,12 @@ export function clusterRoute(server) { handler: (req) => { const config = server.config(); const ccs = req.payload.ccs; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); - const kbnIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.kibana.index_pattern', ccs); - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); - const beatsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); - const apmIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); - const alertsIndex = prefixIndexPattern(config, 'xpack.monitoring.cluster_alerts.index', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); + const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); + const beatsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); + const apmIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); + const alertsIndex = prefixIndexPattern(config, INDEX_ALERTS, ccs); const indexPatterns = { esIndexPattern, kbnIndexPattern, lsIndexPattern, beatsIndexPattern, apmIndexPattern, alertsIndex }; const options = { clusterUuid: req.params.clusterUuid, diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js index 5d3a903ab38d71..2ce91020623df6 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/cluster/clusters.js @@ -9,6 +9,13 @@ import { getClustersFromRequest } from '../../../../lib/cluster/get_clusters_fro import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth'; import { handleError } from '../../../../lib/errors'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { + INDEX_PATTERN_ELASTICSEARCH, + INDEX_PATTERN_KIBANA, + INDEX_PATTERN_LOGSTASH, + INDEX_PATTERN_BEATS, + INDEX_ALERTS +} from '../../../../../common/constants'; export function clustersRoute(server) { /* @@ -40,12 +47,12 @@ export function clustersRoute(server) { // wildcard means to search _all_ clusters const ccs = '*'; const config = server.config(); - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); - const kbnIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.kibana.index_pattern', ccs); - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); - const beatsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); - const apmIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.beats.index_pattern', ccs); - const alertsIndex = prefixIndexPattern(config, 'xpack.monitoring.cluster_alerts.index', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); + const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); + const beatsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); + const apmIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_BEATS, ccs); + const alertsIndex = prefixIndexPattern(config, INDEX_ALERTS, ccs); const indexPatterns = { esIndexPattern, kbnIndexPattern, lsIndexPattern, beatsIndexPattern, apmIndexPattern, alertsIndex }; clusters = await getClustersFromRequest(req, indexPatterns); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js index b3e85cdcee1e80..9047d1f676e853 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr.js @@ -9,6 +9,7 @@ import moment from 'moment'; import { get, groupBy } from 'lodash'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; function getBucketScript(max, min) { return { @@ -185,7 +186,7 @@ export function ccrRoute(server) { async handler(req) { const config = server.config(); const ccs = req.payload.ccs; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); try { const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js index cc8268a3599114..955c32d5b6a79f 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ccr_shard.js @@ -10,6 +10,7 @@ import Joi from 'joi'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getMetrics } from '../../../../lib/details/get_metrics'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; function getFormattedLeaderIndex(leaderIndex) { let leader = leaderIndex; @@ -92,7 +93,7 @@ export function ccrShardRoute(server) { const index = req.params.index; const shardId = req.params.shardId; const ccs = req.payload.ccs; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); const filters = [ { diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js index e27ec33db86ab1..76ba483b0fdd74 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/index_detail.js @@ -13,6 +13,7 @@ import { getShardAllocation, getShardStats } from '../../../../lib/elasticsearch import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSet } from './metric_set_index_detail'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; const { advanced: metricSetAdvanced, overview: metricSetOverview } = metricSet; @@ -45,7 +46,7 @@ export function esIndexRoute(server) { const indexUuid = req.params.id; const start = req.payload.timeRange.min; const end = req.payload.timeRange.max; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); const isAdvanced = req.payload.is_advanced; const metricSet = isAdvanced ? metricSetAdvanced : metricSetOverview; diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js index 4e9d434372bae0..22ad4f6e330c47 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/indices.js @@ -11,6 +11,7 @@ import { getIndices } from '../../../../lib/elasticsearch/indices'; import { getShardStats } from '../../../../lib/elasticsearch/shards'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; export function esIndicesRoute(server) { server.route({ @@ -38,7 +39,7 @@ export function esIndicesRoute(server) { const { clusterUuid } = req.params; const { show_system_indices: showSystemIndices } = req.query; const { ccs } = req.payload; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); try { const clusterStats = await getClusterStats(req, esIndexPattern, clusterUuid); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js index f6387bd1fa25e5..a84e63539554e8 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/ml_jobs.js @@ -11,6 +11,7 @@ import { getMlJobs } from '../../../../lib/elasticsearch/get_ml_jobs'; import { getShardStats } from '../../../../lib/elasticsearch/shards'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; export function mlJobRoute(server) { server.route({ @@ -34,7 +35,7 @@ export function mlJobRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); try { const clusterStats = await getClusterStats(req, esIndexPattern, clusterUuid); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js index 6f5d37930e7c19..2bec1646f896e9 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/node_detail.js @@ -13,6 +13,7 @@ import { getMetrics } from '../../../../lib/details/get_metrics'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSets } from './metric_set_node_detail'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; const { advanced: metricSetAdvanced, overview: metricSetOverview } = metricSets; @@ -45,7 +46,7 @@ export function esNodeRoute(server) { const nodeUuid = req.params.nodeUuid; const start = req.payload.timeRange.min; const end = req.payload.timeRange.max; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); const isAdvanced = req.payload.is_advanced; let metricSet; diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js index 7fe93e1394b219..217cc3d2262c98 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/nodes.js @@ -11,6 +11,7 @@ import { getNodes } from '../../../../lib/elasticsearch/nodes'; import { getShardStats } from '../../../../lib/elasticsearch/shards'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; export function esNodesRoute(server) { server.route({ @@ -34,7 +35,7 @@ export function esNodesRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); try { const clusterStats = await getClusterStats(req, esIndexPattern, clusterUuid); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js index ad1d65c67b6b09..068c36f5064e92 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/elasticsearch/overview.js @@ -13,6 +13,7 @@ import { getShardStats } from '../../../../lib/elasticsearch/shards'; import { handleError } from '../../../../lib/errors/handle_error'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSet } from './metric_set_overview'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../common/constants'; export function esOverviewRoute(server) { server.route({ @@ -36,7 +37,7 @@ export function esOverviewRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const esIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.elasticsearch.index_pattern', ccs); + const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); try { const [ clusterStats, metrics, shardActivity ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js index 6486ea530d53f6..39d16c4e6fa97f 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instance.js @@ -10,6 +10,7 @@ import { handleError } from '../../../../lib/errors'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSet } from './metric_set_instance'; +import { INDEX_PATTERN_KIBANA } from '../../../../../common/constants'; /** * Kibana instance: This will fetch all data required to display a Kibana @@ -41,7 +42,7 @@ export function kibanaInstanceRoute(server) { const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; const kibanaUuid = req.params.kibanaUuid; - const kbnIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.kibana.index_pattern', ccs); + const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); try { const [ metrics, kibanaSummary ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js index 580172ecd7ecea..ca076fd8aec64b 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/instances.js @@ -9,6 +9,7 @@ import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { getKibanaClusterStatus } from './_get_kibana_cluster_status'; import { getKibanas } from '../../../../lib/kibana/get_kibanas'; import { handleError } from '../../../../lib/errors'; +import { INDEX_PATTERN_KIBANA } from '../../../../../common/constants'; export function kibanaInstancesRoute(server) { /** @@ -35,7 +36,7 @@ export function kibanaInstancesRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const kbnIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.kibana.index_pattern', ccs); + const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); try { const [ clusterStatus, kibanas ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js index b7f396eef138fb..275ac81127b975 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/kibana/overview.js @@ -10,6 +10,7 @@ import { getKibanaClusterStatus } from './_get_kibana_cluster_status'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { metricSet } from './metric_set_overview'; import { handleError } from '../../../../lib/errors'; +import { INDEX_PATTERN_KIBANA } from '../../../../../common/constants'; export function kibanaOverviewRoute(server) { /** @@ -36,7 +37,7 @@ export function kibanaOverviewRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const kbnIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.kibana.index_pattern', ccs); + const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); try { const [ clusterStatus, metrics ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js index 6916fa871e810b..28755903c82b87 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/node.js @@ -10,6 +10,7 @@ import { handleError } from '../../../../lib/errors'; import { getMetrics } from '../../../../lib/details/get_metrics'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSets } from './metric_set_node'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../common/constants'; const { advanced: metricSetAdvanced, overview: metricSetOverview } = metricSets; @@ -50,7 +51,7 @@ export function logstashNodeRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); const logstashUuid = req.params.logstashUuid; let metricSet; diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js index 34e3b6cb2a4ccf..f0af65bccaff5c 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/nodes.js @@ -9,6 +9,7 @@ import { getClusterStatus } from '../../../../lib/logstash/get_cluster_status'; import { getNodes } from '../../../../lib/logstash/get_nodes'; import { handleError } from '../../../../lib/errors'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../common/constants'; /* * Logstash Nodes route. @@ -45,7 +46,7 @@ export function logstashNodesRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); try { const [ clusterStatus, nodes ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js index 35fe0271a1885e..c8cfc5b74c9fc6 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/overview.js @@ -10,6 +10,7 @@ import { getMetrics } from '../../../../lib/details/get_metrics'; import { handleError } from '../../../../lib/errors'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; import { metricSet } from './metric_set_overview'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../common/constants'; /* * Logstash Overview route. @@ -46,7 +47,7 @@ export function logstashOverviewRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); try { const [ metrics, clusterStatus ] = await Promise.all([ diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js index 3a93dd57a98182..433c48f02b3eaa 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipeline.js @@ -8,6 +8,7 @@ import Joi from 'joi'; import { handleError } from '../../../../lib/errors'; import { getPipeline } from '../../../../lib/logstash/get_pipeline'; import { prefixIndexPattern } from '../../../../lib/ccs_utils'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../common/constants'; /* * Logstash Pipeline route. @@ -41,7 +42,7 @@ export function logstashPipelineRoute(server) { const config = server.config(); const ccs = req.payload.ccs; const clusterUuid = req.params.clusterUuid; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); const pipelineId = req.params.pipelineId; // Optional params default to empty string, set to null to be more explicit. diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js index 5a90e4ec9e9dc3..247e734360dc91 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/cluster_pipelines.js @@ -9,6 +9,7 @@ import { getClusterStatus } from '../../../../../lib/logstash/get_cluster_status import { getPipelines, processPipelinesAPIResponse } from '../../../../../lib/logstash/get_pipelines'; import { handleError } from '../../../../../lib/errors'; import { prefixIndexPattern } from '../../../../../lib/ccs_utils'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../../common/constants'; /** * Retrieve pipelines for a cluster @@ -35,7 +36,7 @@ export function logstashClusterPipelinesRoute(server) { const config = server.config(); const { ccs } = req.payload; const clusterUuid = req.params.clusterUuid; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); const throughputMetric = 'logstash_cluster_pipeline_throughput'; const nodesCountMetric = 'logstash_cluster_pipeline_nodes_count'; diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js index 8aace30bb61f31..faec0791d7c326 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js +++ b/x-pack/plugins/monitoring/server/routes/api/v1/logstash/pipelines/node_pipelines.js @@ -9,6 +9,7 @@ import { getNodeInfo } from '../../../../../lib/logstash/get_node_info'; import { getPipelines, processPipelinesAPIResponse } from '../../../../../lib/logstash/get_pipelines'; import { handleError } from '../../../../../lib/errors'; import { prefixIndexPattern } from '../../../../../lib/ccs_utils'; +import { INDEX_PATTERN_LOGSTASH } from '../../../../../../common/constants'; /** * Retrieve pipelines for a node @@ -36,7 +37,7 @@ export function logstashNodePipelinesRoute(server) { const config = server.config(); const { ccs } = req.payload; const { clusterUuid, logstashUuid } = req.params; - const lsIndexPattern = prefixIndexPattern(config, 'xpack.monitoring.logstash.index_pattern', ccs); + const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs); const throughputMetric = 'logstash_node_pipeline_throughput'; const nodesCountMetric = 'logstash_node_pipeline_nodes_count'; const metricSet = [ diff --git a/x-pack/plugins/xpack_main/common/constants.js b/x-pack/plugins/xpack_main/common/constants.js index 5f0b956fb1da6f..1dec1a2264ea0b 100644 --- a/x-pack/plugins/xpack_main/common/constants.js +++ b/x-pack/plugins/xpack_main/common/constants.js @@ -34,6 +34,12 @@ export const KIBANA_SYSTEM_ID = 'kibana'; */ export const BEATS_SYSTEM_ID = 'beats'; +/** + * The name of the Apm System ID used to publish and look up Apm stats through the Monitoring system. + * @type {string} + */ +export const APM_SYSTEM_ID = 'beats'; + /** * The name of the Kibana System ID used to look up Logstash stats through the Monitoring system. * @type {string} diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js index 321e2ebdad642c..d38d8f519c047b 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js @@ -6,6 +6,7 @@ import { get } from 'lodash'; import { createQuery } from './create_query'; +import { INDEX_PATTERN_BEATS } from '../../../../../monitoring/common/constants'; const HITS_SIZE = 10000; // maximum hits to receive from ES with each search @@ -173,10 +174,8 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste * @return {Promise} */ async function fetchBeatsByType(server, callCluster, clusterUuids, start, end, { page = 0, ...options } = {}, type) { - const config = server.config(); - const params = { - index: config.get('xpack.monitoring.beats.index_pattern'), + index: INDEX_PATTERN_BEATS, ignoreUnavailable: true, filterPath: [ 'hits.hits._source.cluster_uuid', diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_cluster_uuids.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_cluster_uuids.js index f573a71b77d5e1..9f8aac44a47282 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_cluster_uuids.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_cluster_uuids.js @@ -6,6 +6,7 @@ import { get } from 'lodash'; import { createQuery } from './create_query'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../monitoring/common/constants'; /** * Get a list of Cluster UUIDs that exist within the specified timespan. @@ -33,7 +34,7 @@ export function getClusterUuids(server, callCluster, start, end) { export function fetchClusterUuids(server, callCluster, start, end) { const config = server.config(); const params = { - index: config.get('xpack.monitoring.elasticsearch.index_pattern'), + index: INDEX_PATTERN_ELASTICSEARCH, size: 0, ignoreUnavailable: true, filterPath: 'aggregations.cluster_uuids.buckets.key', diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_es_stats.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_es_stats.js index 377ce8160f2b49..55198a5ec85d48 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_es_stats.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_es_stats.js @@ -5,6 +5,7 @@ */ import { get } from 'lodash'; +import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../../monitoring/common/constants'; /** * Get statistics for all selected Elasticsearch clusters. @@ -30,7 +31,7 @@ export function getElasticsearchStats(server, callCluster, clusterUuids) { export function fetchElasticsearchStats(server, callCluster, clusterUuids) { const config = server.config(); const params = { - index: config.get('xpack.monitoring.elasticsearch.index_pattern'), + index: INDEX_PATTERN_ELASTICSEARCH, size: config.get('xpack.monitoring.max_bucket_size'), ignoreUnavailable: true, filterPath: [ diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_high_level_stats.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_high_level_stats.js index b845fb5115492c..fbbb81d6fd89ea 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_high_level_stats.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_high_level_stats.js @@ -6,6 +6,8 @@ import { get } from 'lodash'; import { createQuery } from './create_query'; +import { INDEX_PATTERN_KIBANA, INDEX_PATTERN_BEATS, INDEX_PATTERN_LOGSTASH } from '../../../../../monitoring/common/constants'; +import { KIBANA_SYSTEM_ID, BEATS_SYSTEM_ID, APM_SYSTEM_ID, LOGSTASH_SYSTEM_ID } from '../../../../common/constants'; /** * Update a counter associated with the {@code key}. @@ -139,6 +141,24 @@ function mapToList(map, keyName) { return list; } +/** + * Returns the right index pattern to find monitoring documents based on the product id + * + * @param {*} product The product id, which should be in the constants file + */ +function getIndexPatternForStackProduct(product) { + switch (product) { + case KIBANA_SYSTEM_ID: + return INDEX_PATTERN_KIBANA; + case BEATS_SYSTEM_ID: + case APM_SYSTEM_ID: + return INDEX_PATTERN_BEATS; + case LOGSTASH_SYSTEM_ID: + return INDEX_PATTERN_LOGSTASH; + } + return null; +} + /** * Get statistics about selected Elasticsearch clusters, for the selected {@code product}. * @@ -170,7 +190,7 @@ export function getHighLevelStats(server, callCluster, clusterUuids, start, end, export function fetchHighLevelStats(server, callCluster, clusterUuids, start, end, product) { const config = server.config(); const params = { - index: config.get(`xpack.monitoring.${product}.index_pattern`), + index: getIndexPatternForStackProduct(product), size: config.get('xpack.monitoring.max_bucket_size'), ignoreUnavailable: true, filterPath: [