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.14] [Obs AI assistant] Relax validation on missing fallbacks (#181324) #181343

Merged
merged 1 commit into from
Apr 22, 2024
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 @@ -33,42 +33,14 @@ describe('correctQueryWithActions', () => {
expect(fixedQuery).toBe('from logstash-* | stats var0 = max(bytes) | eval abs(var0) | limit 1');
});

it(`fixes errors correctly for a query with missing quotes`, async () => {
const fixedQuery = await correctQueryWithActions('from logstash-* | keep field-1');
expect(fixedQuery).toBe('from logstash-* | keep `field-1`');
});

it(`fixes errors correctly for a query with missing quotes in multiple commands`, async () => {
const fixedQuery = await correctQueryWithActions(
'from logstash-* | stats avg(field-1) | eval abs(field-2)'
);
expect(fixedQuery).toBe('from logstash-* | stats avg(`field-1`) | eval abs(`field-2`)');
});

it(`fixes errors correctly for a query with missing quotes and keep with multiple fields`, async () => {
const fixedQuery = await correctQueryWithActions('from logstash-* | keep field-1, field-2');
expect(fixedQuery).toBe('from logstash-* | keep `field-1`, `field-2`');
});

it(`fixes errors correctly for a query with missing quotes with variable assignment`, async () => {
const fixedQuery = await correctQueryWithActions('from logstash-* | stats var1 = avg(field-1)');
expect(fixedQuery).toBe('from logstash-* | stats var1 = avg(`field-1`)');
});

it(`fixes errors correctly for a query with missing quotes in an aggregation`, async () => {
const fixedQuery = await correctQueryWithActions('from logstash-* | stats avg(field-1)');
expect(fixedQuery).toBe('from logstash-* | stats avg(`field-1`)');
});

it(`fixes errors correctly for a query with typo on stats and wrong quotes`, async () => {
const fixedQuery = await correctQueryWithActions('from logstash-* | stats aveg(field-1)');
expect(fixedQuery).toBe('from logstash-* | stats avg(`field-1`)');
});

it(`fixes errors correctly for a query with missing quotes on stats and keep`, async () => {
const fixedQuery = await correctQueryWithActions(
'from logstash-* | stats avg(field-1) | keep field-2'
);
expect(fixedQuery).toBe('from logstash-* | stats avg(`field-1`) | keep `field-2`');
it(`doesnt complain for @timestamp column`, async () => {
const queryWithTimestamp = `FROM logstash-*
| WHERE @timestamp >= NOW() - 15 minutes
| EVAL bucket = DATE_TRUNC(1 minute, @timestamp)
| STATS avg_cpu = AVG(system.cpu.total.norm.pct) BY service.name, bucket
| SORT avg_cpu DESC
| LIMIT 10`;
const fixedQuery = await correctQueryWithActions(queryWithTimestamp);
expect(fixedQuery).toBe(queryWithTimestamp);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { validateQuery, getActions } from '@kbn/esql-validation-autocomplete';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';

const fixedQueryByOneAction = async (queryString: string) => {
const { errors } = await validateQuery(queryString, getAstAndSyntaxErrors);
const { errors } = await validateQuery(queryString, getAstAndSyntaxErrors, {
ignoreOnMissingCallbacks: true,
});

const actions = await getActions(queryString, errors, getAstAndSyntaxErrors, {
relaxOnMissingCallbacks: true,
Expand Down
Loading