31 Commits
Author SHA1 Message Date
Ronak Nathani d7ba03a966 Improves leader election so that we don't lose events (#153)
Currently, when a replica loses its leadership, a new leader isn't elected until leaseDuration seconds.
Here, that is 15s. The max time till we get a new leader is leaseDuration (15s) + retryPeriod (2s) = 17s.

This commit updates the shutdown process such that if the leader replica is sent a shutdown signal,
it sleeps for leaseDuration seconds. This allows the leader replica to continue to export events until
a new leader is elected. And a new leader is elected only if lease hasn't been renewed and leaseDuration expires.

In addition to this, leader election now uses the leases object instead of configMaps and leases. The clusterRole
is also updated to allow writing to the leases object.

For use cases where no event loss is tolerable, users should use maxEventAgeSeconds to > 1.
2024-02-23 08:26:06 +03:00
Ronak Nathani f48d5bf9ba Add owner references to EnhancedEvent, consolidate calls to apiserver, make cache size configurable and add metrics for reads (#144)
* Adds ownerReferences to the exported events

This commit uses the same approach as labels and annotations and adds ownerReferences to the EnhancedEvent struct.
The flow is as follows:
* use an LRU cache to store the ownerReferences with object UID as the key
* if the object doesn't exist in cache, look up using dynamic client and store it in cache
* if the object exists in cache, return the value from cache

* Reduce the number of GetObject calls by using a single cache to store all labels, annotations and ownerReferences

Currently, every time there's an event, the events exporter runs GetObject for metadata like labels and annotations
independently. This results in the same object being looked up multiple times for different pieces of the metadata.
These number of calls grow as we want to look up additional information about the object like ownerReferences.
So, in this change, a struct called `ObjectMetadata` is created to capture all the pieces of information that need to be added
to the EnhancedEvent. And every time there's an event, the object is fetched from the kube-apiserver if it's not in the cache already
and all pieces of metadata require only 1 call. The metadata is cached so repeated events about the same object don't
result in more calls.

Additionally, UID + ResourceVersion is used the cacheKey so if the object changes, it's looked up again.

One more change here is introduction of a `deleted` field in the `EnhancedEvent.InvolvedObject` to capture whether the object
is deleted. This helps receivers identify whether a resource is deleted and create rules for it when needed.

Tests are added for these updates and the mock functions are moved to the test files.

* Make the cache size configurable

* Add metrics for number of reads served from cache and kube-apiserver respectively

* Add `deleted` field to the involvedObject in EnhancedEvent to identify whether the resource is being deleted
2023-11-18 01:00:27 +03:00
Boris Petersen bbcbeeb385 Introduce omitLookup config flag (#115)
This flag wraps the Label and Annotation lookup to prevent API
throttling

Signed-off-by: Boris Petersen <boris.petersen@dkb.de>
2023-08-04 19:48:46 +03:00
Hoshea Jiang 90a96d8721 Support setting the kubeconfig via flag and env variable (#42)
* Support setting the kubeconfig via configuration

* support KUBECONFIG env variable and flag
2023-07-21 10:14:15 +03:00
Mustafa Akın ae366454e3 Revert "@timestamp handling from https://github.com/opsgenie/kubernetes-event-exporter/pull/165 (#92)" (#102)
This reverts commit c572daa48a.
2023-07-06 21:15:09 +03:00
Juha Ylitalo c572daa48a @timestamp handling from https://github.com/opsgenie/kubernetes-event-exporter/pull/165 (#92) 2023-07-06 21:14:15 +03:00
Juha Ylitalo e1070dc954 "io/ioutil" has been deprecated (#85)
As of Go 1.16, the same functionality is now provided by package io or package os
2023-07-06 18:36:15 +03:00
Biriukov Sergei 9aa12cfe43 consolidate metrics code in a single package, add metrics prefix config option (#55) 2023-03-17 09:29:05 +03:00
Biriukov Sergei 858089f2dc Add more visibility for dropped events (#37)
* add warn for when event is discarded

* add events discarded metrics

* drop event onUpdate subscription

* rename ThrottlePeriod -> MaxEventAgeSeconds

* update readme to match new name of config var

* add explicit go arch

* gofmt

* add config tests

* revert accidental change to dockerfile

* add tests for event MaxEventAgeSeconds

* add tests for event discarded to onEvent function

* Use custom role with wider read permissions (#2)

* use longer time intervals for more stable tests on slower ci

* fix failing config test
2022-12-19 17:18:47 +03:00
Mustafa Akın f9335bda24 Updated packages, tidied and changed package name from opsgenie to resmoio (#45)
* Updated packages, tidied and changed package name from opsgenie to resmoio

* Handle removal of clusterName from API and leader election api change

* Update Dockerfile Go to 1.19

* Test case for parsing minCount properly for #43

* more extensive test case to also match apiVersion config
2022-12-19 10:45:46 +03:00
Brian McQueen b79cc20ecd added initial set of prometheus metrics per ticket #4 exposing basic success and error rates (#15) 2022-09-15 11:09:30 +03:00
Mustafa Akın 2bb8c7c357 Merge pull request #3 from fpants/clustername
added support for optional clusterName via config file
2022-07-20 00:21:42 +03:00
Mustafa Akın a7f6c0fa4a Merge branch 'avoid_error_logging_crd' 2022-07-03 22:04:10 +03:00
lob 8915de4a2b fix: GetTimestampMs handles different event timestamp
Signed-off-by: lob <pengyu@pingcap.com>
2022-04-16 17:59:17 +08:00
Brian McQueen 3559ed4c08 added support for optional clusterName via config file, since emitted events need a clustername when multiple clusters are in service 2021-12-01 15:15:47 -08:00
Angelo Poerio 0399a29638 avoid logging at the error level the errors involving CRD, but do it anyway at debug level 2021-11-30 12:57:01 +01:00
Mustafa Akın 5d9d82e7dc remove managed fields from event becasue its useless 2021-11-06 13:54:58 +03:00
Mustafa Akın b3e76c60bd vendor update 2021-11-06 12:56:49 +03:00
mustafaakin-atl 13119e5d33 Merge pull request #141 from omauger/master
Support SASL connection for Kafka and add function to get time format ISO8601
2021-11-06 12:19:14 +03:00
Mauger Ophélie 0782a2df63 Add ThrottlePeriod param to give possibility to choose period for evicted event 2021-08-31 17:01:26 +02:00
omauger e1fcecab73 Add function to have time in ISO8601 format 2021-08-26 14:23:04 +02:00
Mustafa Akın 30e4027760 modify lasttime stamp to 5 seconds 2021-06-16 22:47:51 +03:00
Kirill Buev f50b41b9dd Do not ignore events created more than 5 seconds ago (#98)
* Filter events by LastTimestamp instead of CreationTimestamp

* Ignore events fired more than 1 minute ago
2021-06-16 22:47:24 +03:00
Christoph Petrausch 08ed16bc0f Add a DeDot function to the EnhancedObject to replace dots
This replaces all dots in the labels and annotations of the enhancedObject.

Fixes #109
2021-03-08 16:48:04 +01:00
Mustafa Akin 077bb6654c Namespace support to work without cluster scope, fixes #42 2020-06-22 18:28:11 +03:00
Mustafa Akin fee89514e8 better default config to log to stdout, debug log added for involved object capturing 2020-06-22 18:17:18 +03:00
youyongsong 5dca26ee8c feature: support leader election
leader election function is disabled by default, and could be enabled by adding the
following section in `config.yaml`:

```yaml
leaderElection:
  enabled: true
  leaderElectionID: kubernetes-event-exporter  // this field can be omited, default value is kubernetes-event-exporter
```
2020-04-14 19:35:23 +08:00
aseker 208a261d93 Annotations added to involved object 2020-01-10 15:58:05 +03:00
Mustafa Akin b78cf2d997 Add Slack, SQS, SNS outputs. Batching skeleton is implemented but not used in sinks 2019-12-01 16:26:31 +03:00
Mustafa Akin c4726c1a72 Opsgenie output is added, some minor fixes 2019-11-21 10:30:33 -08:00
Mustafa Akin 1fc04d5570 Initial commit, working tests 2019-10-29 00:03:31 +03:00