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