1 | |
2 | type Render = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List queryable paths |
7 | * The path suggestions are based on the most recent 5000 log lines as filtered by the provided filters |
8 | */ |
9 | export async function main( |
10 | auth: Render, |
11 | startTime: string | undefined, |
12 | endTime: string | undefined, |
13 | resolutionSeconds: string | undefined, |
14 | resource: string | undefined, |
15 | service: string | undefined, |
16 | host: string | undefined, |
17 | statusCode: string | undefined, |
18 | path: string | undefined |
19 | ) { |
20 | const url = new URL(`https://api.render.com/v1/metrics/filters/path`) |
21 | for (const [k, v] of [ |
22 | ['startTime', startTime], |
23 | ['endTime', endTime], |
24 | ['resolutionSeconds', resolutionSeconds], |
25 | ['resource', resource], |
26 | ['service', service], |
27 | ['host', host], |
28 | ['statusCode', statusCode], |
29 | ['path', path] |
30 | ]) { |
31 | if (v !== undefined && v !== '' && k !== undefined) { |
32 | url.searchParams.append(k, v) |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: 'GET', |
37 | headers: { |
38 | Authorization: 'Bearer ' + auth.apiKey |
39 | }, |
40 | body: undefined |
41 | }) |
42 | if (!response.ok) { |
43 | const text = await response.text() |
44 | throw new Error(`${response.status} ${text}`) |
45 | } |
46 | return await response.json() |
47 | } |
48 |
|