Commit Graph

87 Commits

Author SHA1 Message Date
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
Sunil Shivanand
aea98eb150 combine conditional checks
Signed-off-by: Sunil Shivanand <sunil.shivanand@statnett.no>

Kubernetes-commit: 80480f8e21572cba152a4f6f171ebb5de8c6bafb
2023-01-11 09:45:37 +01:00
Sunil Shivanand
0d54cf50db handle event errors caused due to terminating namespaces
Create events are forbidden in terminating namespaces, use info
instead of error to log the failed event.

Signed-off-by: Sunil Shivanand <sunil.shivanand@statnett.no>

Kubernetes-commit: 7a6d58001b7d824f92601fd246b3aad9fbb9c583
2023-01-05 12:56:40 +01:00
HirazawaUi
0a0ddf8b6b generate ReportingInstance and ReportingController in Event
Kubernetes-commit: df0a25382053bb6c0f04fc4d807be6e059b552c1
2023-03-27 22:23:45 +08:00
Tim Hockin
c4339eeca9 Replace uses of ObjectGoPrintDiff with cmp.Diff
ObjectGoPrintDiff is already a shim over cmp.Diff, so no actual output
or behavior changes

Kubernetes-commit: 9627c50ef37f3b5274486e6f5ad37b73b1b69bf0
2023-03-23 11:31:25 -07:00
Lucy Sweet
3a78ee0346 Fix typo
Kubernetes-commit: 247299946bb424407590219729c4f16b073f1e4a
2023-02-21 22:05:02 +01:00
Lucy Sweet
1fc8a8a5a7 Clean up FakeRecorder event emission
Kubernetes-commit: 191fe47b6ca537040b22e56776bb97d3d21737e3
2023-02-21 20:35:54 +01:00
Lucy Sweet
c633a8222b Include annotations all the time
Kubernetes-commit: 8373afef0e0886fcd05a4cbf8b0bedeaa82a4d05
2023-02-21 16:42:37 +01:00
Lucy Sweet
f7f367ebae Respond to review
Kubernetes-commit: 7a48c6e2171d23fea76b7a15ab4971989f125b96
2023-02-21 16:29:38 +01:00
Lucy Sweet
a43f324cb9 Allow inclusion of annotations in channel events when using FakeRecorder
Kubernetes-commit: 9839ce96f557413f522230fa3e374e26356ae3d9
2023-02-17 16:38:10 +01: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
Davanum Srinivas
2a6c116e40 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
bells17
21f4308ca2 Fix typo: type -> eventtype
Kubernetes-commit: 53083ea6aa9817f130b15efaf8ccc2d0c59c4be3
2019-10-21 17:15:44 +09:00
Andrew Stoycos
f19a514ff5 Fix Panic Condition
Currenlty an event recorder can send an event to a
broadcaster that is already stopped, resulting
in a panic.  This ensures the broadcaster holds
a lock while it is shutting down and then forces
any senders to drop queued events following
broadcaster shutdown.

It also updates the Action, ActionOrDrop,  Watch,
and WatchWithPrefix functions to return an error
in the case where data is sent on the closed bradcaster
channel rather than panicing.

Lastly it updates unit tests to ensure the fix works correctly

fixes: https://github.com/kubernetes/kubernetes/issues/108518

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>

Kubernetes-commit: 6aa779f4ed3d3acdad2f2bf17fb27e11e23aabe4
2022-02-11 14:50:19 -05:00
Di Yi
5b56e4a504 resolve casing issue
Kubernetes-commit: 9996c154cba000346db940c90e234265d67dd8a9
2022-01-28 15:50:43 +08:00
Di Yi
93a63158d4 add fieldPath back to event logs
Kubernetes-commit: 94245af8f4a144e0aceb5a4be0d3ae4993e19be7
2022-01-27 14:28:26 +08:00
Wojciech Tyczyński
a806c6e4fd Remove selflink references in different testing-related files
Kubernetes-commit: 551790729f1d26d75c1d3fa1411e341eb367f9f3
2022-01-13 11:33:26 +01:00
Davanum Srinivas
70f09c4943 Check in OWNERS modified by update-yamlfmt.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 9405e9b55ebcd461f161859a698b949ea3bde31d
2021-12-09 21:31:26 -05: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
Aleksandra Gacek
23071d64f0 Allow customizing spam filtering in event client library
Kubernetes-commit: 00080d400fe27f11795b654ad1e124311831a0fc
2021-07-26 16:05:18 +02:00
刁浩 10284789
5b0c7191ef simplify returning boolean expression in staging/src/k8s.io/client-go/tools
Signed-off-by: 刁浩 10284789 <diao.hao@zte.com.cn>

Kubernetes-commit: 9173414da6d1c70436b256d6068e3737a7434f6a
2021-05-24 07:15:36 +00:00
3Xpl0it3r
abc6b41ce3 remove duplicatd description in comment
Kubernetes-commit: 21c15d197348987a572d0048e469ab860f409fa1
2021-04-20 13:44:58 +08:00
Iceber Gu
d39ae5d18d fix typo in comment for EventAggregatorByReasonFunc
Kubernetes-commit: 70d795ff65667eb3f26dc1e9c46bc2a56892350a
2021-04-07 15:06:14 +08:00
wojtekt
4c5ab17317 Add sig-instrumentation approvers to events libraries OWNERS
Kubernetes-commit: 569626109af6d2dd40271efc9da84ea69308fccb
2021-03-05 16:45:20 +01:00
Nikhita Raghunath
1d0cb03f5a *: remove nikhiljindal from OWNERS
Kubernetes-commit: 6cef3a4e33c10c27bb301a1070ea3ff4cdad0c39
2021-02-16 10:50:50 +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
Bryan Boreham
5d2c89de53 Remove unused argument from generateEvent
Kubernetes-commit: beceee68156dff8b10123a37bb4645941b7df0c2
2020-11-17 16:51:10 +00:00
Jordan Liggitt
c476b49dcf Add GC unit tests
Adds unit tests covering the problematic scenarios identified
around conflicting data in child owner references

                      Before   After
package level         51%      68%
garbagecollector.go   60%      75%
graph_builder.go      50%      81%
graph.go              50%      68%

Added/improved coverage of key functions that had lacking unit test coverage:

* attemptToDeleteWorker
* attemptToDeleteItem
* processGraphChanges (added coverage of all added code)

Kubernetes-commit: e491c3bc7056530d82590d95f0af0e8c4d8dded5
2020-10-09 17:50:52 -04:00
Derek Carr
475bc66604 Improve ability to debug Events e2e failure
Kubernetes-commit: 4502fa3cfcd6025ba434f8626102e56d09d95b7e
2020-09-03 15:01:33 -04:00
Jordan Liggitt
e6a0f4acba Fix int->string casts
Kubernetes-commit: 124a5ddf725c4862520d8619017cac9db7a03522
2020-07-24 11:13:07 -04:00
Chelsey Chen
51d7273066 Update conversion between ReportingController and Source.Component
Kubernetes-commit: e010436e2acc96d710620a91ceaaa86becca4060
2020-07-07 13:38:48 -04:00
Benjamin Elder
1a4844dbb1 eparis to emeritus
Kubernetes-commit: 2abc8afececeadad26c6bb90d3b096f2b8008131
2020-06-30 09:50:44 -07:00
Kobayashi Daisuke
b5d4191149 Replace StartLogging(klog.Infof) with StartStructuredLogging(0)
Kubernetes-commit: 4ae11dac2e2cc8594c528a679db5861c0926b514
2020-06-09 12:01:45 +09:00
Kobayashi Daisuke
55768fa31f Add an function for Structured Logging function into EventBroatcaster
Kubernetes-commit: dcaa8d7126cb711b9b93ef10fa84364dac8a22d3
2020-06-09 10:10:41 +09:00
Kobayashi Daisuke
10e6fa29f1 Migrate log to klog.InfoS for staging/src/k8s.io/client-go
Kubernetes-commit: ed1b83c6de5ccc62494e7f0e580cd743ad9a5934
2020-06-03 11:13:54 +09:00
Davanum Srinivas
75fea27a27 switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
Roger Torrentsgeneros
69becbbf29 fix: missing variadic dots
Kubernetes-commit: 9bfcc6144e5ad24ffa2e903f8ee32405cda8d942
2020-01-30 13:08:14 +01:00
mattjmcnaughton
3ada5c0eb8 Remove recorder.PastEventf method
The `recorder.PastEventf` method wasn't actually working as advertised.
It was supposed to accept a timestamp, which would be used when
generating the event. However, as the
[source code](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/tools/record/event.go#L316)
shows, this `timestamp` was never actually used.

In other words, `PastEventf` is identical to `Eventf`.

We have two options: one would be to fix `PastEventf` so that it works
as advertised. The other would be to delete `PastEventf` and only
support `Eventf`.

Ultimately, I could only find one use of `PastEventf` in the code base,
so I propose we just delete `PastEventf` and convert all uses to
`Eventf`.

Kubernetes-commit: 92940fa80d67593c7a2333267da4424c8b45ac88
2019-12-30 11:55:47 -05:00
Luke Shumaker
f5d68cde58 client-go/tools: Docs: Clarify what's "old" core/v1 and what's "new" events/v1beta1
Kubernetes-commit: 2c4bb0fa4db88462a61995d9179fad801b00d69d
2019-11-12 08:30:24 -05:00
Yassine TIJANI
6cdcb13531 add a fallback for kube-scheduler when events.k8s.io is disabled
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>

Kubernetes-commit: f970b3413779ef817d2a374847bc0a4cb733a9a0
2019-10-09 20:14:29 +02:00
Ted Yu
9be50f2e07 Use consistent short name for receivers
Kubernetes-commit: 21b11c2b6434f949299f85a12c535bfd169c2cf3
2019-10-08 09:08:52 -07:00
Ted Yu
c4ea3eed4f Expose Shutdown func for EventBroadcaster
Kubernetes-commit: 57d43e4946f352f075b219b0a2f35942b06cfeb9
2019-10-07 08:58:38 -07: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
vivekbagade
060f7d3455 Added config to EventCorrelator in client-go
Added CorrelatorOptions that contains options to change the
defaults in EventSourceObjectSpamFilter and EventAggregator
in EventCorrelator. Added a eventCorrelator property to the
eventBroadcasterImpl to help with this.

Kubernetes-commit: 9d8e6fb1b9cf2d3fac8139a97334287e33ff911f
2019-03-07 10:39:49 +01:00
Justin SB
931e6a04ad Remove executable file permission from OWNERS files
Kubernetes-commit: dd19b923b7c26420af39fcf4eedfa213b236c8d3
2019-01-03 12:18:20 -05:00
Roy Lenferink
94093d2527 Updated OWNERS files to include link to docs
Kubernetes-commit: b43c04452f3b563473b5c2a765d4ac18cc0ff58f
2019-01-30 20:05:00 +01:00
Yassine TIJANI
60920bb9e4 refactor util functions for event recording
Kubernetes-commit: 7296288928d347dfb1dcb990d779cdfce96ead1b
2019-01-18 15:28:37 +01:00
Davanum Srinivas
74cd8bbeee Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135

Kubernetes-commit: 954996e231074dc7429f7be1256a579bedd8344c
2018-11-09 13:49:10 -05:00