-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs Overview] Overview component (iteration 1) (attempt 2) (#195673)
This is a re-submission of #191899, which was reverted due to a storybook build problem. This introduces a "Logs Overview" component for use in solution UIs behind a feature flag. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
44a42a7
commit 0caea22
Showing
76 changed files
with
3,415 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/kbn-apm-synthtrace-client/src/lib/gaussian_events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { castArray } from 'lodash'; | ||
import { SynthtraceGenerator } from '../types'; | ||
import { Fields } from './entity'; | ||
import { Serializable } from './serializable'; | ||
|
||
export class GaussianEvents<TFields extends Fields = Fields> { | ||
constructor( | ||
private readonly from: Date, | ||
private readonly to: Date, | ||
private readonly mean: Date, | ||
private readonly width: number, | ||
private readonly totalPoints: number | ||
) {} | ||
|
||
*generator<TGeneratedFields extends Fields = TFields>( | ||
map: ( | ||
timestamp: number, | ||
index: number | ||
) => Serializable<TGeneratedFields> | Array<Serializable<TGeneratedFields>> | ||
): SynthtraceGenerator<TGeneratedFields> { | ||
if (this.totalPoints <= 0) { | ||
return; | ||
} | ||
|
||
const startTime = this.from.getTime(); | ||
const endTime = this.to.getTime(); | ||
const meanTime = this.mean.getTime(); | ||
const densityInterval = 1 / (this.totalPoints - 1); | ||
|
||
for (let eventIndex = 0; eventIndex < this.totalPoints; eventIndex++) { | ||
const quantile = eventIndex * densityInterval; | ||
|
||
const standardScore = Math.sqrt(2) * inverseError(2 * quantile - 1); | ||
const timestamp = Math.round(meanTime + standardScore * this.width); | ||
|
||
if (timestamp >= startTime && timestamp <= endTime) { | ||
yield* this.generateEvents(timestamp, eventIndex, map); | ||
} | ||
} | ||
} | ||
|
||
private *generateEvents<TGeneratedFields extends Fields = TFields>( | ||
timestamp: number, | ||
eventIndex: number, | ||
map: ( | ||
timestamp: number, | ||
index: number | ||
) => Serializable<TGeneratedFields> | Array<Serializable<TGeneratedFields>> | ||
): Generator<Serializable<TGeneratedFields>> { | ||
const events = castArray(map(timestamp, eventIndex)); | ||
for (const event of events) { | ||
yield event; | ||
} | ||
} | ||
} | ||
|
||
function inverseError(x: number): number { | ||
const a = 0.147; | ||
const sign = x < 0 ? -1 : 1; | ||
|
||
const part1 = 2 / (Math.PI * a) + Math.log(1 - x * x) / 2; | ||
const part2 = Math.log(1 - x * x) / a; | ||
|
||
return sign * Math.sqrt(Math.sqrt(part1 * part1 - part2) - part1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/kbn-apm-synthtrace-client/src/lib/poisson_events.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { PoissonEvents } from './poisson_events'; | ||
import { Serializable } from './serializable'; | ||
|
||
describe('poisson events', () => { | ||
it('generates events within the given time range', () => { | ||
const poissonEvents = new PoissonEvents(new Date(1000), new Date(2000), 10); | ||
|
||
const events = Array.from( | ||
poissonEvents.generator((timestamp) => new Serializable({ '@timestamp': timestamp })) | ||
); | ||
|
||
expect(events.length).toBeGreaterThanOrEqual(1); | ||
|
||
for (const event of events) { | ||
expect(event.fields['@timestamp']).toBeGreaterThanOrEqual(1000); | ||
expect(event.fields['@timestamp']).toBeLessThanOrEqual(2000); | ||
} | ||
}); | ||
|
||
it('generates at least one event if the rate is greater than 0', () => { | ||
const poissonEvents = new PoissonEvents(new Date(1000), new Date(2000), 1); | ||
|
||
const events = Array.from( | ||
poissonEvents.generator((timestamp) => new Serializable({ '@timestamp': timestamp })) | ||
); | ||
|
||
expect(events.length).toBeGreaterThanOrEqual(1); | ||
|
||
for (const event of events) { | ||
expect(event.fields['@timestamp']).toBeGreaterThanOrEqual(1000); | ||
expect(event.fields['@timestamp']).toBeLessThanOrEqual(2000); | ||
} | ||
}); | ||
|
||
it('generates no event if the rate is 0', () => { | ||
const poissonEvents = new PoissonEvents(new Date(1000), new Date(2000), 0); | ||
|
||
const events = Array.from( | ||
poissonEvents.generator((timestamp) => new Serializable({ '@timestamp': timestamp })) | ||
); | ||
|
||
expect(events.length).toBe(0); | ||
}); | ||
}); |
Oops, something went wrong.