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
be1c3faa
Commit
be1c3faa
authored
Dec 09, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PoC of git clone/fetch requests metric
parent
eb451e03
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
internal/helper/logging.go
internal/helper/logging.go
+28
-0
No files found.
internal/helper/logging.go
View file @
be1c3faa
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"net/http"
"net/http"
"os"
"os"
"strconv"
"strconv"
"strings"
"time"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
...
@@ -27,6 +28,14 @@ var (
...
@@ -27,6 +28,14 @@ var (
},
},
[]
string
{
"code"
,
"method"
},
[]
string
{
"code"
,
"method"
},
)
)
cloneFetchRequests
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_git_clone_fetch_requests"
,
Help
:
"How many Git clone/fetch requests for CI have been processed by gitlab-workhorse, partitioned by CI yes/no status."
,
},
[]
string
{
"ci"
},
)
)
)
func
init
()
{
func
init
()
{
...
@@ -41,6 +50,7 @@ func SetCustomResponseLogger(writer io.Writer) {
...
@@ -41,6 +50,7 @@ func SetCustomResponseLogger(writer io.Writer) {
func
registerPrometheusMetrics
()
{
func
registerPrometheusMetrics
()
{
prometheus
.
MustRegister
(
sessionsActive
)
prometheus
.
MustRegister
(
sessionsActive
)
prometheus
.
MustRegister
(
requestsTotal
)
prometheus
.
MustRegister
(
requestsTotal
)
prometheus
.
MustRegister
(
cloneFetchRequests
)
}
}
type
LoggingResponseWriter
struct
{
type
LoggingResponseWriter
struct
{
...
@@ -88,6 +98,24 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
...
@@ -88,6 +98,24 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
l
.
status
,
l
.
written
,
r
.
Referer
(),
r
.
UserAgent
(),
duration
.
Seconds
(),
l
.
status
,
l
.
written
,
r
.
Referer
(),
r
.
UserAgent
(),
duration
.
Seconds
(),
)
)
l
.
countCloneFetchRequests
(
r
)
sessionsActive
.
Dec
()
sessionsActive
.
Dec
()
requestsTotal
.
WithLabelValues
(
strconv
.
Itoa
(
l
.
status
),
r
.
Method
)
.
Inc
()
requestsTotal
.
WithLabelValues
(
strconv
.
Itoa
(
l
.
status
),
r
.
Method
)
.
Inc
()
}
}
func
(
l
*
LoggingResponseWriter
)
countCloneFetchRequests
(
r
*
http
.
Request
)
{
if
l
.
status
==
401
||
!
strings
.
Contains
(
r
.
RequestURI
,
"/info/refs?service=git-upload-pack"
)
{
return
}
u
,
_
,
ok
:=
r
.
BasicAuth
()
var
forCi
string
if
ok
&&
u
==
"gitlab-ci-token"
{
forCi
=
"1"
}
else
{
forCi
=
"0"
}
cloneFetchRequests
.
WithLabelValues
(
forCi
)
.
Inc
()
}
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