Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit fef004d

Browse files
authored
Forward Proxy & Certificate Rotation (#325)
- adding prometheus metrics for the forwarding proxy and the certificate rotation
1 parent c878552 commit fef004d

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
FEATURES:
55
* Added a --enable-default-deny option to make denial by default [#PR320](https://github.com/gambol99/keycloak-proxy/pull/320)
6+
* Added metrics latency metrics for the forwarding proxy and the certificate rotation [#PR325](https://github.com/gambol99/keycloak-proxy/pull/325)
67
* Added spelling check to the tests [#PR322](https://github.com/gambol99/keycloak-proxy/pull/322)
78
* Added the X-Auth-Audience to the upstream headers [#PR319](https://github.com/gambol99/keycloak-proxy/pull/319)
89
* Added the ability to control the timeout on the initial openid configuration from .well-known/openid-configuration [#PR315](https://github.com/gambol99/keycloak-proxy/pull/315)

doc.go

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ const (
7575
)
7676

7777
var (
78+
certificateRotationMetric = prometheus.NewCounter(
79+
prometheus.CounterOpts{
80+
Name: "proxy_certificate_rotation_total",
81+
Help: "The total amount of times the certificate has been rotated",
82+
},
83+
)
7884
oauthTokensMetric = prometheus.NewCounterVec(
7985
prometheus.CounterOpts{
8086
Name: "proxy_oauth_tokens_total",

forwarding.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
205205
req.URL.Host = hostname
206206
// is the host being signed?
207207
if len(r.config.ForwardingDomains) == 0 || containsSubString(hostname, r.config.ForwardingDomains) {
208-
req.Header.Set("X-Forwarded-Agent", prog)
209208
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", state.token.Encode()))
209+
req.Header.Set("X-Forwarded-Agent", prog)
210210
}
211211
}
212212
}

rotation.go

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ func (c *certificationRotation) watch() error {
8989
zap.String("filename", event.Name),
9090
zap.Error(err))
9191
}
92+
// @metric inform of the rotation
93+
certificateRotationMetric.Inc()
9294
// step: load the new certificate
9395
c.storeCertificate(certificate)
9496
// step: print a debug message for us

server.go

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func init() {
6666
time.LoadLocation("UTC") // ensure all time is in UTC
6767
runtime.GOMAXPROCS(runtime.NumCPU()) // set the core
6868
// @step: register the instrumentation
69+
prometheus.MustRegister(certificateRotationMetric)
6970
prometheus.MustRegister(latencyMetric)
7071
prometheus.MustRegister(oauthLatencyMetric)
7172
prometheus.MustRegister(oauthTokensMetric)
@@ -308,6 +309,7 @@ func (r *oauthProxy) createForwardingProxy() error {
308309
if resp != nil && r.config.EnableLogging {
309310
start := ctx.UserData.(time.Time)
310311
latency := time.Since(start)
312+
latencyMetric.Observe(latency.Seconds())
311313
r.log.Info("client request",
312314
zap.String("method", resp.Request.Method),
313315
zap.String("path", resp.Request.URL.Path),

0 commit comments

Comments
 (0)