-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.ts
92 lines (81 loc) · 3.02 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
export const PLUGIN_ID = 'profiling';
export const PLUGIN_NAME = 'profiling';
const BASE_ROUTE_PATH = '/api/prodfiler';
const BASE_LOCAL_ROUTE_PATH = `${BASE_ROUTE_PATH}/v1`;
const BASE_REMOTE_ROUTE_PATH = `${BASE_ROUTE_PATH}/v2`;
export function getLocalRoutePaths() {
return {
TopN: `${BASE_LOCAL_ROUTE_PATH}/topn`,
TopNContainers: `${BASE_LOCAL_ROUTE_PATH}/topn/containers`,
TopNDeployments: `${BASE_LOCAL_ROUTE_PATH}/topn/deployments`,
TopNHosts: `${BASE_LOCAL_ROUTE_PATH}/topn/hosts`,
TopNThreads: `${BASE_LOCAL_ROUTE_PATH}/topn/threads`,
TopNTraces: `${BASE_LOCAL_ROUTE_PATH}/topn/traces`,
FlamechartElastic: `${BASE_LOCAL_ROUTE_PATH}/flamechart/elastic`,
FlamechartPixi: `${BASE_LOCAL_ROUTE_PATH}/flamechart/pixi`,
};
}
export function getRemoteRoutePaths() {
return {
TopN: `${BASE_REMOTE_ROUTE_PATH}/topn`,
TopNContainers: `${BASE_REMOTE_ROUTE_PATH}/topn/containers`,
TopNDeployments: `${BASE_REMOTE_ROUTE_PATH}/topn/deployments`,
TopNHosts: `${BASE_REMOTE_ROUTE_PATH}/topn/hosts`,
TopNThreads: `${BASE_REMOTE_ROUTE_PATH}/topn/threads`,
TopNTraces: `${BASE_REMOTE_ROUTE_PATH}/topn/traces`,
FlamechartElastic: `${BASE_REMOTE_ROUTE_PATH}/flamechart/elastic`,
FlamechartPixi: `${BASE_REMOTE_ROUTE_PATH}/flamechart/pixi`,
};
}
function toMilliseconds(seconds: string): number {
return parseInt(seconds, 10) * 1000;
}
export function getTopN(obj) {
const data = [];
if (obj.topN?.histogram?.buckets!) {
// needed for data served from Elasticsearch
for (let i = 0; i < obj.topN.histogram.buckets.length; i++) {
const bucket = obj.topN.histogram.buckets[i];
for (let j = 0; j < bucket.group_by.buckets.length; j++) {
const v = bucket.group_by.buckets[j];
data.push({ x: bucket.key, y: v.Count.value, g: v.key });
}
}
} else if (obj.TopN!) {
// needed for data served from fixtures
for (const x in obj.TopN) {
if (obj.TopN.hasOwnProperty(x)) {
const values = obj.TopN[x];
for (let i = 0; i < values.length; i++) {
const v = values[i];
data.push({ x: toMilliseconds(x), y: v.Count, g: v.Value });
}
}
}
}
return data;
}
export function groupSamplesByCategory(samples) {
const series = new Map();
for (let i = 0; i < samples.length; i++) {
const v = samples[i];
if (!series.has(v.g)) {
series.set(v.g, []);
}
const value = series.get(v.g);
value.push([v.x, v.y]);
}
return series;
}
export function timeRangeFromRequest(request: any): [number, number] {
const timeFrom = parseInt(request.query.timeFrom!, 10);
const timeTo = parseInt(request.query.timeTo!, 10);
return [timeFrom, timeTo];
}