Skip to content

Commit

Permalink
moving runtime mapping schema to package
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jul 28, 2023
1 parent d02a6cc commit 40fb370
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 28 deletions.
1 change: 1 addition & 0 deletions x-pack/packages/ml/runtime_field_utils/index.ts
Expand Up @@ -8,3 +8,4 @@
export { getCombinedRuntimeMappings } from './src/get_combined_runtime_mappings';
export { isRuntimeField } from './src/is_runtime_field';
export { isRuntimeMappings, type RuntimeMappings } from './src/is_runtime_mappings';
export { runtimeMappingsSchema } from './src/schema';
Expand Up @@ -8,7 +8,6 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { RUNTIME_FIELD_TYPES } from '@kbn/data-plugin/common';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';

type RuntimeType = typeof RUNTIME_FIELD_TYPES[number];

/**
Expand Down
Expand Up @@ -7,15 +7,19 @@

import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { isRuntimeField } from '@kbn/ml-runtime-field-utils';
import { isRuntimeField } from './is_runtime_field';

/**
* Schema for validating a runtime field
*/

export const runtimeMappingsSchema = schema.object(
{},
{
unknowns: 'allow',
validate: (v: object) => {
if (Object.values(v).some((o) => !isRuntimeField(o))) {
return i18n.translate('xpack.ml.invalidRuntimeFieldMessage', {
return i18n.translate('xpack.aiops.invalidRuntimeFieldMessage', {
defaultMessage: 'Invalid runtime field',
});
}
Expand Down
17 changes: 1 addition & 16 deletions x-pack/plugins/aiops/common/api/log_categorization/schema.ts
Expand Up @@ -6,22 +6,7 @@
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { isRuntimeField } from '@kbn/ml-runtime-field-utils';

export const runtimeMappingsSchema = schema.object(
{},
{
unknowns: 'allow',
validate: (v: object) => {
if (Object.values(v).some((o) => !isRuntimeField(o))) {
return i18n.translate('xpack.aiops.invalidRuntimeFieldMessage', {
defaultMessage: 'Invalid runtime field',
});
}
},
}
);
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';

export const indicesOptionsSchema = schema.object({
expand_wildcards: schema.maybe(
Expand Down
Expand Up @@ -148,7 +148,7 @@ function createCategoryRequest(
wrap: ReturnType<typeof createRandomSamplerWrapper>['wrap'],
intervalMs?: number
) {
const query = processQuery(queryIn, timeField, from, to);
const query = createCategorizeQuery(queryIn, timeField, from, to);
const aggs = {
categories: {
categorize_text: {
Expand Down Expand Up @@ -189,7 +189,7 @@ function createCategoryRequest(
};
}

export function processQuery(
export function createCategorizeQuery(
queryIn: QueryDslQueryContainer,
timeField: string,
from: number | undefined,
Expand Down
Expand Up @@ -11,7 +11,7 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/type
import type { FieldValidationResults } from '@kbn/ml-category-validator';
import { AIOPS_API_ENDPOINT } from '../../../common/api';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import { processQuery } from './use_categorize_request';
import { createCategorizeQuery } from './use_categorize_request';

export function useValidateFieldRequest() {
const { http } = useAiopsAppContext();
Expand All @@ -26,7 +26,7 @@ export function useValidateFieldRequest() {
end: number | undefined,
queryIn: QueryDslQueryContainer
) => {
const query = processQuery(queryIn, timeField, start, end);
const query = createCategorizeQuery(queryIn, timeField, start, end);
const resp = await http.post<FieldValidationResults>(
AIOPS_API_ENDPOINT.CATEGORIZATION_FIELD_VALIDATION,
{
Expand Down
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { runtimeMappingsSchema } from './runtime_mappings_schema';
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';

export const dataAnalyticsJobConfigSchema = schema.object({
description: schema.maybe(schema.string()),
Expand Down
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { runtimeMappingsSchema } from './runtime_mappings_schema';
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';

export const indexPatternSchema = schema.object({
/** Pattern of index or indices for which to return stats. */
Expand Down
Expand Up @@ -6,8 +6,8 @@
*/

import { schema } from '@kbn/config-schema';
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';
import { indicesOptionsSchema } from './datafeeds_schema';
import { runtimeMappingsSchema } from './runtime_mappings_schema';

export const getCardinalityOfFieldsSchema = schema.object({
/** Index or indexes for which to return the time range. */
Expand Down
Expand Up @@ -6,9 +6,9 @@
*/

import { schema } from '@kbn/config-schema';
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';
import { anomalyDetectionJobSchema } from './anomaly_detectors_schema';
import { datafeedConfigSchema, indicesOptionsSchema } from './datafeeds_schema';
import { runtimeMappingsSchema } from './runtime_mappings_schema';

export const categorizationFieldValidationSchema = {
indexPatternTitle: schema.string(),
Expand Down
Expand Up @@ -7,9 +7,9 @@

import { schema } from '@kbn/config-schema';
import { ES_AGGREGATION } from '@kbn/ml-anomaly-utils';
import { runtimeMappingsSchema } from '@kbn/ml-runtime-field-utils';
import { analysisConfigSchema, anomalyDetectionJobSchema } from './anomaly_detectors_schema';
import { datafeedConfigSchema, indicesOptionsSchema } from './datafeeds_schema';
import { runtimeMappingsSchema } from './runtime_mappings_schema';

export const estimateBucketSpanSchema = schema.object({
aggTypes: schema.arrayOf(
Expand Down

0 comments on commit 40fb370

Please sign in to comment.