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

[ResponseOps] es query rule params not compatible between 8.6 and 8.7 #157710

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -144,6 +144,28 @@ describe('ruleType Params validate()', () => {
);
});

it('uses default value "count" if aggType is undefined', async () => {
params.aggType = undefined;
expect(onValidate()).not.toThrow();
});

it('fails for invalid groupBy', async () => {
params.groupBy = 42;
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
`"[groupBy]: expected value of type [string] but got [number]"`
);

params.groupBy = '-not-a-valid-groupBy-';
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
`"[groupBy]: invalid groupBy: \\"-not-a-valid-groupBy-\\""`
);
});

it('uses default value "all" if groupBy is undefined', async () => {
params.groupBy = undefined;
expect(onValidate()).not.toThrow();
});

it('fails for invalid aggField', async () => {
params.aggField = 42;
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const EsQueryRuleParamsSchemaProperties = {
threshold: schema.arrayOf(schema.number(), { minSize: 1, maxSize: 2 }),
thresholdComparator: getComparatorSchemaType(validateComparator),
// aggregation type
aggType: schema.string({ validate: validateAggType }),
aggType: schema.string({ validate: validateAggType, defaultValue: 'count' }),
// aggregation field
aggField: schema.maybe(schema.string({ minLength: 1 })),
// how to group
groupBy: schema.string({ validate: validateGroupBy }),
groupBy: schema.string({ validate: validateGroupBy, defaultValue: 'all' }),
// field to group on (for groupBy: top)
termField: schema.maybe(schema.string({ minLength: 1 })),
// limit on number of groups returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ export function runTests(schema: ObjectType, defaultTypeParams: Record<string, u
);
});

it('uses default value "count" if aggType is undefined', async () => {
params.aggType = undefined;
expect(onValidate()).not.toThrow();
});

it('fails for invalid groupBy', async () => {
params.groupBy = 42;
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
`"[groupBy]: expected value of type [string] but got [number]"`
);

params.groupBy = '-not-a-valid-groupBy-';
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
`"[groupBy]: invalid groupBy: \\"-not-a-valid-groupBy-\\""`
);
});

it('uses default value "all" if groupBy is undefined', async () => {
params.groupBy = undefined;
expect(onValidate()).not.toThrow();
});

it('fails for invalid aggField', async () => {
params.aggField = 42;
expect(onValidate()).toThrowErrorMatchingInlineSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const CoreQueryParamsSchemaProperties = {
// field in index used for date/time
timeField: schema.string({ minLength: 1 }),
// aggregation type
aggType: schema.string({ validate: validateAggType }),
aggType: schema.string({ validate: validateAggType, defaultValue: 'count' }),
// aggregation field
aggField: schema.maybe(schema.string({ minLength: 1 })),
// how to group
groupBy: schema.string({ validate: validateGroupBy }),
groupBy: schema.string({ validate: validateGroupBy, defaultValue: 'all' }),
// field to group on (for groupBy: top)
termField: schema.maybe(schema.string({ minLength: 1 })),
// filter field
Expand Down