1 | |
2 | type Signoz = { |
3 | apiKey: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Update an existing dashboard |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Signoz, |
12 | id: string, |
13 | body: {} & { |
14 | title: string; |
15 | description?: string; |
16 | tags?: string[]; |
17 | layout: { |
18 | x?: number; |
19 | y?: number; |
20 | w?: number; |
21 | h?: number; |
22 | i?: string; |
23 | moved?: false | true; |
24 | static?: false | true; |
25 | }[]; |
26 | variables?: { |
27 | key?: { |
28 | id?: string; |
29 | name?: string; |
30 | description?: string; |
31 | key?: string; |
32 | type?: "QUERY" | "CONSTANT"; |
33 | queryValue?: string; |
34 | allSelected?: false | true; |
35 | customValue?: string; |
36 | multiSelect?: false | true; |
37 | order?: number; |
38 | showALLOption?: false | true; |
39 | sort?: "ASC" | "DESC"; |
40 | textboxValue?: string; |
41 | }; |
42 | }; |
43 | widgets: { |
44 | id: string; |
45 | description?: string; |
46 | isStacked?: false | true; |
47 | nullZeroValues?: false | true; |
48 | opacity?: number; |
49 | panelTypes: "graph" | "table" | "value" | "list" | "trace"; |
50 | timePreferance?: "GLOBAL_TIME"; |
51 | title: string; |
52 | yAxisUnit?: string; |
53 | query: { |
54 | queryType: "builder" | "clickhouse_sql" | "promql"; |
55 | promql?: { |
56 | disabled: false | true; |
57 | name: string; |
58 | query: string; |
59 | legend?: string; |
60 | }[]; |
61 | clickhouse_sql?: { |
62 | disabled: false | true; |
63 | name: string; |
64 | query: string; |
65 | legend?: string; |
66 | }[]; |
67 | builder?: { |
68 | queryData?: { |
69 | queryName: string; |
70 | stepInterval: number; |
71 | dataSource: "metrics" | "traces" | "logs"; |
72 | aggregateOperator?: |
73 | | "noop" |
74 | | "count" |
75 | | "count_distinct" |
76 | | "sum" |
77 | | "avg" |
78 | | "min" |
79 | | "max" |
80 | | "p05" |
81 | | "p10" |
82 | | "p20" |
83 | | "p25" |
84 | | "p50" |
85 | | "p75" |
86 | | "p90" |
87 | | "p95" |
88 | | "p99" |
89 | | "rate" |
90 | | "rate_sum" |
91 | | "rate_avg" |
92 | | "rate_min" |
93 | | "rate_max"; |
94 | aggregateAttribute?: { |
95 | key: string; |
96 | dataType?: |
97 | | "string" |
98 | | "int64" |
99 | | "float64" |
100 | | "bool" |
101 | | "array(string)" |
102 | | "array(int64)" |
103 | | "array(float64)" |
104 | | "array(bool)"; |
105 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
106 | isColumn?: false | true; |
107 | isJSON?: false | true; |
108 | }; |
109 | temporality?: "Unspecified" | "Delta" | "Cumulative"; |
110 | filters?: { |
111 | op?: "AND" | "OR"; |
112 | items?: { |
113 | key: { |
114 | key: string; |
115 | dataType?: |
116 | | "string" |
117 | | "int64" |
118 | | "float64" |
119 | | "bool" |
120 | | "array(string)" |
121 | | "array(int64)" |
122 | | "array(float64)" |
123 | | "array(bool)"; |
124 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
125 | isColumn?: false | true; |
126 | isJSON?: false | true; |
127 | }; |
128 | value?: {}; |
129 | op: |
130 | | "=" |
131 | | "!=" |
132 | | ">" |
133 | | ">=" |
134 | | "<" |
135 | | "<=" |
136 | | "in" |
137 | | "nin" |
138 | | "like" |
139 | | "nlike" |
140 | | "contains" |
141 | | "ncontains" |
142 | | "regex" |
143 | | "nregex" |
144 | | "exists" |
145 | | "nexists" |
146 | | "has" |
147 | | "nhas"; |
148 | }[]; |
149 | }; |
150 | groupBy?: { |
151 | key: string; |
152 | dataType?: |
153 | | "string" |
154 | | "int64" |
155 | | "float64" |
156 | | "bool" |
157 | | "array(string)" |
158 | | "array(int64)" |
159 | | "array(float64)" |
160 | | "array(bool)"; |
161 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
162 | isColumn?: false | true; |
163 | isJSON?: false | true; |
164 | }[]; |
165 | expression: string; |
166 | disabled?: false | true; |
167 | having?: { |
168 | columnName: string; |
169 | op: "=" | "!=" | ">" | ">=" | "<" | "<=" | "IN" | "NOT_IN"; |
170 | value: {}; |
171 | }[]; |
172 | legend?: string; |
173 | limit?: number; |
174 | offset?: number; |
175 | pageSize?: number; |
176 | orderBy?: { columnName: string; order: "asc" | "desc" }[]; |
177 | reduceTo?: "sum" | "avg" | "min" | "max" | "last"; |
178 | selectColumns?: { |
179 | key: string; |
180 | dataType?: |
181 | | "string" |
182 | | "int64" |
183 | | "float64" |
184 | | "bool" |
185 | | "array(string)" |
186 | | "array(int64)" |
187 | | "array(float64)" |
188 | | "array(bool)"; |
189 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
190 | isColumn?: false | true; |
191 | isJSON?: false | true; |
192 | }[]; |
193 | timeAggregation?: |
194 | | "count" |
195 | | "count_distinct" |
196 | | "sum" |
197 | | "avg" |
198 | | "min" |
199 | | "max" |
200 | | "rate" |
201 | | "latest" |
202 | | "increase"; |
203 | spaceAggregation?: |
204 | | "count" |
205 | | "sum" |
206 | | "avg" |
207 | | "min" |
208 | | "max" |
209 | | "p50" |
210 | | "p75" |
211 | | "p90" |
212 | | "p95" |
213 | | "p99"; |
214 | seriesAggregation?: "sum" | "avg" | "min" | "max"; |
215 | functions?: { |
216 | name: |
217 | | "cutOffMin" |
218 | | "cutOffMax" |
219 | | "clampMin" |
220 | | "clampMax" |
221 | | "absolute" |
222 | | "runningDiff" |
223 | | "log2" |
224 | | "log10" |
225 | | "cumSum" |
226 | | "ewma3" |
227 | | "ewma5" |
228 | | "ewma7" |
229 | | "median3" |
230 | | "median5" |
231 | | "median7" |
232 | | "timeShift" |
233 | | "anomaly"; |
234 | args?: {}[]; |
235 | namedArgs?: {}; |
236 | }[]; |
237 | }; |
238 | queryFormulas?: { |
239 | queryName: string; |
240 | stepInterval: number; |
241 | dataSource: "metrics" | "traces" | "logs"; |
242 | aggregateOperator?: |
243 | | "noop" |
244 | | "count" |
245 | | "count_distinct" |
246 | | "sum" |
247 | | "avg" |
248 | | "min" |
249 | | "max" |
250 | | "p05" |
251 | | "p10" |
252 | | "p20" |
253 | | "p25" |
254 | | "p50" |
255 | | "p75" |
256 | | "p90" |
257 | | "p95" |
258 | | "p99" |
259 | | "rate" |
260 | | "rate_sum" |
261 | | "rate_avg" |
262 | | "rate_min" |
263 | | "rate_max"; |
264 | aggregateAttribute?: { |
265 | key: string; |
266 | dataType?: |
267 | | "string" |
268 | | "int64" |
269 | | "float64" |
270 | | "bool" |
271 | | "array(string)" |
272 | | "array(int64)" |
273 | | "array(float64)" |
274 | | "array(bool)"; |
275 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
276 | isColumn?: false | true; |
277 | isJSON?: false | true; |
278 | }; |
279 | temporality?: "Unspecified" | "Delta" | "Cumulative"; |
280 | filters?: { |
281 | op?: "AND" | "OR"; |
282 | items?: { |
283 | key: { |
284 | key: string; |
285 | dataType?: |
286 | | "string" |
287 | | "int64" |
288 | | "float64" |
289 | | "bool" |
290 | | "array(string)" |
291 | | "array(int64)" |
292 | | "array(float64)" |
293 | | "array(bool)"; |
294 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
295 | isColumn?: false | true; |
296 | isJSON?: false | true; |
297 | }; |
298 | value?: {}; |
299 | op: |
300 | | "=" |
301 | | "!=" |
302 | | ">" |
303 | | ">=" |
304 | | "<" |
305 | | "<=" |
306 | | "in" |
307 | | "nin" |
308 | | "like" |
309 | | "nlike" |
310 | | "contains" |
311 | | "ncontains" |
312 | | "regex" |
313 | | "nregex" |
314 | | "exists" |
315 | | "nexists" |
316 | | "has" |
317 | | "nhas"; |
318 | }[]; |
319 | }; |
320 | groupBy?: { |
321 | key: string; |
322 | dataType?: |
323 | | "string" |
324 | | "int64" |
325 | | "float64" |
326 | | "bool" |
327 | | "array(string)" |
328 | | "array(int64)" |
329 | | "array(float64)" |
330 | | "array(bool)"; |
331 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
332 | isColumn?: false | true; |
333 | isJSON?: false | true; |
334 | }[]; |
335 | expression: string; |
336 | disabled?: false | true; |
337 | having?: { |
338 | columnName: string; |
339 | op: "=" | "!=" | ">" | ">=" | "<" | "<=" | "IN" | "NOT_IN"; |
340 | value: {}; |
341 | }[]; |
342 | legend?: string; |
343 | limit?: number; |
344 | offset?: number; |
345 | pageSize?: number; |
346 | orderBy?: { columnName: string; order: "asc" | "desc" }[]; |
347 | reduceTo?: "sum" | "avg" | "min" | "max" | "last"; |
348 | selectColumns?: { |
349 | key: string; |
350 | dataType?: |
351 | | "string" |
352 | | "int64" |
353 | | "float64" |
354 | | "bool" |
355 | | "array(string)" |
356 | | "array(int64)" |
357 | | "array(float64)" |
358 | | "array(bool)"; |
359 | type?: "tag" | "resource" | "scope" | "spanSearchScope"; |
360 | isColumn?: false | true; |
361 | isJSON?: false | true; |
362 | }[]; |
363 | timeAggregation?: |
364 | | "count" |
365 | | "count_distinct" |
366 | | "sum" |
367 | | "avg" |
368 | | "min" |
369 | | "max" |
370 | | "rate" |
371 | | "latest" |
372 | | "increase"; |
373 | spaceAggregation?: |
374 | | "count" |
375 | | "sum" |
376 | | "avg" |
377 | | "min" |
378 | | "max" |
379 | | "p50" |
380 | | "p75" |
381 | | "p90" |
382 | | "p95" |
383 | | "p99"; |
384 | seriesAggregation?: "sum" | "avg" | "min" | "max"; |
385 | functions?: { |
386 | name: |
387 | | "cutOffMin" |
388 | | "cutOffMax" |
389 | | "clampMin" |
390 | | "clampMax" |
391 | | "absolute" |
392 | | "runningDiff" |
393 | | "log2" |
394 | | "log10" |
395 | | "cumSum" |
396 | | "ewma3" |
397 | | "ewma5" |
398 | | "ewma7" |
399 | | "median3" |
400 | | "median5" |
401 | | "median7" |
402 | | "timeShift" |
403 | | "anomaly"; |
404 | args?: {}[]; |
405 | namedArgs?: {}; |
406 | }[]; |
407 | }; |
408 | }; |
409 | }; |
410 | }[]; |
411 | }, |
412 | ) { |
413 | const url = new URL(`https://${auth.baseUrl}/api/v1/dashboards/${id}`); |
414 |
|
415 | const response = await fetch(url, { |
416 | method: "PUT", |
417 | headers: { |
418 | "Content-Type": "application/json", |
419 | "SIGNOZ-API-KEY": auth.apiKey, |
420 | }, |
421 | body: JSON.stringify(body), |
422 | }); |
423 | if (!response.ok) { |
424 | const text = await response.text(); |
425 | throw new Error(`${response.status} ${text}`); |
426 | } |
427 | return await response.text(); |
428 | } |
429 |
|