Skip to content

Commit 6d373a9

Browse files
Merge branch 'main' into multi-metric-partition-charts
2 parents b240615 + b1bb591 commit 6d373a9

70 files changed

Lines changed: 1702 additions & 287 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/plugins/unified_field_list/common/utils/field_stats_utils.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ export async function getNumberHistogram(
193193
? minMaxResult.aggregations!.sample.top_values
194194
: {
195195
buckets: [] as Array<{ doc_count: number; key: string | number }>,
196+
sum_other_doc_count: 0,
196197
};
197198

198-
const topValuesBuckets = {
199+
const topValues = {
199200
buckets: terms.buckets.map((bucket) => ({
200201
count: bucket.doc_count,
201202
key: bucket.key,
@@ -211,9 +212,11 @@ export async function getNumberHistogram(
211212
if (histogramInterval === 0) {
212213
return {
213214
totalDocuments: getHitsTotal(minMaxResult),
214-
sampledValues: minMaxResult.aggregations!.sample.sample_count.value!,
215+
sampledValues:
216+
sumSampledValues(topValues, terms.sum_other_doc_count) ||
217+
minMaxResult.aggregations!.sample.sample_count.value!,
215218
sampledDocuments: minMaxResult.aggregations!.sample.doc_count,
216-
topValues: topValuesBuckets,
219+
topValues,
217220
histogram: useTopHits
218221
? { buckets: [] }
219222
: {
@@ -244,14 +247,16 @@ export async function getNumberHistogram(
244247
return {
245248
totalDocuments: getHitsTotal(minMaxResult),
246249
sampledDocuments: minMaxResult.aggregations!.sample.doc_count,
247-
sampledValues: minMaxResult.aggregations!.sample.sample_count.value!,
250+
sampledValues:
251+
sumSampledValues(topValues, terms.sum_other_doc_count) ||
252+
minMaxResult.aggregations!.sample.sample_count.value!,
248253
histogram: {
249254
buckets: histogramResult.aggregations!.sample.histo.buckets.map((bucket) => ({
250255
count: bucket.doc_count,
251256
key: bucket.key,
252257
})),
253258
},
254-
topValues: topValuesBuckets,
259+
topValues,
255260
};
256261
}
257262

@@ -284,16 +289,22 @@ export async function getStringSamples(
284289
{ body: { aggs: typeof topValuesBody } }
285290
>;
286291

292+
const topValues = {
293+
buckets: topValuesResult.aggregations!.sample.top_values.buckets.map((bucket) => ({
294+
count: bucket.doc_count,
295+
key: bucket.key,
296+
})),
297+
};
298+
287299
return {
288300
totalDocuments: getHitsTotal(topValuesResult),
289301
sampledDocuments: topValuesResult.aggregations!.sample.doc_count,
290-
sampledValues: topValuesResult.aggregations!.sample.sample_count.value!,
291-
topValues: {
292-
buckets: topValuesResult.aggregations!.sample.top_values.buckets.map((bucket) => ({
293-
count: bucket.doc_count,
294-
key: bucket.key,
295-
})),
296-
},
302+
sampledValues:
303+
sumSampledValues(
304+
topValues,
305+
topValuesResult.aggregations!.sample.top_values.sum_other_doc_count
306+
) || topValuesResult.aggregations!.sample.sample_count.value!,
307+
topValues,
297308
};
298309
}
299310

@@ -392,3 +403,14 @@ function getFieldRef(field: DataViewField) {
392403
const getHitsTotal = (body: estypes.SearchResponse): number => {
393404
return (body.hits.total as estypes.SearchTotalHits).value ?? body.hits.total ?? 0;
394405
};
406+
407+
// We could use `aggregations.sample.sample_count.value` instead, but it does not always give a correct sum
408+
// See Github issue #144625
409+
export function sumSampledValues(
410+
topValues: FieldStatsResponse<string | number>['topValues'],
411+
sumOtherDocCount: number
412+
): number {
413+
const valuesInTopBuckets =
414+
topValues?.buckets?.reduce((prev, bucket) => bucket.count + prev, 0) || 0;
415+
return valuesInTopBuckets + (sumOtherDocCount || 0);
416+
}

x-pack/plugins/fleet/server/types/rest_spec/epm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const GetInfoRequestSchemaDeprecated = {
5757
query: schema.object({
5858
ignoreUnverified: schema.maybe(schema.boolean()),
5959
prerelease: schema.maybe(schema.boolean()),
60+
full: schema.maybe(schema.boolean()),
6061
}),
6162
};
6263

x-pack/plugins/observability/dev_docs/slo.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ curl --request POST \
5757
"name": "My SLO Name",
5858
"description": "My SLO Description",
5959
"indicator": {
60-
"type": "slo.apm.transaction_error_rate",
60+
"type": "sli.apm.transaction_error_rate",
6161
"params": {
6262
"environment": "production",
6363
"service": "o11y-app",
@@ -91,7 +91,7 @@ curl --request POST \
9191
"name": "My SLO Name",
9292
"description": "My SLO Description",
9393
"indicator": {
94-
"type": "slo.apm.transaction_error_rate",
94+
"type": "sli.apm.transaction_error_rate",
9595
"params": {
9696
"environment": "production",
9797
"service": "o11y-app",
@@ -127,7 +127,7 @@ curl --request POST \
127127
"name": "My SLO Name",
128128
"description": "My SLO Description",
129129
"indicator": {
130-
"type": "slo.apm.transaction_error_rate",
130+
"type": "sli.apm.transaction_error_rate",
131131
"params": {
132132
"environment": "production",
133133
"service": "o11y-app",
@@ -165,7 +165,7 @@ curl --request POST \
165165
"name": "My SLO Name",
166166
"description": "My SLO Description",
167167
"indicator": {
168-
"type": "slo.apm.transaction_duration",
168+
"type": "sli.apm.transaction_duration",
169169
"params": {
170170
"environment": "production",
171171
"service": "o11y-app",
@@ -199,7 +199,7 @@ curl --request POST \
199199
"name": "My SLO Name",
200200
"description": "My SLO Description",
201201
"indicator": {
202-
"type": "slo.apm.transaction_duration",
202+
"type": "sli.apm.transaction_duration",
203203
"params": {
204204
"environment": "production",
205205
"service": "o11y-app",
@@ -236,7 +236,7 @@ curl --request POST \
236236
"name": "My SLO Name",
237237
"description": "My SLO Description",
238238
"indicator": {
239-
"type": "slo.apm.transaction_duration",
239+
"type": "sli.apm.transaction_duration",
240240
"params": {
241241
"environment": "production",
242242
"service": "o11y-app",
@@ -278,7 +278,7 @@ curl --request POST \
278278
"name": "My SLO Name",
279279
"description": "My SLO Description",
280280
"indicator": {
281-
"type": "slo.kql.custom",
281+
"type": "sli.kql.custom",
282282
"params": {
283283
"index": "high-cardinality-data-fake_logs*",
284284
"numerator": "latency < 300",

x-pack/plugins/observability/server/types/models/common.ts renamed to x-pack/plugins/observability/server/domain/models/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77
import * as t from 'io-ts';
8-
import { dateRangeSchema } from '../schema';
8+
import { dateRangeSchema } from '../../types/schema';
99

1010
type DateRange = t.TypeOf<typeof dateRangeSchema>;
1111

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { Duration, DurationUnit } from './duration';
9+
10+
describe('Duration', () => {
11+
it('throws when value is negative', () => {
12+
expect(() => new Duration(-1, DurationUnit.Day)).toThrow('invalid duration value');
13+
});
14+
15+
it('throws when value is zero', () => {
16+
expect(() => new Duration(0, DurationUnit.Day)).toThrow('invalid duration value');
17+
});
18+
19+
it('throws when unit is not valid', () => {
20+
expect(() => new Duration(1, 'z' as DurationUnit)).toThrow('invalid duration unit');
21+
});
22+
23+
describe('format', () => {
24+
it('formats the duration correctly', () => {
25+
expect(new Duration(1, DurationUnit.Minute).format()).toBe('1m');
26+
expect(new Duration(1, DurationUnit.Hour).format()).toBe('1h');
27+
expect(new Duration(1, DurationUnit.Day).format()).toBe('1d');
28+
expect(new Duration(1, DurationUnit.Week).format()).toBe('1w');
29+
expect(new Duration(1, DurationUnit.Month).format()).toBe('1M');
30+
expect(new Duration(1, DurationUnit.Quarter).format()).toBe('1Q');
31+
expect(new Duration(1, DurationUnit.Year).format()).toBe('1Y');
32+
});
33+
});
34+
35+
describe('isShorterThan', () => {
36+
it('returns true when the current duration is shorter than the other duration', () => {
37+
const short = new Duration(1, DurationUnit.Minute);
38+
expect(short.isShorterThan(new Duration(1, DurationUnit.Hour))).toBe(true);
39+
expect(short.isShorterThan(new Duration(1, DurationUnit.Day))).toBe(true);
40+
expect(short.isShorterThan(new Duration(1, DurationUnit.Week))).toBe(true);
41+
expect(short.isShorterThan(new Duration(1, DurationUnit.Month))).toBe(true);
42+
expect(short.isShorterThan(new Duration(1, DurationUnit.Quarter))).toBe(true);
43+
expect(short.isShorterThan(new Duration(1, DurationUnit.Year))).toBe(true);
44+
});
45+
46+
it('returns false when the current duration is longer (or equal) than the other duration', () => {
47+
const long = new Duration(1, DurationUnit.Year);
48+
expect(long.isShorterThan(new Duration(1, DurationUnit.Minute))).toBe(false);
49+
expect(long.isShorterThan(new Duration(1, DurationUnit.Hour))).toBe(false);
50+
expect(long.isShorterThan(new Duration(1, DurationUnit.Day))).toBe(false);
51+
expect(long.isShorterThan(new Duration(1, DurationUnit.Week))).toBe(false);
52+
expect(long.isShorterThan(new Duration(1, DurationUnit.Month))).toBe(false);
53+
expect(long.isShorterThan(new Duration(1, DurationUnit.Quarter))).toBe(false);
54+
expect(long.isShorterThan(new Duration(1, DurationUnit.Year))).toBe(false);
55+
});
56+
});
57+
});

x-pack/plugins/observability/server/types/models/duration.ts renamed to x-pack/plugins/observability/server/domain/models/duration.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { assertNever } from '@kbn/std';
99
import * as moment from 'moment';
1010

1111
enum DurationUnit {
12-
'm' = 'm',
13-
'h' = 'h',
14-
'd' = 'd',
15-
'w' = 'w',
16-
'M' = 'M',
17-
'Q' = 'Q',
18-
'Y' = 'Y',
12+
'Minute' = 'm',
13+
'Hour' = 'h',
14+
'Day' = 'd',
15+
'Week' = 'w',
16+
'Month' = 'M',
17+
'Quarter' = 'Q',
18+
'Year' = 'Y',
1919
}
2020

2121
class Duration {
@@ -41,19 +41,19 @@ class Duration {
4141

4242
const toMomentUnitOfTime = (unit: DurationUnit): moment.unitOfTime.Diff => {
4343
switch (unit) {
44-
case DurationUnit.m:
44+
case DurationUnit.Minute:
4545
return 'minutes';
46-
case DurationUnit.h:
46+
case DurationUnit.Hour:
4747
return 'hours';
48-
case DurationUnit.d:
48+
case DurationUnit.Day:
4949
return 'days';
50-
case DurationUnit.w:
50+
case DurationUnit.Week:
5151
return 'weeks';
52-
case DurationUnit.M:
52+
case DurationUnit.Month:
5353
return 'months';
54-
case DurationUnit.Q:
54+
case DurationUnit.Quarter:
5555
return 'quarters';
56-
case DurationUnit.Y:
56+
case DurationUnit.Year:
5757
return 'years';
5858
default:
5959
assertNever(unit);

x-pack/plugins/observability/server/types/models/error_budget.ts renamed to x-pack/plugins/observability/server/domain/models/error_budget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as t from 'io-ts';
9-
import { errorBudgetSchema } from '../schema';
9+
import { errorBudgetSchema } from '../../types/schema';
1010

1111
type ErrorBudget = t.TypeOf<typeof errorBudgetSchema>;
1212

x-pack/plugins/observability/server/types/models/index.ts renamed to x-pack/plugins/observability/server/domain/models/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* 2.0.
66
*/
77

8-
export * from './slo';
9-
export * from './indicators';
10-
export * from './error_budget';
11-
export * from './duration';
128
export * from './common';
9+
export * from './duration';
10+
export * from './error_budget';
11+
export * from './indicators';
12+
export * from './slo';
13+
export * from './time_window';

x-pack/plugins/observability/server/types/models/indicators.ts renamed to x-pack/plugins/observability/server/domain/models/indicators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
indicatorSchema,
1414
indicatorTypesSchema,
1515
kqlCustomIndicatorSchema,
16-
} from '../schema';
16+
} from '../../types/schema';
1717

1818
type APMTransactionErrorRateIndicator = t.TypeOf<typeof apmTransactionErrorRateIndicatorSchema>;
1919
type APMTransactionDurationIndicator = t.TypeOf<typeof apmTransactionDurationIndicatorSchema>;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import * as t from 'io-ts';
9+
import { sloSchema } from '../../types/schema';
10+
11+
type SLO = t.TypeOf<typeof sloSchema>;
12+
type StoredSLO = t.OutputOf<typeof sloSchema>;
13+
14+
export type { SLO, StoredSLO };

0 commit comments

Comments
 (0)