[Monitoring] Fixed internal monitoring check (#79241)
* fixed internal monitoring check * Added range filter * Added single vs ccs condtion * Fixed spelling * Passing global state ccs Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c90045720b
commit
cd4df4bbf9
|
@ -69,9 +69,11 @@ export function monitoringClustersProvider($injector) {
|
|||
if (Legacy.shims.isCloud) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const globalState = $injector.get('globalState');
|
||||
return $http
|
||||
.get('../api/monitoring/v1/elasticsearch_settings/check/internal_monitoring')
|
||||
.post('../api/monitoring/v1/elasticsearch_settings/check/internal_monitoring', {
|
||||
ccs: globalState.ccs,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
showInternalMonitoringToast({
|
||||
legacyIndices: data.legacy_indices,
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
*/
|
||||
import { isFunction, get } from 'lodash';
|
||||
|
||||
export function appendMetricbeatIndex(config, indexPattern) {
|
||||
export function appendMetricbeatIndex(config, indexPattern, bypass = false) {
|
||||
if (bypass) {
|
||||
return indexPattern;
|
||||
}
|
||||
// Leverage this function to also append the dynamic metricbeat index too
|
||||
let mbIndex = null;
|
||||
// TODO: NP
|
||||
|
@ -16,8 +19,7 @@ export function appendMetricbeatIndex(config, indexPattern) {
|
|||
mbIndex = get(config, 'ui.metricbeat.index');
|
||||
}
|
||||
|
||||
const newIndexPattern = `${indexPattern},${mbIndex}`;
|
||||
return newIndexPattern;
|
||||
return `${indexPattern},${mbIndex}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +33,7 @@ export function appendMetricbeatIndex(config, indexPattern) {
|
|||
* @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, indexPattern, ccs) {
|
||||
export function prefixIndexPattern(config, indexPattern, ccs, monitoringIndicesOnly = false) {
|
||||
let ccsEnabled = false;
|
||||
// TODO: NP
|
||||
// This function is called with both NP config and LP config
|
||||
|
@ -42,7 +44,7 @@ export function prefixIndexPattern(config, indexPattern, ccs) {
|
|||
}
|
||||
|
||||
if (!ccsEnabled || !ccs) {
|
||||
return appendMetricbeatIndex(config, indexPattern);
|
||||
return appendMetricbeatIndex(config, indexPattern, monitoringIndicesOnly);
|
||||
}
|
||||
|
||||
const patterns = indexPattern.split(',');
|
||||
|
@ -50,10 +52,14 @@ export function prefixIndexPattern(config, indexPattern, ccs) {
|
|||
|
||||
// if a wildcard is used, then we also want to search the local indices
|
||||
if (ccs === '*') {
|
||||
return appendMetricbeatIndex(config, `${prefixedPattern},${indexPattern}`);
|
||||
return appendMetricbeatIndex(
|
||||
config,
|
||||
`${prefixedPattern},${indexPattern}`,
|
||||
monitoringIndicesOnly
|
||||
);
|
||||
}
|
||||
|
||||
return appendMetricbeatIndex(config, prefixedPattern);
|
||||
return appendMetricbeatIndex(config, prefixedPattern, monitoringIndicesOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,15 +4,34 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { RequestHandlerContext } from 'kibana/server';
|
||||
import {
|
||||
INDEX_PATTERN_ELASTICSEARCH,
|
||||
INDEX_PATTERN_KIBANA,
|
||||
INDEX_PATTERN_LOGSTASH,
|
||||
} from '../../../../../../common/constants';
|
||||
// @ts-ignore
|
||||
import { getIndexPatterns } from '../../../../../lib/cluster/get_index_patterns';
|
||||
import { prefixIndexPattern } from '../../../../../lib/ccs_utils';
|
||||
// @ts-ignore
|
||||
import { handleError } from '../../../../../lib/errors';
|
||||
import { RouteDependencies } from '../../../../../types';
|
||||
|
||||
const queryBody = {
|
||||
size: 0,
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
range: {
|
||||
timestamp: {
|
||||
gte: 'now-12h',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
types: {
|
||||
terms: {
|
||||
|
@ -49,20 +68,31 @@ const checkLatestMonitoringIsLegacy = async (context: RequestHandlerContext, ind
|
|||
return counts;
|
||||
};
|
||||
|
||||
export function internalMonitoringCheckRoute(server: unknown, npRoute: RouteDependencies) {
|
||||
npRoute.router.get(
|
||||
export function internalMonitoringCheckRoute(
|
||||
server: { config: () => unknown },
|
||||
npRoute: RouteDependencies
|
||||
) {
|
||||
npRoute.router.post(
|
||||
{
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/check/internal_monitoring',
|
||||
validate: false,
|
||||
validate: {
|
||||
body: schema.object({
|
||||
ccs: schema.maybe(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async (context, _request, response) => {
|
||||
async (context, request, response) => {
|
||||
try {
|
||||
const typeCount = {
|
||||
legacy_indices: 0,
|
||||
mb_indices: 0,
|
||||
};
|
||||
|
||||
const { esIndexPattern, kbnIndexPattern, lsIndexPattern } = getIndexPatterns(server);
|
||||
const config = server.config();
|
||||
const { ccs } = request.body;
|
||||
const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs, true);
|
||||
const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs, true);
|
||||
const lsIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_LOGSTASH, ccs, true);
|
||||
const indexCounts = await Promise.all([
|
||||
checkLatestMonitoringIsLegacy(context, esIndexPattern),
|
||||
checkLatestMonitoringIsLegacy(context, kbnIndexPattern),
|
||||
|
|
Loading…
Reference in a new issue