mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Stack Monitoring] Convert elasticsearch_settings routes to TypeScript (#131261)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
2b5de747a6
commit
9ca3f4a92d
12 changed files with 128 additions and 36 deletions
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
|
||||
export const getElasticsearchSettingsClusterResponsePayloadRT = rt.type({
|
||||
// TODO: add payload entries
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
|
||||
export const getElasticsearchSettingsNodesResponsePayloadRT = rt.type({
|
||||
// TODO: add payload entries
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export * from './get_elasticsearch_settings_cluster';
|
||||
export * from './get_elasticsearch_settings_nodes';
|
||||
export * from './post_elasticsearch_settings_internal_monitoring';
|
||||
export * from './put_elasticsearch_settings_collection_enabled';
|
||||
export * from './put_elasticsearch_settings_collection_interval';
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
import { ccsRT } from '../shared';
|
||||
|
||||
export const postElasticsearchSettingsInternalMonitoringRequestPayloadRT = rt.partial({
|
||||
ccs: ccsRT,
|
||||
});
|
||||
|
||||
export type PostElasticsearchSettingsInternalMonitoringRequestPayload = rt.TypeOf<
|
||||
typeof postElasticsearchSettingsInternalMonitoringRequestPayloadRT
|
||||
>;
|
||||
|
||||
export const postElasticsearchSettingsInternalMonitoringResponsePayloadRT = rt.type({
|
||||
body: rt.type({
|
||||
legacy_indices: rt.number,
|
||||
mb_indices: rt.number,
|
||||
}),
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
|
||||
export const putElasticsearchSettingsCollectionEnabledResponsePayloadRT = rt.type({
|
||||
// TODO: add payload entries
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
|
||||
export const putElasticsearchSettingsCollectionIntervalResponsePayloadRT = rt.type({
|
||||
// TODO: add payload entries
|
||||
});
|
|
@ -5,25 +5,25 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { getElasticsearchSettingsClusterResponsePayloadRT } from '../../../../../../common/http_api/elasticsearch_settings';
|
||||
import { checkClusterSettings } from '../../../../../lib/elasticsearch_settings';
|
||||
import { handleSettingsError } from '../../../../../lib/errors';
|
||||
import { MonitoringCore } from '../../../../../types';
|
||||
|
||||
/*
|
||||
* Cluster Settings Check Route
|
||||
*/
|
||||
export function clusterSettingsCheckRoute(server) {
|
||||
export function clusterSettingsCheckRoute(server: MonitoringCore) {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
method: 'get',
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/check/cluster',
|
||||
config: {
|
||||
validate: {},
|
||||
},
|
||||
validate: {},
|
||||
async handler(req) {
|
||||
try {
|
||||
const response = await checkClusterSettings(req); // needs to be try/catch to handle privilege error
|
||||
return response;
|
||||
return getElasticsearchSettingsClusterResponsePayloadRT.encode(response);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
server.log.error(err);
|
||||
throw handleSettingsError(err);
|
||||
}
|
||||
},
|
|
@ -5,17 +5,21 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { RequestHandlerContext } from '@kbn/core/server';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { RequestHandlerContext } from '@kbn/core/server';
|
||||
import { prefixIndexPatternWithCcs } from '../../../../../../common/ccs_utils';
|
||||
import {
|
||||
INDEX_PATTERN_ELASTICSEARCH,
|
||||
INDEX_PATTERN_KIBANA,
|
||||
INDEX_PATTERN_LOGSTASH,
|
||||
} from '../../../../../../common/constants';
|
||||
import { prefixIndexPatternWithCcs } from '../../../../../../common/ccs_utils';
|
||||
import {
|
||||
postElasticsearchSettingsInternalMonitoringRequestPayloadRT,
|
||||
postElasticsearchSettingsInternalMonitoringResponsePayloadRT,
|
||||
} from '../../../../../../common/http_api/elasticsearch_settings';
|
||||
import { createValidationFunction } from '../../../../../lib/create_route_validation_function';
|
||||
import { handleError } from '../../../../../lib/errors';
|
||||
import { RouteDependencies, LegacyServer } from '../../../../../types';
|
||||
import { LegacyServer, RouteDependencies } from '../../../../../types';
|
||||
|
||||
const queryBody = {
|
||||
size: 0,
|
||||
|
@ -69,13 +73,15 @@ const checkLatestMonitoringIsLegacy = async (context: RequestHandlerContext, ind
|
|||
};
|
||||
|
||||
export function internalMonitoringCheckRoute(server: LegacyServer, npRoute: RouteDependencies) {
|
||||
const validateBody = createValidationFunction(
|
||||
postElasticsearchSettingsInternalMonitoringRequestPayloadRT
|
||||
);
|
||||
|
||||
npRoute.router.post(
|
||||
{
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/check/internal_monitoring',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
ccs: schema.maybe(schema.string()),
|
||||
}),
|
||||
body: validateBody,
|
||||
},
|
||||
},
|
||||
async (context, request, response) => {
|
||||
|
@ -101,9 +107,11 @@ export function internalMonitoringCheckRoute(server: LegacyServer, npRoute: Rout
|
|||
typeCount.mb_indices += counts.mbIndicesCount;
|
||||
});
|
||||
|
||||
return response.ok({
|
||||
body: typeCount,
|
||||
});
|
||||
return response.ok(
|
||||
postElasticsearchSettingsInternalMonitoringResponsePayloadRT.encode({
|
||||
body: typeCount,
|
||||
})
|
||||
);
|
||||
} catch (err) {
|
||||
throw handleError(err);
|
||||
}
|
||||
|
|
|
@ -5,23 +5,23 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { getElasticsearchSettingsNodesResponsePayloadRT } from '../../../../../../common/http_api/elasticsearch_settings';
|
||||
import { checkNodesSettings } from '../../../../../lib/elasticsearch_settings';
|
||||
import { handleSettingsError } from '../../../../../lib/errors';
|
||||
import { MonitoringCore } from '../../../../../types';
|
||||
|
||||
/*
|
||||
* Cluster Settings Check Route
|
||||
*/
|
||||
export function nodesSettingsCheckRoute(server) {
|
||||
export function nodesSettingsCheckRoute(server: MonitoringCore) {
|
||||
server.route({
|
||||
method: 'GET',
|
||||
method: 'get',
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/check/nodes',
|
||||
config: {
|
||||
validate: {},
|
||||
},
|
||||
validate: {},
|
||||
async handler(req) {
|
||||
try {
|
||||
const response = await checkNodesSettings(req); // needs to be try/catch to handle privilege error
|
||||
return response;
|
||||
return getElasticsearchSettingsNodesResponsePayloadRT.encode(response);
|
||||
} catch (err) {
|
||||
throw handleSettingsError(err);
|
||||
}
|
|
@ -5,8 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export { internalMonitoringCheckRoute } from './check/internal_monitoring';
|
||||
export { clusterSettingsCheckRoute } from './check/cluster';
|
||||
export { internalMonitoringCheckRoute } from './check/internal_monitoring';
|
||||
export { nodesSettingsCheckRoute } from './check/nodes';
|
||||
export { setCollectionEnabledRoute } from './set/collection_enabled';
|
||||
export { setCollectionIntervalRoute } from './set/collection_interval';
|
|
@ -5,23 +5,23 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { putElasticsearchSettingsCollectionEnabledResponsePayloadRT } from '../../../../../../common/http_api/elasticsearch_settings';
|
||||
import { setCollectionEnabled } from '../../../../../lib/elasticsearch_settings';
|
||||
import { handleSettingsError } from '../../../../../lib/errors';
|
||||
import { MonitoringCore } from '../../../../../types';
|
||||
|
||||
/*
|
||||
* Cluster Settings Check Route
|
||||
*/
|
||||
export function setCollectionEnabledRoute(server) {
|
||||
export function setCollectionEnabledRoute(server: MonitoringCore) {
|
||||
server.route({
|
||||
method: 'PUT',
|
||||
method: 'put',
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/set/collection_enabled',
|
||||
config: {
|
||||
validate: {},
|
||||
},
|
||||
validate: {},
|
||||
async handler(req) {
|
||||
try {
|
||||
const response = await setCollectionEnabled(req);
|
||||
return response;
|
||||
return putElasticsearchSettingsCollectionEnabledResponsePayloadRT.encode(response);
|
||||
} catch (err) {
|
||||
throw handleSettingsError(err);
|
||||
}
|
|
@ -5,23 +5,23 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { putElasticsearchSettingsCollectionIntervalResponsePayloadRT } from '../../../../../../common/http_api/elasticsearch_settings';
|
||||
import { setCollectionInterval } from '../../../../../lib/elasticsearch_settings';
|
||||
import { handleSettingsError } from '../../../../../lib/errors';
|
||||
import { MonitoringCore } from '../../../../../types';
|
||||
|
||||
/*
|
||||
* Cluster Settings Check Route
|
||||
*/
|
||||
export function setCollectionIntervalRoute(server) {
|
||||
export function setCollectionIntervalRoute(server: MonitoringCore) {
|
||||
server.route({
|
||||
method: 'PUT',
|
||||
method: 'put',
|
||||
path: '/api/monitoring/v1/elasticsearch_settings/set/collection_interval',
|
||||
config: {
|
||||
validate: {},
|
||||
},
|
||||
validate: {},
|
||||
async handler(req) {
|
||||
try {
|
||||
const response = await setCollectionInterval(req);
|
||||
return response;
|
||||
return putElasticsearchSettingsCollectionIntervalResponsePayloadRT.encode(response);
|
||||
} catch (err) {
|
||||
throw handleSettingsError(err);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue