Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
2b0e1fd1
Commit
2b0e1fd1
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add debug page for lbv2
parent
292e4e71
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
fe/http.go
+6
-4
6 additions, 4 deletions
fe/http.go
fe/http_debug.go
+1
-1
1 addition, 1 deletion
fe/http_debug.go
fe/http_test.go
+10
-0
10 additions, 0 deletions
fe/http_test.go
fe/lbv2/debug.go
+80
-0
80 additions, 0 deletions
fe/lbv2/debug.go
with
97 additions
and
5 deletions
fe/http.go
+
6
−
4
View file @
2b0e1fd1
...
...
@@ -316,10 +316,12 @@ func (h *HttpRedirector) createHandler() http.Handler {
nil
))
// Pass /debug/ to the default ServeMux, all the default debug
// handlers are installed there.
mux
.
Handle
(
"/debug/"
,
handlers
.
GZIPHandler
(
http
.
DefaultServeMux
,
nil
))
// handlers are installed there. Add a debug handler for the
// LoadBalancer data. Gzip the responses.
debugMux
:=
http
.
NewServeMux
()
debugMux
.
Handle
(
"/debug/lbv2"
,
h
.
lb
)
debugMux
.
Handle
(
"/"
,
http
.
DefaultServeMux
)
mux
.
Handle
(
"/debug/"
,
handlers
.
GZIPHandler
(
debugMux
,
nil
))
// Optionally enable a reverse proxy to the local Icecast for
// the direct stream URLs (below IcecastMountPrefix).
...
...
This diff is collapsed.
Click to expand it.
fe/http_debug.go
+
1
−
1
View file @
2b0e1fd1
...
...
@@ -2,10 +2,10 @@ package fe
import
(
"fmt"
"html/template"
"net/http"
"sort"
"sync"
"text/template"
"time"
)
...
...
This diff is collapsed.
Click to expand it.
fe/http_test.go
+
10
−
0
View file @
2b0e1fd1
...
...
@@ -103,6 +103,16 @@ func TestHttpRedirector_Static(t *testing.T) {
}
}
func
TestHttpRedirector_LBDebugPage
(
t
*
testing
.
T
)
{
_
,
srv
:=
createTestHttpServer
(
t
)
defer
srv
.
Close
()
data
:=
doHttpRequest
(
t
,
"GET"
,
srv
.
URL
+
"/debug/lbv2"
,
200
)
if
!
strings
.
Contains
(
data
,
"node1"
)
{
t
.
Errorf
(
"Bad response:
\n
%s"
,
data
)
}
}
type
httpTestContext
struct
{
srv
*
httptest
.
Server
targetSrv
*
httptest
.
Server
...
...
This diff is collapsed.
Click to expand it.
fe/lbv2/debug.go
0 → 100644
+
80
−
0
View file @
2b0e1fd1
package
lbv2
import
(
"fmt"
"html/template"
"net/http"
)
const
debugText
=
`<html>
<body>
<title>Load Balancer</title>
<h3>Query costs</h3>
<table>
<tr><th>Node</th><th>Requests</th><th>Utilization/Cost</th></tr>
{{$dimensions := .Dimensions}}
{{range .Nodes}}
<tr>
<td>{{.Name}}</td>
<td>{{.Requests}}</td>
{{range $d := $dimensions}}
{{$data := index .Data $d}}
<td>
{{$data.PredictedUtilization}}/{{$data.ReportedUtilization}}/{{$data.Cost}}
</td>
{{end}}
</tr>
{{end}}
</table>
</body>
</html>`
var
debugTmpl
=
template
.
Must
(
template
.
New
(
"lbv2 debug"
)
.
Parse
(
debugText
))
type
nodeDebugData
struct
{
Name
string
Requests
int
Data
map
[
int
]
costAndUtil
}
type
costAndUtil
struct
{
ReportedUtilization
float64
PredictedUtilization
float64
Cost
float64
}
func
(
l
*
LoadBalancer
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// Build a view of the cost/utilization data.
l
.
lock
.
Lock
()
var
nodes
[]
nodeDebugData
for
_
,
n
:=
range
l
.
nodes
{
ndata
:=
nodeDebugData
{
Name
:
n
.
Name
(),
Data
:
make
(
map
[
int
]
costAndUtil
)}
for
dim
,
pred
:=
range
l
.
predictors
{
util
:=
n
.
Utilization
(
dim
)
ndata
.
Requests
=
util
.
Requests
ndata
.
Data
[
dim
]
=
costAndUtil
{
ReportedUtilization
:
util
.
Utilization
,
PredictedUtilization
:
pred
.
Utilization
(
n
),
Cost
:
float64
(
pred
.
cost
[
n
.
Name
()]),
}
}
nodes
=
append
(
nodes
,
ndata
)
}
var
dimensions
[]
int
for
dim
:=
range
l
.
predictors
{
dimensions
=
append
(
dimensions
,
dim
)
}
l
.
lock
.
Unlock
()
ctx
:=
struct
{
Nodes
[]
nodeDebugData
Dimensions
[]
int
NumDimensions
int
}{
nodes
,
dimensions
,
len
(
dimensions
)}
err
:=
debugTmpl
.
Execute
(
w
,
ctx
)
if
err
!=
nil
{
fmt
.
Fprintln
(
w
,
"debug: error executing template: "
,
err
.
Error
())
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment