1 | |
2 | |
3 | * Fetch cluster metrics |
4 | * Fetch cluster metrics. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Qovery, |
8 | clusterId: string, |
9 | endpoint: string | undefined, |
10 | query: string | undefined, |
11 | start?: string | undefined, |
12 | end?: string | undefined, |
13 | step?: string | undefined, |
14 | time?: string | undefined, |
15 | timeout?: string | undefined, |
16 | dedup?: string | undefined, |
17 | partial_response?: string | undefined, |
18 | max_source_resolution?: string | undefined, |
19 | engine?: string | undefined, |
20 | analyze?: string | undefined, |
21 | board_short_name?: string | undefined, |
22 | metric_short_name?: string | undefined, |
23 | trace_id?: string | undefined, |
24 | range?: string | undefined |
25 | ) { |
26 | const url = new URL(`https://api.qovery.com/cluster/${clusterId}/metrics`) |
27 | for (const [k, v] of [ |
28 | ['endpoint', endpoint], |
29 | ['query', query], |
30 | ['start', start], |
31 | ['end', end], |
32 | ['step', step], |
33 | ['time', time], |
34 | ['timeout', timeout], |
35 | ['dedup', dedup], |
36 | ['partial_response', partial_response], |
37 | ['max_source_resolution', max_source_resolution], |
38 | ['engine', engine], |
39 | ['analyze', analyze], |
40 | ['board_short_name', board_short_name], |
41 | ['metric_short_name', metric_short_name], |
42 | ['trace_id', trace_id], |
43 | ['range', range] |
44 | ]) { |
45 | if (v !== undefined && v !== '') { |
46 | url.searchParams.append(k, v) |
47 | } |
48 | } |
49 | const response = await fetch(url, { |
50 | method: 'GET', |
51 | headers: { |
52 | Authorization: 'Token ' + auth.apiKey |
53 | }, |
54 | body: undefined |
55 | }) |
56 | if (!response.ok) { |
57 | const text = await response.text() |
58 | throw new Error(`${response.status} ${text}`) |
59 | } |
60 | return await response.json() |
61 | } |
62 |
|