Skip to content

Commit

Permalink
[Obs AI assistant] Relax validation on missing fallbacks (#181324)
Browse files Browse the repository at this point in the history
## Summary

Relaxes the validation which means that we can't quick fix the quotes
problem but we are still fixing other syntax errors such as functions
misspell etc.
  • Loading branch information
stratoula authored Apr 22, 2024
1 parent ebeea05 commit 0643f63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
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

0 comments on commit 0643f63

Please sign in to comment.