mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Refactor trace-generators.js to TypeScript (#59431)
This commit is contained in:
parent
eaf96081d2
commit
d6bd3c4fb6
1
packages/jaeger-ui-components/src/demo/chance.d.ts
vendored
Normal file
1
packages/jaeger-ui-components/src/demo/chance.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare module 'chance';
|
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import Chance from 'chance';
|
import Chance from 'chance';
|
||||||
|
import { TraceSpanData, TraceProcess } from 'src/types/trace';
|
||||||
|
|
||||||
import { getSpanId } from '../selectors/span';
|
import { getSpanId } from '../selectors/span';
|
||||||
|
|
||||||
@ -30,12 +31,16 @@ export const OPERATIONS_LIST = [
|
|||||||
'MongoDB::update',
|
'MongoDB::update',
|
||||||
];
|
];
|
||||||
|
|
||||||
function setupParentSpan(spans, parentSpanValues) {
|
type Process = TraceProcess & {
|
||||||
|
processID: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function setupParentSpan(spans: TraceSpanData[], parentSpanValues: TraceSpanData) {
|
||||||
Object.assign(spans[0], parentSpanValues);
|
Object.assign(spans[0], parentSpanValues);
|
||||||
return spans;
|
return spans;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParentSpanId(span, levels) {
|
function getParentSpanId(span: TraceSpanData, levels: string[][]) {
|
||||||
let nestingLevel = chance.integer({ min: 1, max: levels.length });
|
let nestingLevel = chance.integer({ min: 1, max: levels.length });
|
||||||
|
|
||||||
// pick the correct nesting level if allocated by the levels calculation
|
// pick the correct nesting level if allocated by the levels calculation
|
||||||
@ -49,10 +54,10 @@ function getParentSpanId(span, levels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* this simulates the hierarchy created by CHILD_OF tags */
|
/* this simulates the hierarchy created by CHILD_OF tags */
|
||||||
function attachReferences(spans, depth, spansPerLevel) {
|
function attachReferences(spans: TraceSpanData[], depth: number, spansPerLevel: null) {
|
||||||
let levels = [[getSpanId(spans[0])]];
|
let levels: string[][] = [[getSpanId(spans[0])]];
|
||||||
|
|
||||||
const duplicateLevelFilter = (currentLevels) => (span) =>
|
const duplicateLevelFilter = (currentLevels: string[][]) => (span: TraceSpanData) =>
|
||||||
!currentLevels.find((level) => level.indexOf(span.spanID) >= 0);
|
!currentLevels.find((level) => level.indexOf(span.spanID) >= 0);
|
||||||
|
|
||||||
while (levels.length < depth) {
|
while (levels.length < depth) {
|
||||||
@ -60,6 +65,7 @@ function attachReferences(spans, depth, spansPerLevel) {
|
|||||||
if (remainingSpans.length <= 0) {
|
if (remainingSpans.length <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLevel = chance.pickset(remainingSpans, spansPerLevel || chance.integer({ min: 4, max: 8 })).map(getSpanId);
|
const newLevel = chance.pickset(remainingSpans, spansPerLevel || chance.integer({ min: 4, max: 8 })).map(getSpanId);
|
||||||
levels.push(newLevel);
|
levels.push(newLevel);
|
||||||
}
|
}
|
||||||
@ -99,10 +105,10 @@ export default chance.mixin({
|
|||||||
spansPerLevel = null,
|
spansPerLevel = null,
|
||||||
}) {
|
}) {
|
||||||
const traceID = chance.guid();
|
const traceID = chance.guid();
|
||||||
const duration = chance.integer({ min: 10000, max: 5000000 });
|
const duration: number = chance.integer({ min: 10000, max: 5000000 });
|
||||||
const timestamp = (new Date().getTime() - chance.integer({ min: 0, max: 1000 }) * 1000) * 1000;
|
const timestamp = (new Date().getTime() - chance.integer({ min: 0, max: 1000 }) * 1000) * 1000;
|
||||||
|
|
||||||
const processArray = chance.processes({ numberOfProcesses });
|
const processArray: Process[] = chance.processes({ numberOfProcesses });
|
||||||
const processes = processArray.reduce((pMap, p) => ({ ...pMap, [p.processID]: p }), {});
|
const processes = processArray.reduce((pMap, p) => ({ ...pMap, [p.processID]: p }), {});
|
||||||
|
|
||||||
let spans = chance.n(chance.span, numberOfSpans, {
|
let spans = chance.n(chance.span, numberOfSpans, {
|
||||||
@ -113,7 +119,8 @@ export default chance.mixin({
|
|||||||
});
|
});
|
||||||
spans = attachReferences(spans, maxDepth, spansPerLevel);
|
spans = attachReferences(spans, maxDepth, spansPerLevel);
|
||||||
if (spans.length > 1) {
|
if (spans.length > 1) {
|
||||||
spans = setupParentSpan(spans, { startTime: timestamp, duration });
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
spans = setupParentSpan(spans, { startTime: timestamp, duration } as TraceSpanData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -132,10 +139,14 @@ export default chance.mixin({
|
|||||||
span({
|
span({
|
||||||
traceID = chance.guid(),
|
traceID = chance.guid(),
|
||||||
processes = {},
|
processes = {},
|
||||||
traceStartTime = chance.timestamp() * 1000 * 1000,
|
traceStartTime = 0,
|
||||||
traceEndTime = traceStartTime + 100000,
|
traceEndTime = 0,
|
||||||
operations = OPERATIONS_LIST,
|
operations = OPERATIONS_LIST,
|
||||||
}) {
|
}) {
|
||||||
|
// Set default values for trace start/end time.
|
||||||
|
traceStartTime = traceStartTime || chance.timestamp() * 1000 * 1000;
|
||||||
|
traceEndTime = traceEndTime || traceStartTime + 100000;
|
||||||
|
|
||||||
const startTime = chance.integer({
|
const startTime = chance.integer({
|
||||||
min: traceStartTime,
|
min: traceStartTime,
|
||||||
max: traceEndTime,
|
max: traceEndTime,
|
Loading…
Reference in New Issue
Block a user