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
28ab61e1
Commit
28ab61e1
authored
Dec 12, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor metrics counting
parent
8e4cf676
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
33 deletions
+34
-33
internal/artifacts/artifacts_upload.go
internal/artifacts/artifacts_upload.go
+5
-7
internal/git/git-http.go
internal/git/git-http.go
+27
-18
internal/helper/logging.go
internal/helper/logging.go
+0
-4
internal/sendfile/sendfile.go
internal/sendfile/sendfile.go
+2
-4
No files found.
internal/artifacts/artifacts_upload.go
View file @
28ab61e1
...
...
@@ -18,20 +18,18 @@ import (
)
var
(
artifactsUploadRequests
=
prometheus
.
NewCounter
Vec
(
artifactsUploadRequests
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_artifacts_upload_requests"
,
Help
:
"How many artifacts upload requests have been processed by gitlab-workhorse."
,
},
nil
,
)
artifactsUploadBytes
=
prometheus
.
NewCounter
Vec
(
artifactsUploadBytes
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_artifacts_upload_bytes"
,
Help
:
"How many artifacts upload bytes have been sen
d
by gitlab-workhorse."
,
Help
:
"How many artifacts upload bytes have been sen
t
by gitlab-workhorse."
,
},
nil
,
)
)
...
...
@@ -98,9 +96,9 @@ func (a *artifactsUploadProcessor) Cleanup() {
func
UploadArtifacts
(
myAPI
*
api
.
API
,
h
http
.
Handler
)
http
.
Handler
{
return
myAPI
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
artifactsUploadRequests
.
WithLabelValues
()
.
Inc
()
artifactsUploadRequests
.
Inc
()
defer
func
()
{
artifactsUploadBytes
.
WithLabelValues
()
.
Add
(
float64
(
r
.
ContentLength
))
artifactsUploadBytes
.
Add
(
float64
(
r
.
ContentLength
))
}()
if
a
.
TempPath
==
""
{
...
...
internal/git/git-http.go
View file @
28ab61e1
...
...
@@ -26,17 +26,17 @@ var (
gitHTTPRequests
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_git_http_requests"
,
Help
:
"How many Git HTTP requests have been processed by gitlab-workhorse, partitioned by
CI yes/no status
."
,
Help
:
"How many Git HTTP requests have been processed by gitlab-workhorse, partitioned by
request type and agent
."
,
},
[]
string
{
"
ci
"
},
[]
string
{
"
request_type"
,
"agent
"
},
)
gitHTTPBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_git_http_bytes"
,
Help
:
"How many Git HTTP bytes have been sen
d by gitlab-workhorse, partitioned by CI yes/no status
."
,
Help
:
"How many Git HTTP bytes have been sen
t by gitlab-workhorse, partitioned by request type, agent and direction
."
,
},
[]
string
{
"
ci
"
},
[]
string
{
"
request_type"
,
"agent"
,
"direction
"
},
)
)
...
...
@@ -63,25 +63,19 @@ func looksLikeRepo(p string) bool {
return
true
}
func
forCI
(
r
*
http
.
Request
)
string
{
func
getRequestAgent
(
r
*
http
.
Request
)
string
{
u
,
_
,
ok
:=
r
.
BasicAuth
()
if
ok
&&
u
==
"gitlab-ci-token"
{
return
"1"
return
"gitlab-ci"
}
else
if
ok
{
return
"logged"
}
else
{
return
"
0
"
return
"
anonymous
"
}
}
func
repoPreAuthorizeHandler
(
myAPI
*
api
.
API
,
handleFunc
api
.
HandleFunc
)
http
.
Handler
{
return
myAPI
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
gitHTTPRequests
.
WithLabelValues
(
forCI
(
r
))
.
Inc
()
defer
func
()
{
lw
,
ok
:=
w
.
(
*
helper
.
LoggingResponseWriter
)
if
ok
{
gitHTTPBytes
.
WithLabelValues
(
forCI
(
r
))
.
Add
(
float64
(
lw
.
Size
()))
}
}()
if
a
.
RepoPath
==
""
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"repoPreAuthorizeHandler: RepoPath empty"
))
return
...
...
@@ -104,6 +98,13 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *api.Response)
return
}
requestType
:=
"get-info-refs"
gitHTTPRequests
.
WithLabelValues
(
requestType
,
getRequestAgent
(
r
))
.
Inc
()
var
writtenOut
int64
defer
func
()
{
gitHTTPBytes
.
WithLabelValues
(
requestType
,
getRequestAgent
(
r
),
"out"
)
.
Add
(
float64
(
writtenOut
))
}()
// Prepare our Git subprocess
cmd
:=
gitCommand
(
a
.
GL_ID
,
"git"
,
subCommand
(
rpc
),
"--stateless-rpc"
,
"--advertise-refs"
,
a
.
RepoPath
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
...
...
@@ -130,7 +131,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *api.Response)
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: pktFlush: %v"
,
err
))
return
}
if
_
,
err
:
=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
if
writtenOut
,
err
=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
helper
.
LogError
(
r
,
&
copyError
{
fmt
.
Errorf
(
"handleGetInfoRefs: copy output of %v: %v"
,
cmd
.
Args
,
err
)},
...
...
@@ -156,6 +157,14 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
return
}
requestType
:=
"post-"
+
action
gitHTTPRequests
.
WithLabelValues
(
requestType
,
getRequestAgent
(
r
))
.
Inc
()
var
writtenIn
,
writtenOut
int64
defer
func
()
{
gitHTTPBytes
.
WithLabelValues
(
requestType
,
getRequestAgent
(
r
),
"in"
)
.
Add
(
float64
(
writtenIn
))
gitHTTPBytes
.
WithLabelValues
(
requestType
,
getRequestAgent
(
r
),
"out"
)
.
Add
(
float64
(
writtenOut
))
}()
if
action
==
"git-upload-pack"
{
buffer
:=
&
bytes
.
Buffer
{}
// Only sniff on the first 4096 bytes: we assume that if we find no
...
...
@@ -194,7 +203,7 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
defer
helper
.
CleanUpProcessGroup
(
cmd
)
// Ensure brute force subprocess clean-up
// Write the client request body to Git's standard input
if
_
,
err
:
=
io
.
Copy
(
stdin
,
body
);
err
!=
nil
{
if
writtenIn
,
err
=
io
.
Copy
(
stdin
,
body
);
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handlePostRPC: write to %v: %v"
,
cmd
.
Args
,
err
))
return
}
...
...
@@ -211,7 +220,7 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
w
.
WriteHeader
(
200
)
// Don't bother with HTTP 500 from this point on, just return
// This io.Copy may take a long time, both for Git push and pull.
if
_
,
err
:
=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
if
writtenOut
,
err
=
io
.
Copy
(
w
,
stdout
);
err
!=
nil
{
helper
.
LogError
(
r
,
&
copyError
{
fmt
.
Errorf
(
"handlePostRPC: copy output of %v: %v"
,
cmd
.
Args
,
err
)},
...
...
internal/helper/logging.go
View file @
28ab61e1
...
...
@@ -91,7 +91,3 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
sessionsActive
.
Dec
()
requestsTotal
.
WithLabelValues
(
strconv
.
Itoa
(
l
.
status
),
r
.
Method
)
.
Inc
()
}
func
(
l
*
LoggingResponseWriter
)
Size
()
int64
{
return
l
.
written
}
internal/sendfile/sendfile.go
View file @
28ab61e1
...
...
@@ -30,7 +30,7 @@ var (
sendFileBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_sendfile_bytes"
,
Help
:
"How many X-Sendfile bytes have been sen
d
by gitlab-workhorse, partitioned by sendfile type."
,
Help
:
"How many X-Sendfile bytes have been sen
t
by gitlab-workhorse, partitioned by sendfile type."
,
},
[]
string
{
"type"
},
)
...
...
@@ -125,9 +125,7 @@ func countSendFileMetrics(size int64, r *http.Request) {
}
sendFileRequests
.
WithLabelValues
(
requestType
)
.
Inc
()
defer
func
()
{
sendFileBytes
.
WithLabelValues
(
requestType
)
.
Add
(
float64
(
size
))
}()
}
func
(
s
*
sendFileResponseWriter
)
Flush
()
{
...
...
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