Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6bce120a
Commit
6bce120a
authored
Oct 05, 2017
by
Mik Vyatskov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add throttling to the batching audit webhook
Signed-off-by:
Mik Vyatskov
<
vmik@google.com
>
parent
5f4ff9f2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Godeps.json
staging/src/k8s.io/apiserver/Godeps/Godeps.json
+4
-0
BUILD
staging/src/k8s.io/apiserver/plugin/pkg/audit/webhook/BUILD
+1
-0
webhook.go
.../src/k8s.io/apiserver/plugin/pkg/audit/webhook/webhook.go
+12
-0
No files found.
staging/src/k8s.io/apiserver/Godeps/Godeps.json
View file @
6bce120a
...
...
@@ -1661,6 +1661,10 @@
{
"ImportPath"
:
"k8s.io/client-go/util/cert"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath"
:
"k8s.io/client-go/util/flowcontrol"
,
"Rev"
:
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
staging/src/k8s.io/apiserver/plugin/pkg/audit/webhook/BUILD
View file @
6bce120a
...
...
@@ -42,6 +42,7 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/audit:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/webhook:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/util/flowcontrol:go_default_library",
],
)
...
...
staging/src/k8s.io/apiserver/plugin/pkg/audit/webhook/webhook.go
View file @
6bce120a
...
...
@@ -35,6 +35,7 @@ import (
"k8s.io/apiserver/pkg/audit"
"k8s.io/apiserver/pkg/util/webhook"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
)
const
(
...
...
@@ -63,6 +64,9 @@ const (
defaultBatchMaxSize
=
400
// Only send up to 400 events at a time.
defaultBatchMaxWait
=
30
*
time
.
Second
// Send events at least twice a minute.
defaultInitialBackoff
=
10
*
time
.
Second
// Wait at least 10 seconds before retrying.
defaultBatchThrottleQPS
=
10
// Limit the send rate by 10 QPS.
defaultBatchThrottleBurst
=
15
// Allow up to 15 QPS burst.
)
// The plugin name reported in error metrics.
...
...
@@ -154,6 +158,7 @@ func newBatchWebhook(configFile string, groupVersion schema.GroupVersion) (*batc
maxBatchSize
:
defaultBatchMaxSize
,
maxBatchWait
:
defaultBatchMaxWait
,
shutdownCh
:
make
(
chan
struct
{}),
throttle
:
flowcontrol
.
NewTokenBucketRateLimiter
(
defaultBatchThrottleQPS
,
defaultBatchThrottleBurst
),
},
nil
}
...
...
@@ -181,6 +186,9 @@ type batchBackend struct {
// all requests have been completed and no new will be spawned, since the
// sending routine is not running anymore.
reqMutex
sync
.
RWMutex
// Limits the number of requests sent to the backend per second.
throttle
flowcontrol
.
RateLimiter
}
func
(
b
*
batchBackend
)
Run
(
stopCh
<-
chan
struct
{})
error
{
...
...
@@ -306,6 +314,10 @@ func (b *batchBackend) sendBatchEvents(events []auditinternal.Event) {
list
:=
auditinternal
.
EventList
{
Items
:
events
}
if
b
.
throttle
!=
nil
{
b
.
throttle
.
Accept
()
}
// Locking reqMutex for read will guarantee that the shutdown process will
// block until the goroutine started below is finished. At the same time, it
// will not prevent other batches from being proceed further this point.
...
...
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