forked from dolthub/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logz_utils.go
157 lines (143 loc) · 3.61 KB
/
logz_utils.go
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
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tabletserver
import (
"bytes"
"net/http"
"strconv"
"time"
)
func startHTMLTable(w http.ResponseWriter) {
w.Write([]byte(`
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
border-width: 1px;
border-collapse: collapse;
table-layout:fixed;
overflow: hidden;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
background-color: #dedede;
white-space: nowrap;
}
table.gridtable tr.low {
background-color: #f0f0f0;
}
table.gridtable tr.medium {
background-color: #ffcc00;
}
table.gridtable tr.high {
background-color: #ff3300;
}
table.gridtable tr.error {
background-color: #00ddff;
}
table.gridtable td {
border-width: 1px;
padding: 4px;
border-style: solid;
}
table.gridtable th {
padding-left: 2em;
padding-right: 2em;
}
table.gridtable th.descending:before {
content: "▲";
float: left;
}
table.gridtable th.ascending:before {
content: "▼";
float: left;
}
</style>
</head>
<body>
<table class="gridtable">
`))
}
func endHTMLTable(w http.ResponseWriter) {
defer w.Write([]byte(`
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
$.fn.sortableByColumn = function() {
var body = this.find('tbody');
var header = this.find('thead');
var contents = function(el, i) {
var data = $(el).children('td').eq(i).text().toLowerCase();
var asNumber = parseFloat(data);
return data == asNumber ? asNumber : data;
};
this.find('thead tr th').each(function(index, th) {
$(th).wrapInner('<div width="5em;"></div>');
var direction = -1;
$(th).click(function() {
direction *= -1;
header.find('th').removeClass('ascending descending');
$(th).addClass(direction > 0? 'ascending' : 'descending');
var rows = body.find('tr').detach();
rows.sort(function(left, right) {
var cl = contents(left, index);
var cr = contents(right, index);
if (cl === cr) {
return 0
} else {
return contents(left, index) > contents(right, index)? direction : -direction;
}
});
body.append(rows);
});
});
}
$(function() {
$('table').sortableByColumn();
});
</script>
</body>
</html>`))
}
// wrappable inserts zero-width whitespaces to make
// the string wrappable.
func wrappable(in string) string {
buf := bytes.NewBuffer(nil)
for _, ch := range in {
buf.WriteRune(ch)
if ch == ',' || ch == ')' {
// zero-width whitespace
buf.WriteRune('\u200B')
}
}
return buf.String()
}
func adjustValue(val int, lower int, upper int) int {
if val < lower {
return lower
} else if val > upper {
return upper
}
return val
}
func parseTimeoutLimitParams(req *http.Request) (time.Duration, int) {
timeout := 10
limit := 300
if ts, ok := req.URL.Query()["timeout"]; ok {
if t, err := strconv.Atoi(ts[0]); err == nil {
timeout = adjustValue(t, 0, 60)
}
}
if l, ok := req.URL.Query()["limit"]; ok {
if lim, err := strconv.Atoi(l[0]); err == nil {
limit = adjustValue(lim, 1, 200000)
}
}
return time.Duration(timeout) * time.Second, limit
}