chore(slo): require customkql timestamp field (#154654)

This commit is contained in:
Kevin Delemme 2023-04-11 08:31:53 -04:00 committed by GitHub
parent a727ba183a
commit 450e19598e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 21 deletions

View file

@ -50,17 +50,13 @@ const apmTransactionErrorRateIndicatorSchema = t.type({
const kqlCustomIndicatorTypeSchema = t.literal('sli.kql.custom');
const kqlCustomIndicatorSchema = t.type({
type: kqlCustomIndicatorTypeSchema,
params: t.intersection([
t.type({
index: t.string,
filter: t.string,
good: t.string,
total: t.string,
}),
t.partial({
timestampField: t.string,
}),
]),
params: t.type({
index: t.string,
filter: t.string,
good: t.string,
total: t.string,
timestampField: t.string,
}),
});
const indicatorDataSchema = t.type({

View file

@ -362,6 +362,7 @@ components:
nullable: false
required:
- index
- timestampField
properties:
index:
description: The index or index pattern to use

View file

@ -11,6 +11,7 @@ properties:
nullable: false
required:
- index
- timestampField
properties:
index:
description: The index or index pattern to use

View file

@ -51,6 +51,7 @@ export const buildCustomKqlIndicator = (
good: 'latency < 300',
total: 'latency > 0',
filter: 'labels.eventId: event-0',
timestampField: '@timestamp',
...params,
},
};

View file

@ -62,6 +62,7 @@ export const SLO_EDIT_FORM_DEFAULT_VALUES: CreateSLOInput = {
filter: '',
good: '',
total: '',
timestampField: '',
},
},
timeWindow: {

View file

@ -64,6 +64,7 @@ export const createKQLCustomIndicator = (
filter: 'labels.groupId: group-3',
good: 'latency < 300',
total: '',
timestampField: 'log_timestamp',
...params,
},
});

View file

@ -147,7 +147,7 @@ Object {
"group_by": Object {
"@timestamp": Object {
"date_histogram": Object {
"field": "@timestamp",
"field": "log_timestamp",
"fixed_interval": "2m",
},
},
@ -198,7 +198,7 @@ Object {
"sync": Object {
"time": Object {
"delay": "1m",
"field": "@timestamp",
"field": "log_timestamp",
},
},
"transform_id": Any<String>,
@ -243,7 +243,7 @@ Object {
"group_by": Object {
"@timestamp": Object {
"date_histogram": Object {
"field": "@timestamp",
"field": "log_timestamp",
"fixed_interval": "1m",
},
},
@ -294,7 +294,7 @@ Object {
"sync": Object {
"time": Object {
"delay": "1m",
"field": "@timestamp",
"field": "log_timestamp",
},
},
"transform_id": Any<String>,

View file

@ -29,9 +29,9 @@ export class KQLCustomTransformGenerator extends TransformGenerator {
this.buildDescription(slo),
this.buildSource(slo, slo.indicator),
this.buildDestination(),
this.buildGroupBy(slo, this.getTimestampFieldOrDefault(slo.indicator.params.timestampField)),
this.buildGroupBy(slo, slo.indicator.params.timestampField),
this.buildAggregations(slo, slo.indicator),
this.buildSettings(slo, this.getTimestampFieldOrDefault(slo.indicator.params.timestampField))
this.buildSettings(slo, slo.indicator.params.timestampField)
);
}
@ -79,8 +79,4 @@ export class KQLCustomTransformGenerator extends TransformGenerator {
}),
};
}
private getTimestampFieldOrDefault(timestampField: string | undefined): string {
return !!timestampField && timestampField.length > 0 ? timestampField : '@timestamp';
}
}