Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1] [Stack Monitoring] More typescript conversion (#126654) #126719

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import { Logger, ICustomClusterClient, ElasticsearchClientConfig } from 'kibana/server';
// @ts-ignore
import { monitoringBulk } from '../kibana_monitoring/lib/monitoring_bulk';
import { monitoringEndpointDisableWatches } from './monitoring_endpoint_disable_watches';
import { MonitoringElasticsearchConfig } from '../config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* 2.0.
*/

export function monitoringBulk(Client, _config, components) {
// TODO: Track down where this function is called by the elasticsearch client setup so we can properly type these

export function monitoringBulk(Client: any, _config: any, components: any) {
const ca = components.clientAction.factory;
Client.prototype.monitoring = components.clientAction.namespaceFactory();
const monitoring = Client.prototype.monitoring.prototype;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function getClustersFromRequest(
start,
end,
codePaths,
}: { clusterUuid: string; start: number; end: number; codePaths: string[] }
}: { clusterUuid?: string; start?: number; end?: number; codePaths: string[] }
) {
const { filebeatIndexPattern } = indexPatterns;

Expand Down Expand Up @@ -96,13 +96,14 @@ export async function getClustersFromRequest(
cluster.ml = { jobs: mlJobs };
}

cluster.logs = isInCodePath(codePaths, [CODE_PATH_LOGS])
? await getLogTypes(req, filebeatIndexPattern, {
clusterUuid: get(cluster, 'elasticsearch.cluster.id', cluster.cluster_uuid),
start,
end,
})
: [];
cluster.logs =
start && end && isInCodePath(codePaths, [CODE_PATH_LOGS])
? await getLogTypes(req, filebeatIndexPattern, {
clusterUuid: get(cluster, 'elasticsearch.cluster.id', cluster.cluster_uuid),
start,
end,
})
: [];
} else if (!isStandaloneCluster) {
// get all clusters
if (!clusters || clusters.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Globals } from '../../static_globals';
* @param {String} clusterUuid (optional) If not undefined, getClusters will filter for a single cluster
* @return {Promise} A promise containing an array of clusters.
*/
export function getClustersStats(req: LegacyRequest, clusterUuid: string, ccs?: string) {
export function getClustersStats(req: LegacyRequest, clusterUuid?: string, ccs?: string) {
return (
fetchClusterStats(req, clusterUuid, ccs)
.then((response) => handleClusterStats(response))
Expand All @@ -42,7 +42,7 @@ export function getClustersStats(req: LegacyRequest, clusterUuid: string, ccs?:
* @param {String} clusterUuid (optional) - if not undefined, getClusters filters for a single clusterUuid
* @return {Promise} Object representing each cluster.
*/
function fetchClusterStats(req: LegacyRequest, clusterUuid: string, ccs?: string) {
function fetchClusterStats(req: LegacyRequest, clusterUuid?: string, ccs?: string) {
const dataset = 'cluster_stats';
const moduleType = 'elasticsearch';
const indexPattern = getNewIndexPatterns({
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/lib/create_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ interface CreateQueryOptions {
dsDataset?: string;
metricset?: string;
filters?: any[];
clusterUuid: string;
clusterUuid?: string;
uuid?: string;
start?: number;
end?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { LegacyRequest } from '../../types';
*
* @param req {Object} the server route handler request object
*/

// TODO: replace LegacyRequest with current request object + plugin retrieval
export async function verifyMonitoringAuth(req: LegacyRequest) {
const xpackInfo = get(req.server.plugins.monitoring, 'info');

Expand All @@ -38,6 +40,8 @@ export async function verifyMonitoringAuth(req: LegacyRequest) {
* @param req {Object} the server route handler request object
* @return {Promise} That either resolves with no response (void) or an exception.
*/

// TODO: replace LegacyRequest with current request object + plugin retrieval
async function verifyHasPrivileges(req: LegacyRequest) {
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Globals } from '../../static_globals';

interface GetLogstashPipelineIdsParams {
req: LegacyRequest;
clusterUuid: string;
clusterUuid?: string;
size: number;
logstashUuid?: string;
ccs?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth';
import { handleError } from '../../../../lib/errors';
import { LegacyRequest, LegacyServer } from '../../../../types';

/*
* API for checking read privilege on Monitoring Data
* Used for the "Access Denied" page as something to auto-retry with.
*/
export function checkAccessRoute(server) {

// TODO: Replace this LegacyServer call with the "new platform" core Kibana route method
export function checkAccessRoute(server: LegacyServer) {
server.route({
method: 'GET',
path: '/api/monitoring/v1/check_access',
handler: async (req) => {
const response = {};
handler: async (req: LegacyRequest) => {
const response: { has_access?: boolean } = {};
try {
await verifyMonitoringAuth(req);
response.has_access = true; // response data is ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
*/

import { schema } from '@kbn/config-schema';
import { LegacyRequest, LegacyServer } from '../../../../types';
import { getClustersFromRequest } from '../../../../lib/cluster/get_clusters_from_request';
import { verifyMonitoringAuth } from '../../../../lib/elasticsearch/verify_monitoring_auth';
import { handleError } from '../../../../lib/errors';
import { getIndexPatterns } from '../../../../lib/cluster/get_index_patterns';

export function clustersRoute(server) {
export function clustersRoute(server: LegacyServer) {
/*
* Monitoring Home
* Route Init (for checking license and compatibility for multi-cluster monitoring
*/

// TODO switch from the LegacyServer route() method to the "new platform" route methods
server.route({
method: 'POST',
path: '/api/monitoring/v1/clusters',
Expand All @@ -30,7 +33,7 @@ export function clustersRoute(server) {
}),
},
},
handler: async (req) => {
handler: async (req: LegacyRequest) => {
let clusters = [];
const config = server.config;

Expand All @@ -43,7 +46,7 @@ export function clustersRoute(server) {
filebeatIndexPattern: config.ui.logs.index,
});
clusters = await getClustersFromRequest(req, indexPatterns, {
codePaths: req.payload.codePaths,
codePaths: req.payload.codePaths as string[], // TODO remove this cast when we can properly type req by using the right route handler
});
} catch (err) {
throw handleError(err, req);
Expand Down