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
8e4cf676
Commit
8e4cf676
authored
Dec 12, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add artifacts related metrics
parent
32b3fa9f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
0 deletions
+73
-0
internal/artifacts/artifacts_upload.go
internal/artifacts/artifacts_upload.go
+30
-0
internal/sendfile/sendfile.go
internal/sendfile/sendfile.go
+43
-0
No files found.
internal/artifacts/artifacts_upload.go
View file @
8e4cf676
...
...
@@ -9,12 +9,37 @@ import (
"os/exec"
"syscall"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/upload"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/zipartifacts"
)
var
(
artifactsUploadRequests
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_artifacts_upload_requests"
,
Help
:
"How many artifacts upload requests have been processed by gitlab-workhorse."
,
},
nil
,
)
artifactsUploadBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_artifacts_upload_bytes"
,
Help
:
"How many artifacts upload bytes have been send by gitlab-workhorse."
,
},
nil
,
)
)
func
init
()
{
prometheus
.
MustRegister
(
artifactsUploadRequests
)
prometheus
.
MustRegister
(
artifactsUploadBytes
)
}
type
artifactsUploadProcessor
struct
{
TempPath
string
metadataFile
string
...
...
@@ -73,6 +98,11 @@ 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
()
defer
func
()
{
artifactsUploadBytes
.
WithLabelValues
()
.
Add
(
float64
(
r
.
ContentLength
))
}()
if
a
.
TempPath
==
""
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"UploadArtifacts: TempPath is empty"
))
return
...
...
internal/sendfile/sendfile.go
View file @
8e4cf676
...
...
@@ -9,12 +9,33 @@ package sendfile
import
(
"log"
"net/http"
"regexp"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
const
sendFileResponseHeader
=
"X-Sendfile"
var
(
sendFileRequests
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_sendfile_requests"
,
Help
:
"How many X-Sendfile requests have been processed by gitlab-workhorse, partitioned by sendfile type."
,
},
[]
string
{
"type"
},
)
sendFileBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_sendfile_bytes"
,
Help
:
"How many X-Sendfile bytes have been send by gitlab-workhorse, partitioned by sendfile type."
,
},
[]
string
{
"type"
},
)
)
type
sendFileResponseWriter
struct
{
rw
http
.
ResponseWriter
status
int
...
...
@@ -22,6 +43,11 @@ type sendFileResponseWriter struct {
req
*
http
.
Request
}
func
init
()
{
prometheus
.
MustRegister
(
sendFileRequests
)
prometheus
.
MustRegister
(
sendFileBytes
)
}
func
SendFile
(
h
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
s
:=
&
sendFileResponseWriter
{
...
...
@@ -84,9 +110,26 @@ func sendFileFromDisk(w http.ResponseWriter, r *http.Request, file string) {
}
defer
content
.
Close
()
countSendFileMetrics
(
fi
.
Size
(),
r
)
http
.
ServeContent
(
w
,
r
,
""
,
fi
.
ModTime
(),
content
)
}
func
countSendFileMetrics
(
size
int64
,
r
*
http
.
Request
)
{
var
requestType
string
switch
{
case
regexp
.
MustCompile
(
"builds/[0-9]+/artifacts"
)
.
MatchString
(
r
.
RequestURI
)
:
requestType
=
"artifacts"
default
:
requestType
=
"other"
}
sendFileRequests
.
WithLabelValues
(
requestType
)
.
Inc
()
defer
func
()
{
sendFileBytes
.
WithLabelValues
(
requestType
)
.
Add
(
float64
(
size
))
}()
}
func
(
s
*
sendFileResponseWriter
)
Flush
()
{
s
.
WriteHeader
(
http
.
StatusOK
)
}
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