Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
044e189
Introduce KubernetesResource interface
ruromero Apr 14, 2020
1d05f23
Rename and move KubernetesObject
ruromero Apr 20, 2020
74fc5b0
:bug: cannot specify ControlPlane in envtest.Environment
dmvolod Apr 25, 2020
32b4434
:sparkles: Manager: Export defaultNewClient
alvaroaleman Apr 27, 2020
77de589
Merge pull request #930 from alvaroaleman/export-default-new-client
k8s-ci-robot Apr 27, 2020
fe0e759
Merge pull request #929 from dmvolod/issue-875
k8s-ci-robot Apr 27, 2020
fa1f7f8
Reset resource version if fake client Create call failed
muvaf Apr 22, 2020
ea2e6b1
Rename to Object
ruromero May 6, 2020
c8e2053
:running: Remove unsed Config attribute from controller
alvaroaleman May 6, 2020
eec4f74
Merge pull request #938 from alvaroaleman/remove-config-from-controlller
k8s-ci-robot May 7, 2020
c2dfe1a
Merge pull request #919 from muvaf/fixfake
k8s-ci-robot May 9, 2020
33c7bf8
✨ Controller: Let sources sync even if they use a different cluster
alvaroaleman May 10, 2020
16f7321
Add webhook total and in-flight metrics
boekkooi-fresh May 12, 2020
96e2b22
Initialize the most likely HTTP status codes.
boekkooi-fresh May 12, 2020
ca25c1f
Merge pull request #941 from alvaroaleman/syncing-source
k8s-ci-robot May 12, 2020
da2a49b
:running: Remove unused attributes from controller
alvaroaleman May 9, 2020
374972f
Do not include "code" for latency
boekkooi-fresh May 13, 2020
a4b50a4
Prevent errors to be logged multiple times in builtins example
ialidzhikov May 18, 2020
934bda8
Merge pull request #898 from ruromero/k8sresource
k8s-ci-robot May 20, 2020
c451e69
Fix scheme used by `DeleteAllOf` in the fake client.
Random-Liu May 20, 2020
aac7ac5
Merge pull request #954 from Random-Liu/fix-delete-all-of
k8s-ci-robot May 20, 2020
a2d55b5
Merge pull request #953 from ialidzhikov/fix/double-logging
k8s-ci-robot May 21, 2020
6fc3892
doc: provide example of client.Patch
knight42 May 17, 2020
b999e72
:sparkles: Add ContainsFinalizer helper to the controllerutil
dmvolod Apr 23, 2020
2f1457b
Merge pull request #922 from dmvolod/issue-920
k8s-ci-robot May 22, 2020
0222c26
:sparkles: Migrate controllerutil AddFinalizer and RemoveFinalizer to…
dmvolod May 23, 2020
4c7b43a
Merge pull request #962 from dmvolod/issue-959
k8s-ci-robot May 25, 2020
0d35799
fix(dependency) Use github.com/fsnotify/fsnotify instead of deprecate…
holyhope May 27, 2020
676c350
Merge pull request #968 from holyhope/fix/fsnotify-dependency
k8s-ci-robot May 28, 2020
8c6919c
:sparkles: Add Patch MergeFrom optimistic locking option
vincepri May 27, 2020
f66de86
Merge pull request #969 from vincepri/add-optimistic-locking
k8s-ci-robot May 29, 2020
4257573
Merge pull request #951 from knight42/update-client-example
k8s-ci-robot Jun 1, 2020
4c3fca1
Always shutdown etcd when stopping envtest
akutz Jun 1, 2020
b66bbb4
Merge pull request #975 from akutz/bugfix/envtest-shutdown-order
k8s-ci-robot Jun 1, 2020
587ca7c
Merge pull request #944 from boekkooi-fresh/webhook-metrics
k8s-ci-robot Jun 1, 2020
1423c04
Nit: improve doc string
ialidzhikov Jun 9, 2020
eb68324
Merge pull request #987 from ialidzhikov/nit/comment
k8s-ci-robot Jun 9, 2020
5362611
Merge pull request #940 from alvaroaleman/simplify-3
k8s-ci-robot Jun 12, 2020
8707dc8
Move pwittrock from emeritus approvers to approvers
pwittrock Jun 16, 2020
c4893e0
Merge pull request #997 from pwittrock/master
k8s-ci-robot Jun 16, 2020
526dfa4
:running: Clarify log line in apiutil.GVKForObject
vincepri Jun 19, 2020
41e80ea
[0.6] Update go.mod dependencies patch versions (v0.18.4)
vincepri Jun 19, 2020
b28b798
Merge pull request #1010 from vincepri/update-06-deps
k8s-ci-robot Jun 19, 2020
5693894
Cleanup controller internal logger
vincepri Jun 19, 2020
bb96678
Merge pull request #1003 from vincepri/cleanup-logger
k8s-ci-robot Jun 19, 2020
6954fa5
Update json-patch to e83c0a1c26c8
vincepri Jun 19, 2020
0534547
Merge pull request #1008 from vincepri/fix-log-gvk
k8s-ci-robot Jun 21, 2020
4836ec2
Merge pull request #985 from vincepri/updatejsonpatch5
k8s-ci-robot Jun 21, 2020
5db0b9d
:bug: Fix webhook example
msiebuhr Jun 23, 2020
add0b64
Merge pull request #1016 from msiebuhr/fix-webhook-example
k8s-ci-robot Jun 23, 2020
6febc12
feat:remove the whitelist word from our codebase
tanjunchen Jul 9, 2020
04f2831
Merge pull request #1037 from tanjunchen/remove-whitelisted
k8s-ci-robot Jul 9, 2020
0438a9c
feat:Remove master word from our codebase
tanjunchen Jul 9, 2020
ea795f6
Merge pull request #1038 from tanjunchen/remove-master
k8s-ci-robot Jul 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add webhook total and in-flight metrics
Add a gauge for requests currently being handled and a counter for the total amount of requests processed.

Used [prometheus/promhttp](https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/promhttp?tab=doc) package which provides nice decorators for `Http.Handler` to handle the metrics instead of the custom code.
  • Loading branch information
boekkooi-fresh committed May 12, 2020
commit 16f73213e2983c485a0a93d0f21236268b6834c7
27 changes: 24 additions & 3 deletions pkg/webhook/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,32 @@ var (
Name: "controller_runtime_webhook_latency_seconds",
Help: "Histogram of the latency of processing admission requests",
},
[]string{"webhook"},
[]string{"webhook", "code"},
)

// RequestTotal is a prometheus metric which is a counter of the total processed admission requests.
RequestTotal = func() *prometheus.CounterVec {
return prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "controller_runtime_webhook_requests_total",
Help: "Total number of admission requests by HTTP status code.",
},
[]string{"webhook", "code"},
)
}()

// RequestInFlight is a prometheus metric which is a gauge of the in-flight admission requests.
RequestInFlight = func() *prometheus.GaugeVec {
return prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "controller_runtime_webhook_requests_in_flight",
Help: "Current number of admission requests being served.",
},
[]string{"webhook"},
)
}()
)

func init() {
metrics.Registry.MustRegister(
RequestLatency)
metrics.Registry.MustRegister(RequestLatency, RequestTotal, RequestInFlight)
}
23 changes: 15 additions & 8 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
"path/filepath"
"strconv"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/webhook/internal/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics"
Expand Down Expand Up @@ -123,13 +124,19 @@ func (s *Server) Register(path string, hook http.Handler) {

// instrumentedHook adds some instrumentation on top of the given webhook.
func instrumentedHook(path string, hookRaw http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
startTS := time.Now()
defer func() { metrics.RequestLatency.WithLabelValues(path).Observe(time.Since(startTS).Seconds()) }()
hookRaw.ServeHTTP(resp, req)

// TODO(directxman12): add back in metric about total requests broken down by result?
})
lbl := prometheus.Labels{"webhook": path}

lat := metrics.RequestLatency.MustCurryWith(lbl)
cnt := metrics.RequestTotal.MustCurryWith(lbl)
gge := metrics.RequestInFlight.With(lbl)

return promhttp.InstrumentHandlerDuration(
lat,
promhttp.InstrumentHandlerCounter(
cnt,
promhttp.InstrumentHandlerInFlight(gge, hookRaw),
),
)
}

// Start runs the server.
Expand Down