-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathqueries-logs.html
More file actions
263 lines (246 loc) · 10.7 KB
/
queries-logs.html
File metadata and controls
263 lines (246 loc) · 10.7 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
{{ $metadata := .Metadata }} {{ $serviceConfig := .ServiceConfig }} {{ $leftmeta := .LeftMetadata }} {{ template "page-head" . }}
<body class="app header-fixed sidebar-fixed sidebar-lg-show">
{{ template "page-header" . }}
<div class="app-body">
{{ template "page-aside-left" . }}
<main class="main">
<div class="container-fluid">
<div class="animated fadeIn">
{{ if $leftmeta.Query }} {{ with .Query }}
<div class="card mt-2">
<div class="card-header">
{{ if .Expired }}
<i class="fas fa-stopwatch"></i> [ <b>QUERY EXPIRED</b> ] - {{ .Name }} {{ else }} {{ if .Completed }} <i class="fas fa-flag-checkered"></i> [ <b>QUERY COMPLETED</b> ] - {{ .Name }} {{ else }}
<i class="fas fa-hourglass-half"></i> [ <b>QUERY ACTIVE</b> ] - {{ .Name }} - <b>{{ inFutureTime .Expiration }}</b> {{ end }} -
<a href="{{ queryResultLink .Name $leftmeta.EnvUUID }}" target="_blank" rel="noopener noreferrer"><i class="fas fa-external-link-alt"></i></a>
{{ end }}
<div class="card-header-actions">
<button class="btn btn-sm btn-outline-primary" data-tooltip="true" data-placement="bottom" title="Refresh table" onclick="refreshTableNow('tableQueryLogs');">
<i class="fas fa-sync-alt"></i>
</button>
</div>
</div>
<div class="card-body table-responsive">
<table class="table table-responsive-sm table-bordered table-striped text-center">
<thead>
<tr>
<th width="60%">Query</th>
<th width="25%">Target</th>
<th width="15%">Expected / Status</th>
</tr>
</thead>
<tbody>
<tr>
<td class="query-log">
<b>{{ .Query }}</b>
</td>
<td>
<table class="table table-sm table-light" style="width: 100%">
<tr>
<th width="50%">Type</th>
<th width="50%">Value</th>
</tr>
<tr>
{{ range $i, $e := $.QueryTargets }}
</tr>
<tr style="background-color: #ffffff">
<td>{{ $e.Type }}</td>
<td><b>{{ $e.Value }}</b></td>
</tr>
{{ end }}
</table>
</td>
<td style="text-align: center; vertical-align: middle">
<span style="color: black">{{ .Expected }}</span>/ <b><span style="color: green">{{ .Executions }}</span></b
>/
<b><span style="color: red">{{ .Errors }}</span></b>
</td>
</tr>
</tbody>
</table>
<br />
{{ if eq $serviceConfig.Logger "db" }}
<div id="downloadLinkContainer" class="alert alert-info" style="display: none">
<i class="fas fa-info-circle"></i>
<strong>Large Result Set:</strong> The results are too large to display in the table.
<a id="downloadLink" href="#" class="btn btn-sm btn-primary ml-2"> <i class="fas fa-download"></i> Download Full Results </a>
</div>
<table id="tableQueryLogs" class="table table-bordered table-striped" style="width: 100%">
<input type="hidden" id="refresh_value" value="yes" />
<thead>
<tr>
<th>Created</th>
<th>Target</th>
<th>Data</th>
</tr>
</thead>
</table>
{{ else }}
<div class="alert alert-warning" role="alert"><i class="fas fa-exclamation-triangle"></i> The logger is set to <b>{{ $serviceConfig.Logger }}</b> in the service configuration. No results available.</div>
{{ end }}
</div>
</div>
{{ end }} {{ else }}
<div class="card mt-2">
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading"><i class="fas fa-exclamation-triangle"></i> Query logs not available</h4>
</div>
</div>
{{ end }}
</div>
</div>
</main>
{{ if $metadata.Admin }} {{ template "page-aside-right" . }} {{ end }}
</div>
{{ template "page-js" . }}
<!-- custom JS -->
<script src="/static/js/tables.js"></script>
{{ with .Query }}
<script type="text/javascript">
$(document).ready(function () {
$.fn.dataTable.ext.errMode = function (settings, helpPage, message) {
console.log(message);
$(".card-header").addClass("bg-danger");
};
$.fn.dataTable.ext.ajax;
var downloadUrl = ""; // Store download URL globally
var tableQueryLogs = $("#tableQueryLogs").DataTable({
initComplete: function (settings, json) {
$(".card-header").removeClass("bg-danger");
},
pageLength: 25,
searching: true,
processing: true,
ajax: {
url: "/json/query/{{ $leftmeta.EnvUUID }}/{{ .Name }}",
dataSrc: function (json) {
$("#status-card-header").removeClass("bg-danger");
// Store download URL if available
downloadUrl = json.download || "";
// Show/hide download link container
if (downloadUrl && downloadUrl !== "") {
$("#downloadLink").attr("href", downloadUrl);
$("#downloadLinkContainer").show();
} else {
$("#downloadLinkContainer").hide();
}
return json.data;
},
error: function (xhr, error, code) {
$(".card-header").addClass("bg-danger");
console.log("Error: " + error);
console.log("Error code: " + code);
console.log("Error response: " + xhr.responseText);
},
},
columns: [
{
data: {
_: "created.display",
sort: "created.timestamp",
},
},
{ data: "target" },
{ data: "data" },
],
order: [[0, "desc"]],
columnDefs: [
{ width: "10%", targets: 0 },
{
width: "15%",
targets: 1,
render: function (data, type, row, meta) {
if (type === "display") {
return '<a href="/node/' + data.uuid + '">' + data.name + "</a>";
} else {
return data;
}
},
},
{
width: "75%",
targets: 2,
render: function (data, type, row, meta) {
try {
var rawData = JSON.parse(JSON.parse(data));
var results = rawData.result;
if (!Array.isArray(results) || results.length === 0) {
return type === "display" ? '<div class="text-muted">No results</div>' : "";
}
// For filtering/searching, return all values as searchable text
if (type === "filter" || type === "search") {
var searchText = [];
results.forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
var value = obj[key];
if (value !== undefined && value !== null) {
if (typeof value === "object") {
searchText.push(JSON.stringify(value));
} else {
searchText.push(String(value));
}
}
});
});
return searchText.join(" ");
}
// For display, show the table
if (type === "display") {
// Get all unique keys from all objects
var keys = [];
results.forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
if (keys.indexOf(key) === -1) {
keys.push(key);
}
});
});
// Build table
var table = '<table class="table table-sm table-bordered table-hover" style="margin-bottom: 0;">';
table += '<thead class="thead-light"><tr>';
keys.forEach(function (key) {
table += '<th style="font-size: 0.85rem;">' + key + "</th>";
});
table += "</tr></thead><tbody>";
results.forEach(function (obj) {
table += "<tr>";
keys.forEach(function (key) {
var value = obj[key] !== undefined && obj[key] !== null ? obj[key] : "";
// Handle nested objects/arrays
if (typeof value === "object") {
value = JSON.stringify(value);
}
table += '<td style="font-size: 0.85rem;">' + value + "</td>";
});
table += "</tr>";
});
table += "</tbody></table>";
return table;
}
// For other types (sort, etc), return raw data
return data;
} catch (e) {
return type === "display" ? '<div class="text-danger">Error parsing results: ' + e.message + "</div>" : "";
}
},
},
],
});
// Enable all tooltips
$('[data-tooltip="true"]').tooltip({ trigger: "hover" });
// Auto-refresh table
setInterval(function () {
tableQueryLogs.ajax.reload();
}, 30000);
// Refresh sidebar stats
beginStats();
var statsTimer = setInterval(function () {
beginStats();
}, 60000);
});
</script>
{{ end }}
</body>
</html>