-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathkxdash.q
More file actions
56 lines (46 loc) · 1.77 KB
/
kxdash.q
File metadata and controls
56 lines (46 loc) · 1.77 KB
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
\d .kxdash
enabled:@[value;`enabled;{0b}];
// use this to store the additional params that the kx dashboards seem to send in
dashparams:`o`w`r`limit!(0;0i;0i;0W)
// function to be called from the dashboards
dashexec:{[q;s;j]
.gw.syncexecj[q;(),s;j]
}
// execute the request
// return a dict of status and result, along with the params
// add a flag to the start of the list to stop dictionaries collapsing
// to tables in the join function
dashremote:{[q;dashparams]
(`kxdash;dashparams,`status`result!@[{(1b;value x)};q;{(0b;x)}])
}
// join function used for dashboard results
dashjoin:{[joinfunc;r]
$[min r[;1;`status];
(`.dash.rcv_msg;r[0;1;`w];r[0;1;`o];r[0;1;`r];r[0;1;`limit] sublist joinfunc r[;1;`result]);
(`.dash.snd_err;r[0;1;`w];r[0;1;`r];r[0;1;`result])]
}
// this function is to be inserted into .z.ps to set the .kxdash.dashparams variable
dashps:{
// check the query coming in meets the format
if[@[{`f`w`r`x`u~first 1_ value first x};x;0b];
// pull out the values we need to return to the dashboards
dashparams::`o`w`r`limit!(last value x 1;x 2;x 3;x[4;0])];
};
// need this to handle queries that only hit one backend process
// reformat those responses to look the same
formatresponse:{[status;sync;result]
if[`kxdash~first result;
res:last result;
:$[res`status;
(`.dash.rcv_msg;res`w;res`o;res`r;res`result);
(`.dash.snd_err;res`w;res`r;res`result)]];
$[not[status]and sync;'result;result]}
init:{
// KX dashboards are expecting getFunctions to be defined on the process
.api.getFunctions:@[value;`.api.getFunctions;{{:()}}];
// Reset format response
.gw.formatresponse:formatresponse;
// incorporate dashps into the .z.ps definition
.dotz.set[`.z.ps;{x@y;.kxdash.dashps y}@[value;.dotz.getcommand[`.z.ps];{{value x}}]];
};
if[enabled;init[]];