Skip to content

Commit

Permalink
Add category examples route
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Jan 13, 2020
1 parent 892806e commit 2455a9f
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

export * from './log_entry_categories';
export * from './log_entry_category_datasets';
export * from './log_entry_category_examples';
export * from './log_entry_rate';
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as rt from 'io-ts';

import {
badRequestErrorRT,
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';

export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH =
'/api/infra/log_analysis/results/log_entry_category_examples';

/**
* request
*/

export const getLogEntryCategoryExamplesRequestPayloadRT = rt.type({
data: rt.type({
// the category to fetch the examples for
categoryId: rt.number,
// the number of examples to fetch
exampleCount: rt.number,
// the id of the source configuration
sourceId: rt.string,
// the time range to fetch the category examples from
timeRange: timeRangeRT,
}),
});

export type GetLogEntryCategoryExamplesRequestPayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesRequestPayloadRT
>;

/**
* response
*/

const logEntryCategoryExampleRT = rt.type({
timestamp: rt.number,
message: rt.string,
});

export type LogEntryCategoryExample = rt.TypeOf<typeof logEntryCategoryExampleRT>;

export const getLogEntryCategoryExamplesSuccessReponsePayloadRT = rt.intersection([
rt.type({
data: rt.type({
examples: rt.array(logEntryCategoryExampleRT),
}),
}),
rt.partial({
timing: routeTimingMetadataRT,
}),
]);

export type GetLogEntryCategoryExamplesSuccessResponsePayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesSuccessReponsePayloadRT
>;

export const getLogEntryCategoryExamplesResponsePayloadRT = rt.union([
getLogEntryCategoryExamplesSuccessReponsePayloadRT,
badRequestErrorRT,
forbiddenErrorRT,
]);

export type GetLogEntryCategoryExamplesReponsePayload = rt.TypeOf<
typeof getLogEntryCategoryExamplesResponsePayloadRT
>;
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ export const jobSourceConfigurationRT = rt.type({
});

export type JobSourceConfiguration = rt.TypeOf<typeof jobSourceConfigurationRT>;

export const jobCustomSettingsRT = rt.partial({
job_revision: rt.number,
logs_source_config: rt.partial(jobSourceConfigurationRT.props),
});

export type JobCustomSettings = rt.TypeOf<typeof jobCustomSettingsRT>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

import * as rt from 'io-ts';

import { jobSourceConfigurationRT } from '../../../../../common/log_analysis';

export const jobCustomSettingsRT = rt.partial({
job_revision: rt.number,
logs_source_config: rt.partial(jobSourceConfigurationRT.props),
});

export const getMlCapabilitiesResponsePayloadRT = rt.type({
capabilities: rt.type({
canGetJobs: rt.boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import * as rt from 'io-ts';
import { npStart } from 'ui/new_platform';
import { jobCustomSettingsRT } from './ml_api_types';
import { throwErrors, createPlainError } from '../../../../../common/runtime_types';
import { getJobId } from '../../../../../common/log_analysis';

import { getJobId, jobCustomSettingsRT } from '../../../../../common/log_analysis';
import { createPlainError, throwErrors } from '../../../../../common/runtime_types';

export const callJobsSummaryAPI = async <JobType extends string>(
spaceId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/

import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import * as rt from 'io-ts';
import { npStart } from 'ui/new_platform';
import { throwErrors, createPlainError } from '../../../../../common/runtime_types';
import { jobCustomSettingsRT } from './ml_api_types';

import { jobCustomSettingsRT } from '../../../../../common/log_analysis';
import { createPlainError, throwErrors } from '../../../../../common/runtime_types';

export const callGetMlModuleAPI = async (moduleId: string) => {
const response = await npStart.core.http.fetch(`/api/ml/modules/get_module/${moduleId}`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/

import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import * as rt from 'io-ts';
import { npStart } from 'ui/new_platform';
import { throwErrors, createPlainError } from '../../../../../common/runtime_types';
import { getJobIdPrefix } from '../../../../../common/log_analysis';

import { getJobIdPrefix, jobCustomSettingsRT } from '../../../../../common/log_analysis';
import { createPlainError, throwErrors } from '../../../../../common/runtime_types';

export const callSetupMlModuleAPI = async (
moduleId: string,
Expand Down Expand Up @@ -48,7 +49,10 @@ const setupMlModuleTimeParamsRT = rt.partial({
end: rt.number,
});

const setupMlModuleJobOverridesRT = rt.object;
const setupMlModuleJobOverridesRT = rt.type({
job_id: rt.string,
custom_settings: jobCustomSettingsRT,
});

export type SetupMlModuleJobOverrides = rt.TypeOf<typeof setupMlModuleJobOverridesRT>;

Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/infra/server/infra_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { InfraBackendLibs } from './lib/infra_types';
import {
initGetLogEntryCategoriesRoute,
initGetLogEntryCategoryDatasetsRoute,
initGetLogEntryCategoryExamplesRoute,
initGetLogEntryRateRoute,
initValidateLogAnalysisIndicesRoute,
} from './routes/log_analysis';
Expand Down Expand Up @@ -45,6 +46,7 @@ export const initInfraServer = (libs: InfraBackendLibs) => {
initIpToHostName(libs);
initGetLogEntryCategoriesRoute(libs);
initGetLogEntryCategoryDatasetsRoute(libs);
initGetLogEntryCategoryExamplesRoute(libs);
initGetLogEntryRateRoute(libs);
initSnapshotRoute(libs);
initNodeDetailsRoute(libs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ export class KibanaFramework {
method: 'indices.get' | 'ml.getBuckets',
options?: object
): Promise<InfraDatabaseGetIndicesResponse>;
callWithRequest(
requestContext: RequestHandlerContext,
method: 'ml.getJobs',
options?: object
): Promise<object>;
callWithRequest(
requestContext: RequestHandlerContext,
endpoint: string,
Expand Down
23 changes: 23 additions & 0 deletions x-pack/legacy/plugins/infra/server/lib/log_analysis/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,32 @@
* you may not use this file except in compliance with the Elastic License.
*/

/* eslint-disable max-classes-per-file */

export class NoLogAnalysisResultsIndexError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}

export class NoLogAnalysisMlJobError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}

export class InsufficientLogAnalysisMlJobConfigurationError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}

export class UnknownCategoryError extends Error {
constructor(categoryId: number) {
super(`Unknown ml category ${categoryId}`);
Object.setPrototypeOf(this, new.target.prototype);
}
}
Loading

0 comments on commit 2455a9f

Please sign in to comment.