Commit Graph

28 Commits

Author SHA1 Message Date
Patrick Ohly
ebbf7d7dc3 client-go/tools/record: fix and test Broadcaster shutdown + logging
Constructing a Broadcaster already starts a watch which runs in the
background. Shutdown must be called to avoid leaking the goroutine.  Providing
a context was supposed to remove the need to call Shutdown, but that did not
actually work because the logic for "must check for cancellation" was
accidentally inverted.

While at it, structured log output also gets tested together with checking for
goroutine leaks.

Kubernetes-commit: ff779f1cb56cf896405e52f7923188b99b88bb00
2024-04-30 12:16:55 +02:00
Patrick Ohly
3595e5242a k8s.io/client-go/tools: support context for event recording
Using StartRecordingToSinkWithContext instead of StartRecordingToSink and
StartLogging instead of StartStructuredLogging has several advantages:

- Spawned goroutines no longer get stuck for extended periods of
  time during shutdown when passing in a context that gets canceled.
- Log output can be directed towards a specific logger instead of the global
  default, for example one which writes to a testing.T instance.
- The new methods return an error when something went wrong instead of
  merely recording the error.

That last point is the reason for deprecating the old methods instead of merely
adding new alternatives.

Setting a context when constructing an EventBroadcaster makes calling Shutdown
optional. It can also be used to specify the logger.

Both EventRecorder interfaces in tools/events and tools/record now have a
WithLogger helper. Using that method is optional, but recommended to support
contextual logging properly. Without it, errors that occur while emitting an
event are not associated with the caller.

Kubernetes-commit: 27a68aee3a48340f7c14235f7fc24aa69aaeb8f6
2023-09-18 09:13:22 +02:00
HirazawaUi
0a0ddf8b6b generate ReportingInstance and ReportingController in Event
Kubernetes-commit: df0a25382053bb6c0f04fc4d807be6e059b552c1
2023-03-27 22:23:45 +08:00
Patrick Ohly
f6a5a1f139 client-go: don't wait too long after EventBroadcaster.Shutdown
When Shutdown was called, delivery of each pending event would still be retried
12 times with a delay of ~10s between each retry. In apiserver integration
tests that caused the goroutine to linger long after the corresponding
apiserver of the test was shut down.

Kubernetes-commit: 15b01af9c18a0840d71e2bb7dff4d8c29b158aad
2023-02-03 14:52:20 +01:00
Wojciech Tyczyński
a806c6e4fd Remove selflink references in different testing-related files
Kubernetes-commit: 551790729f1d26d75c1d3fa1411e341eb367f9f3
2022-01-13 11:33:26 +01:00
Madhav Jivrajani
721036c908 migrate k8s.io/apimachinery/util/clock -> k8s.io/utils/clock
Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: fed2ec99c652550ed4a8c00b7cfc6c93abbc4ade
2021-09-21 15:53:43 +05:30
Madhav Jivrajani
b9fa896d5d Refactor client-go/util/flowcontrol/throttle.go RateLimiter
- Introduce PassiveRateLimiter which implements all methods of previous RateLimiter except Accept() and Wait()
- Change RateLimiter interface to extend PassiveRateLimiter by additionally implementing Accept() and Wait()
- Make client-go/tools/record use PassiveRateLimiter

Refactor EventSourceObjectSpamFilter, EventAggregator, EventCorrelator

- EventSourceObjectSpamFilter, EventAggregator, EventCorrelator use clock.PassiveClock now.
	- This won't be a breaking change because even if a clock.Clock is passed, it still implements the clock.PassiveClock interface.
- Extend clock.PassiveClock through Clock.
- Replace pacakge local implementation of realClock with clock.RealClock
- In flowcontrol/throttle.go split tokenBucketRateLimiters to use Clock and clock.PassiveClock.
- Migrate client-go/tools/record tests from using IntervalClock to using SimpleIntervalClock (honest implementation of clock.PassiveClock)

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: ac5c55f0bd853fcf883d9b8e1f5ef728a2fb5309
2021-08-25 21:56:26 +05:30
Solly Ross
726d27fe7a Don't record events in goroutines
This changes the event recorder to use the equivalent of a select
statement instead of a goroutine to record events.

Previously, we used a goroutine to make event recording non-blocking.
Unfortunately, this writes to a channel, and during shutdown we then
race to write to a closed channel, panicing (caught by the error
handler, but still) and making the race detector unhappy.

Instead, we now use the select statement to make event emitting
non-blocking, and if we'd block, we just drop the event.  We already
drop events if a particular sink is overloaded, so this just moves the
incoming event queue to match that behavior (and makes the incoming
event queue much longer).

This means that, if the user uses `Eventf` and friends correctly (i.e.
ensure they've returned by the time we call `Shutdown`), it's
now safe to call Shutdown.  This matches the conventional go guidance on
channels: the writer should call close.

Kubernetes-commit: e90e67bd002e70a525d3ee9045b213a5d826074d
2020-10-16 15:05:00 -07:00
Jordan Liggitt
e6a0f4acba Fix int->string casts
Kubernetes-commit: 124a5ddf725c4862520d8619017cac9db7a03522
2020-07-24 11:13:07 -04:00
wojtekt
1bed22dd11 Fix selflinks in events tests
Kubernetes-commit: cfa16959e23e4801847b1722f6cc1c73f26e1c3d
2019-08-01 15:23:49 +02:00
Mikhail Mazurskiy
c90a87409a Cleanup math/rand package usage
Kubernetes-commit: 4ce1fb7d40beb9010e56d60792c4da25e8d86ed0
2018-11-17 16:45:36 +11:00
Lars Lehtonen
f6d2dca1b0 vendor/k8s.io/client-go/tools/record: Fix two swallowed errors in tests
Kubernetes-commit: b64a0a8f5aad2403a55fb3ec035c35702b0b9ab9
2017-09-27 19:43:11 -07:00
Derek Carr
170149c11b Add client side event rate limiting
Kubernetes-commit: b62fa1d72855ef1eb02ec2c908b16b7477feb3b1
2017-09-05 13:48:55 +00:00
Dr. Stefan Schimanski
c5fd4b1202 Move pkg/api/v1/ref -> client-go/tools/reference
Kubernetes-commit: 5925a0a1df1cb8cfbf9d1b4c9aa62d772090ad75
2017-07-28 13:45:48 +00:00
Chao Xu
d82cfb70dd run hack/update-staging-client-go, somehow we copied listers/<authn,authz,imagepolicy>
Kubernetes-commit: ffe74d1fe749b5887711f70af24e1375856f2520
2017-06-28 00:06:44 +00:00
Chao Xu
1e9caa8e14 run root-rewrite-import-client-go-api-types
Kubernetes-commit: f2d3220a11111f86b2f481e70e3c1ca4f5896f44
2017-06-28 00:06:44 +00:00
Clayton Coleman
09165439d7 Refactor move of client-go/util/clock to apimachinery
Kubernetes-commit: 3e095d12b4f152a45b593927804e2e7b8816239a
2017-05-21 17:20:29 +00:00
Chao Xu
7b1f9a193b remove references to client-go/pkg/api
Kubernetes-commit: d978f22e04519f6eecfde839110c398dc28d4e8e
2017-05-03 20:28:31 +00:00
Chao Xu
354468e551 move pkg/api/v1/ref.go and pkg/api/v1/resource.go to subpackages. move some functions in resource.go to pkg/api/v1/node and pkg/api/v1/pod
Kubernetes-commit: 4f9591b1de11bff617c920f89144004669b0f461
2017-04-18 20:28:21 +00:00
Kubernetes Publisher
7ac1236194 published by bot
(https://github.com/kubernetes/test-infra/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is ab794c612853e6c6dfda63594cb5d74914e7e151
2017-02-03 22:09:57 +00:00
Kubernetes Publisher
b766ef93a4 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is a2b65f03bf83013d1af05c99b7aa22049ca63de3
2017-01-31 15:19:42 +00:00
Kubernetes Publisher
fcdf37233b published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is baaaf26609565b4299008018486ec75fb30903eb
2017-01-25 15:19:43 +00:00
Kubernetes Publisher
0eb5431cb7 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 8d5227bb2e05e01031ace81fa6611a13f598278e
2017-01-21 15:19:42 +00:00
Kubernetes Publisher
8fa0506b26 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d9467519245c3858ac58c5fa91ec9e5b16c1f507
2017-01-18 15:19:42 +00:00
Kubernetes Publisher
204f12b1f3 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 616038db1b0d1e852b4a3d10c8c512a052f91fba
2017-01-14 15:19:47 +00:00
Kubernetes Publisher
124670e99d published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 81d788dd6e0748e5d53a62c16d933c5f7a0718af
2016-12-04 11:39:55 +00:00
Kubernetes Publisher
75399f68c8 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is e56cfc5322138aa23e6418ee30a6ab54c7c6fe8c
2016-10-21 04:44:19 +00:00
Chao Xu
a6d206121d remove the top-level folders for versions
remove scripts
2016-10-19 14:34:19 -07:00