Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
Commits
a2d49902
Commit
a2d49902
authored
Dec 03, 2021
by
Catalin Irimie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Workhorse metrics for secondary proxy requests
Changelog: added EE: true
parent
6bd1a6f6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
6 deletions
+86
-6
workhorse/internal/upstream/metrics.go
workhorse/internal/upstream/metrics.go
+14
-0
workhorse/internal/upstream/metrics_test.go
workhorse/internal/upstream/metrics_test.go
+54
-0
workhorse/internal/upstream/routes.go
workhorse/internal/upstream/routes.go
+17
-5
workhorse/internal/upstream/upstream.go
workhorse/internal/upstream/upstream.go
+1
-1
No files found.
workhorse/internal/upstream/metrics.go
View file @
a2d49902
...
...
@@ -101,6 +101,16 @@ var (
},
[]
string
{
"code"
,
"method"
,
"route"
},
)
httpGeoProxiedRequestsTotal
=
promauto
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Subsystem
:
httpSubsystem
,
Name
:
"geo_proxied_requests_total"
,
Help
:
"A counter for Geo proxied requests through workhorse."
,
},
[]
string
{
"code"
,
"method"
,
"route"
},
)
)
func
instrumentRoute
(
next
http
.
Handler
,
method
string
,
regexpStr
string
)
http
.
Handler
{
...
...
@@ -115,3 +125,7 @@ func instrumentRoute(next http.Handler, method string, regexpStr string) http.Ha
return
handler
}
func
instrumentGeoProxyRoute
(
next
http
.
Handler
,
method
string
,
regexpStr
string
)
http
.
Handler
{
return
promhttp
.
InstrumentHandlerCounter
(
httpGeoProxiedRequestsTotal
.
MustCurryWith
(
map
[
string
]
string
{
"route"
:
regexpStr
}),
next
)
}
workhorse/internal/upstream/metrics_test.go
0 → 100644
View file @
a2d49902
package
upstream
import
(
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/config"
)
func
TestInstrumentGeoProxyRoute
(
t
*
testing
.
T
)
{
const
(
remote
=
`\A/remote\z`
local
=
`\A/local\z`
main
=
""
)
u
:=
newUpstream
(
config
.
Config
{},
logrus
.
StandardLogger
(),
func
(
u
*
upstream
)
{
u
.
Routes
=
[]
routeEntry
{
handleRouteWithMatchers
(
u
,
remote
,
withGeoProxy
()),
handleRouteWithMatchers
(
u
,
local
),
handleRouteWithMatchers
(
u
,
main
),
}
})
ts
:=
httptest
.
NewServer
(
u
)
defer
ts
.
Close
()
testCases
:=
[]
testCase
{
{
"remote"
,
"/remote"
,
remote
},
{
"local"
,
"/local"
,
local
},
{
"main"
,
"/"
,
main
},
}
httpGeoProxiedRequestsTotal
.
Reset
()
runTestCases
(
t
,
ts
,
testCases
)
require
.
Equal
(
t
,
1
,
testutil
.
CollectAndCount
(
httpGeoProxiedRequestsTotal
))
require
.
InDelta
(
t
,
1
,
testutil
.
ToFloat64
(
httpGeoProxiedRequestsTotal
.
WithLabelValues
(
"200"
,
"get"
,
remote
)),
0.1
)
require
.
InDelta
(
t
,
0
,
testutil
.
ToFloat64
(
httpGeoProxiedRequestsTotal
.
WithLabelValues
(
"200"
,
"get"
,
local
)),
0.1
)
require
.
InDelta
(
t
,
0
,
testutil
.
ToFloat64
(
httpGeoProxiedRequestsTotal
.
WithLabelValues
(
"200"
,
"get"
,
main
)),
0.1
)
}
func
handleRouteWithMatchers
(
u
*
upstream
,
regex
string
,
matchers
...
func
(
*
routeOptions
))
routeEntry
{
handler
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
io
.
WriteString
(
w
,
regex
)
})
return
u
.
route
(
""
,
regex
,
handler
,
matchers
...
)
}
workhorse/internal/upstream/routes.go
View file @
a2d49902
...
...
@@ -43,6 +43,7 @@ type routeEntry struct {
type
routeOptions
struct
{
tracing
bool
isGeoProxyRoute
bool
matchers
[]
matcherFunc
}
...
...
@@ -94,7 +95,13 @@ func withoutTracing() func(*routeOptions) {
}
}
func
(
u
*
upstream
)
observabilityMiddlewares
(
handler
http
.
Handler
,
method
string
,
regexpStr
string
)
http
.
Handler
{
func
withGeoProxy
()
func
(
*
routeOptions
)
{
return
func
(
options
*
routeOptions
)
{
options
.
isGeoProxyRoute
=
true
}
}
func
(
u
*
upstream
)
observabilityMiddlewares
(
handler
http
.
Handler
,
method
string
,
regexpStr
string
,
opts
*
routeOptions
)
http
.
Handler
{
handler
=
log
.
AccessLogger
(
handler
,
log
.
WithAccessLogger
(
u
.
accessLogger
),
...
...
@@ -106,6 +113,11 @@ func (u *upstream) observabilityMiddlewares(handler http.Handler, method string,
)
handler
=
instrumentRoute
(
handler
,
method
,
regexpStr
)
// Add prometheus metrics
if
opts
!=
nil
&&
opts
.
isGeoProxyRoute
{
handler
=
instrumentGeoProxyRoute
(
handler
,
method
,
regexpStr
)
// Add Geo prometheus metrics
}
return
handler
}
...
...
@@ -119,7 +131,7 @@ func (u *upstream) route(method, regexpStr string, handler http.Handler, opts ..
f
(
&
options
)
}
handler
=
u
.
observabilityMiddlewares
(
handler
,
method
,
regexpStr
)
handler
=
u
.
observabilityMiddlewares
(
handler
,
method
,
regexpStr
,
&
options
)
handler
=
denyWebsocket
(
handler
)
// Disallow websockets
if
options
.
tracing
{
// Add distributed tracing
...
...
@@ -136,7 +148,7 @@ func (u *upstream) route(method, regexpStr string, handler http.Handler, opts ..
func
(
u
*
upstream
)
wsRoute
(
regexpStr
string
,
handler
http
.
Handler
,
matchers
...
matcherFunc
)
routeEntry
{
method
:=
"GET"
handler
=
u
.
observabilityMiddlewares
(
handler
,
method
,
regexpStr
)
handler
=
u
.
observabilityMiddlewares
(
handler
,
method
,
regexpStr
,
nil
)
return
routeEntry
{
method
:
method
,
...
...
workhorse/internal/upstream/upstream.go
View file @
a2d49902
...
...
@@ -239,5 +239,5 @@ func (u *upstream) updateGeoProxyFields(geoProxyURL *url.URL) {
geoProxyRoundTripper
:=
roundtripper
.
NewBackendRoundTripper
(
u
.
geoProxyBackend
,
""
,
u
.
ProxyHeadersTimeout
,
u
.
DevelopmentMode
)
geoProxyUpstream
:=
proxypkg
.
NewProxy
(
u
.
geoProxyBackend
,
u
.
Version
,
geoProxyRoundTripper
)
u
.
geoProxyCableRoute
=
u
.
wsRoute
(
`^/-/cable\z`
,
geoProxyUpstream
)
u
.
geoProxyRoute
=
u
.
route
(
""
,
""
,
geoProxyUpstream
)
u
.
geoProxyRoute
=
u
.
route
(
""
,
""
,
geoProxyUpstream
,
withGeoProxy
()
)
}
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