mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
* update queries for elasticsearch package * fix unit test * add gitCcs helper function * modify rest of es queries * update logstash and kibana queries to use new createQuery * change beats and apm to use new createQuery * update changeQuery and remove old one * make getIndexPattern take request to check for ccs * fix unit test * fix unit tests * update queries and createQuery * don't add metric constant without dataset in query * fix types * fix type * comment out mb tests * fix unit test * fix unit test * fix * fix function param * change to getMetrics name * change to node_stats * comment out metricbeat tests * fix types * improve types and readability for test * remove passing of data stream type for now * add tests for createQuery changes * update getNewIndexPatterns to take one dataset * add unit test for getNewIndexPatterns * fix types * remove metrics from filter, update tests * update createNewIndexPatterns to accept new config instead of legacy * update alert queries to include datas stream index patterns * update comment * fix defaulting ccs to * for non cluster requests * update elasticsearch enterprise module * update unit test * remove data_stream.type from queries * change entsearch to metricbeat module name enterprisesearch * undo ccs cluster stats change * fix import * update alert queries * fix unit test * update unit test * change shard size query to use filter * change must to filter fix * update findSupportedBasicLicenseCluster index pattern * add ccs param to cluster request functions * update queries for ccs in get_clusters_from_request * update getBeatsForClusters query * update clusters apm query * update enterprisesearch query * move index pattern to query in fetch for alerts, fix ccs * remove metricbeat config from alert tests * fix ts * add metricset.name back to queries * comment tests back in * remove enterprise search checking for standalone cluster to fix test * update es index metricset name from index_stats to index for mb data * fix type * fetchClusters creates index pattern * fix type * remove monitoring.ui.metricbeat.index from config and usage in getCollectionStatus * fix type Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
92 lines
3 KiB
TypeScript
92 lines
3 KiB
TypeScript
/*
|
|
* 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 { isFunction, get } from 'lodash';
|
|
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
|
import type { MonitoringConfig } from '../server/config';
|
|
|
|
type Config = Partial<MonitoringConfig> & {
|
|
get?: (key: string) => any;
|
|
};
|
|
|
|
export function getConfigCcs(config: Config): boolean {
|
|
let ccsEnabled = false;
|
|
// TODO: NP
|
|
// This function is called with both NP config and LP config
|
|
if (isFunction(config.get)) {
|
|
ccsEnabled = config.get('monitoring.ui.ccs.enabled');
|
|
} else {
|
|
ccsEnabled = get(config, 'ui.ccs.enabled');
|
|
}
|
|
return ccsEnabled;
|
|
}
|
|
/**
|
|
* Prefix all comma separated index patterns within the original {@code indexPattern}.
|
|
*
|
|
* Cross-cluster search (CCS) prefixing is ignored if the user has disabled CCS via kibana.yml,
|
|
* which means that the index pattern will be returned without using {@code ccs}.
|
|
*
|
|
* @param {Object} config The Kibana configuration object.
|
|
* @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: Config, indexPattern: string, ccs?: string) {
|
|
const ccsEnabled = getConfigCcs(config);
|
|
if (!ccsEnabled || !ccs) {
|
|
return indexPattern;
|
|
}
|
|
|
|
const patterns = indexPattern.split(',');
|
|
const prefixedPattern = patterns.map((pattern) => `${ccs}:${pattern}`).join(',');
|
|
|
|
// if a wildcard is used, then we also want to search the local indices
|
|
if (ccs === '*') {
|
|
return `${prefixedPattern},${indexPattern}`;
|
|
}
|
|
return prefixedPattern;
|
|
}
|
|
|
|
/**
|
|
* Parse the cross-cluster prefix from an index name returned as part of a hit from Elasticsearch.
|
|
*
|
|
* For example, the first hit should return 'my_cluster', while the second hit should return null:
|
|
*
|
|
* {
|
|
* hits: {
|
|
* total: 2,
|
|
* hits: [
|
|
* {
|
|
* _index: my_cluster:.monitoring-es-6-2017.07.28,
|
|
* _type: doc,
|
|
* _id: xyz456,
|
|
* _source: { ... }
|
|
* },
|
|
* {
|
|
* _index: .monitoring-es-6-2017.07.28,
|
|
* _type: doc,
|
|
* _id: abc123,
|
|
* _source: { ... }
|
|
* }
|
|
* ]
|
|
* }
|
|
* }
|
|
*
|
|
* @param {String} indexName The index's name, possibly including the cross-cluster prefix
|
|
* @return {String} {@code null} if none. Otherwise the cluster prefix.
|
|
*/
|
|
export function parseCrossClusterPrefix(indexName: string) {
|
|
const colonIndex = indexName.indexOf(':');
|
|
|
|
if (colonIndex === -1) {
|
|
return null;
|
|
}
|
|
|
|
// if we found a : in the index name, then cross-cluster search (CCS) was used to find the cluster
|
|
// and we _should_ use it when we search explicitly for this cluster (to avoid inefficiently checking other monitoring _clusters_)
|
|
return indexName.substr(0, colonIndex);
|
|
}
|