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
32b3fa9f
Commit
32b3fa9f
authored
Dec 12, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move metrics from helper/logging.go to git/git-http.go
parent
bad25752
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
36 deletions
+44
-36
internal/git/git-http.go
internal/git/git-http.go
+42
-0
internal/helper/logging.go
internal/helper/logging.go
+2
-36
No files found.
internal/git/git-http.go
View file @
32b3fa9f
...
...
@@ -16,10 +16,35 @@ import (
"path/filepath"
"strings"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
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."
,
},
[]
string
{
"ci"
},
)
gitHTTPBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_git_http_bytes"
,
Help
:
"How many Git HTTP bytes have been send by gitlab-workhorse, partitioned by CI yes/no status."
,
},
[]
string
{
"ci"
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
gitHTTPRequests
)
prometheus
.
MustRegister
(
gitHTTPBytes
)
}
func
GetInfoRefs
(
a
*
api
.
API
)
http
.
Handler
{
return
repoPreAuthorizeHandler
(
a
,
handleGetInfoRefs
)
}
...
...
@@ -38,8 +63,25 @@ func looksLikeRepo(p string) bool {
return
true
}
func
forCI
(
r
*
http
.
Request
)
string
{
u
,
_
,
ok
:=
r
.
BasicAuth
()
if
ok
&&
u
==
"gitlab-ci-token"
{
return
"1"
}
else
{
return
"0"
}
}
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
...
...
internal/helper/logging.go
View file @
32b3fa9f
...
...
@@ -7,7 +7,6 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
...
...
@@ -28,22 +27,6 @@ var (
},
[]
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"
},
)
cloneFetchBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_git_clone_fetch_bytes"
,
Help
:
"How many Git clone/fetch bytes for CI have been send by gitlab-workhorse, partitioned by CI yes/no status."
,
},
[]
string
{
"ci"
},
)
)
func
init
()
{
...
...
@@ -58,8 +41,6 @@ func SetCustomResponseLogger(writer io.Writer) {
func
registerPrometheusMetrics
()
{
prometheus
.
MustRegister
(
sessionsActive
)
prometheus
.
MustRegister
(
requestsTotal
)
prometheus
.
MustRegister
(
cloneFetchRequests
)
prometheus
.
MustRegister
(
cloneFetchBytes
)
}
type
LoggingResponseWriter
struct
{
...
...
@@ -107,25 +88,10 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
l
.
status
,
l
.
written
,
r
.
Referer
(),
r
.
UserAgent
(),
duration
.
Seconds
(),
)
l
.
countCloneFetchRequests
(
r
)
sessionsActive
.
Dec
()
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
()
cloneFetchBytes
.
WithLabelValues
(
forCi
)
.
Add
(
float64
(
l
.
written
))
func
(
l
*
LoggingResponseWriter
)
Size
()
int64
{
return
l
.
written
}
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