Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
1bcbb47a
Commit
1bcbb47a
authored
Mar 01, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use counters and gauges with labels defined as global variables
parent
6fca6fbb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
14 deletions
+31
-14
internal/builds/register.go
internal/builds/register.go
+31
-14
No files found.
internal/builds/register.go
View file @
1bcbb47a
...
...
@@ -33,6 +33,23 @@ var (
)
)
var
(
registerHandlerOpenAtReading
=
registerHandlerOpen
.
WithLabelValues
(
"reading"
)
registerHandlerOpenAtProxying
=
registerHandlerOpen
.
WithLabelValues
(
"proxying"
)
registerHandlerOpenAtWatching
=
registerHandlerOpen
.
WithLabelValues
(
"watching"
)
)
var
(
registerHandlerBodyReadErrors
=
registerHandlerHits
.
WithLabelValues
(
"body-read-error"
)
registerHandlerBodyParseErrors
=
registerHandlerHits
.
WithLabelValues
(
"body-parse-error"
)
registerHandlerMissingValues
=
registerHandlerHits
.
WithLabelValues
(
"missing-values"
)
registerHandlerWatchErrors
=
registerHandlerHits
.
WithLabelValues
(
"watch-error"
)
registerHandlerAlreadyChangedHits
=
registerHandlerHits
.
WithLabelValues
(
"already-changed"
)
registerHandlerSeenChangeHits
=
registerHandlerHits
.
WithLabelValues
(
"seen-change"
)
registerHandlerTimeoutHits
=
registerHandlerHits
.
WithLabelValues
(
"timeout"
)
registerHandlerNoChangeHits
=
registerHandlerHits
.
WithLabelValues
(
"no-change"
)
)
type
largeBodyError
struct
{
error
}
type
watchError
struct
{
error
}
...
...
@@ -51,8 +68,8 @@ type runnerRequest struct {
}
func
readRunnerBody
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
([]
byte
,
error
)
{
registerHandlerOpen
.
WithLabelValues
(
"reading"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"reading"
)
.
Dec
()
registerHandlerOpen
AtReading
.
Inc
()
defer
registerHandlerOpen
AtReading
.
Dec
()
return
helper
.
ReadRequestBody
(
w
,
r
,
maxRegisterBodySize
)
}
...
...
@@ -73,15 +90,15 @@ func readRunnerRequest(r *http.Request, body []byte) (runnerRequest, error) {
}
func
proxyRegisterRequest
(
h
http
.
Handler
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
registerHandlerOpen
.
WithLabelValues
(
"proxying"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"proxying"
)
.
Dec
()
registerHandlerOpen
AtProxying
.
Inc
()
defer
registerHandlerOpen
AtProxying
.
Dec
()
h
.
ServeHTTP
(
w
,
r
)
}
func
watchForRunnerChange
(
watchHandler
WatchKeyHandler
,
token
,
lastUpdate
string
,
duration
time
.
Duration
)
(
redis
.
WatchKeyStatus
,
error
)
{
registerHandlerOpen
.
WithLabelValues
(
"watching"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"watching"
)
.
Dec
()
registerHandlerOpen
AtWatching
.
Inc
()
defer
registerHandlerOpen
AtWatching
.
Dec
()
return
watchHandler
(
runnerBuildQueue
+
token
,
lastUpdate
,
duration
)
}
...
...
@@ -94,7 +111,7 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
requestBody
,
err
:=
readRunnerBody
(
w
,
r
)
if
err
!=
nil
{
registerHandler
Hits
.
WithLabelValues
(
"body-read-error"
)
.
Inc
()
registerHandler
BodyReadErrors
.
Inc
()
helper
.
RequestEntityTooLarge
(
w
,
r
,
&
largeBodyError
{
err
})
return
}
...
...
@@ -103,13 +120,13 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
runnerRequest
,
err
:=
readRunnerRequest
(
r
,
requestBody
)
if
err
!=
nil
{
registerHandler
Hits
.
WithLabelValues
(
"body-parse-error"
)
.
Inc
()
registerHandler
BodyParseErrors
.
Inc
()
proxyRegisterRequest
(
h
,
w
,
newRequest
)
return
}
if
runnerRequest
.
Token
==
""
||
runnerRequest
.
LastUpdate
==
""
{
registerHandler
Hits
.
WithLabelValues
(
"missing-values"
)
.
Inc
()
registerHandler
MissingValues
.
Inc
()
proxyRegisterRequest
(
h
,
w
,
newRequest
)
return
}
...
...
@@ -117,7 +134,7 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
result
,
err
:=
watchForRunnerChange
(
watchHandler
,
runnerRequest
.
Token
,
runnerRequest
.
LastUpdate
,
pollingDuration
)
if
err
!=
nil
{
registerHandler
Hits
.
WithLabelValues
(
"watch-error"
)
.
Inc
()
registerHandler
WatchErrors
.
Inc
()
proxyRegisterRequest
(
h
,
w
,
newRequest
)
return
}
...
...
@@ -126,7 +143,7 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
// It means that we detected a change before starting watching on change,
// We proxy request to Rails, to see whether we can receive the build
case
redis
.
WatchKeyStatusAlreadyChanged
:
registerHandler
Hits
.
WithLabelValues
(
"already-changed"
)
.
Inc
()
registerHandler
AlreadyChangedHits
.
Inc
()
proxyRegisterRequest
(
h
,
w
,
newRequest
)
// It means that we detected a change after watching.
...
...
@@ -135,18 +152,18 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
// as don't really know whether ResponseWriter is still in a sane state,
// whether the connection is not dead
case
redis
.
WatchKeyStatusSeenChange
:
registerHandler
Hits
.
WithLabelValues
(
"seen-change"
)
.
Inc
()
registerHandler
SeenChangeHits
.
Inc
()
w
.
WriteHeader
(
http
.
StatusNoContent
)
// When we receive one of these statuses, it means that we detected no change,
// so we return to runner 204, which means nothing got changed,
// and there's no new builds to process
case
redis
.
WatchKeyStatusTimeout
:
registerHandler
Hits
.
WithLabelValues
(
"timeout"
)
.
Inc
()
registerHandler
TimeoutHits
.
Inc
()
w
.
WriteHeader
(
http
.
StatusNoContent
)
case
redis
.
WatchKeyStatusNoChange
:
registerHandler
Hits
.
WithLabelValues
(
"no-change"
)
.
Inc
()
registerHandler
NoChangeHits
.
Inc
()
w
.
WriteHeader
(
http
.
StatusNoContent
)
}
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment