mirror of
https://github.com/resmoio/kubernetes-event-exporter.git
synced 2026-08-19 14:56:27 +00:00
I known File Sink is currently mostly used in local development, but we also tend to use it in our production environment with fluentd, because this combination is very stable and reliable.
Currently File Sink lacks the file rolling function, which is very important for the production environment. So I want to add file rolling function to File Sink through this pr without breaking changes.
file rolling is disabled by default, and can be enabled by adding the following arguments:
```yaml
- receivers:
file:
path: ./test.log
maxsize: 20 // if ./test.log is larger than 20MB, it will be renamed to ./test-<datetime>.log as a backup file,
and create a new file named test.log to receive events. It defaults to 100 megabytes.
maxage: 20 // if backup files ./test-<datetime>.log are created 20 days ago, they will be deleted. The default
is not to remove old log files based on age.
maxbackups: 3 // if backup files are more than 3, older backup files will be removed.
```
the rolling function is powered by [lumberjack](https://github.com/natefinch/lumberjack). Becasue `lumberjack.Logger` implmented `io.WriteCloser` interface, so it is easy to replace `file *os.file` with `writer &lumberjack.Logger`.
run kubernetes-event-exporter with following config:
```yaml
logLevel: debug
route:
match:
- receiver: "file"
receivers:
- name: "file"
file:
path: "./event.log"
maxsize: 1
maxbackups: 4
```
run following script to generate events and output `./event*.log` status:
```shell
while true
do
kubectl run nginx --image nginx || kubectl delete deployment nginx
ls -lh event*.log
sleep 2
done
```
the result is:
```
deployment.apps "nginx" deleted
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:03 event-2020-03-04T10-03-30.271.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:15 event-2020-03-04T10-15-52.496.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:28 event-2020-03-04T10-28-27.334.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:41 event-2020-03-04T10-41-11.316.log
-rw-r--r-- 1 ysyou staff 1023K Mar 4 18:54 event.log
deployment.apps/nginx created
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:15 event-2020-03-04T10-15-52.496.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:28 event-2020-03-04T10-28-27.334.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:41 event-2020-03-04T10-41-11.316.log
-rw-r--r-- 1 ysyou staff 1.0M Mar 4 18:54 event-2020-03-04T10-54-11.451.log
-rw-r--r-- 1 ysyou staff 2.0K Mar 4 18:54 event.log
```
when `event.log` reaches 1M, it is renamed to `event-2020-03-04T10-54-11.451.log`, because backup files are more than 4, the oldest one `event-2020-03-04T10-03-30.271.log` is deleted.
46 lines
1.9 KiB
AMPL
46 lines
1.9 KiB
AMPL
module github.com/opsgenie/kubernetes-event-exporter
|
|
|
|
go 1.14
|
|
|
|
require (
|
|
cloud.google.com/go v0.38.0
|
|
github.com/Masterminds/goutils v1.1.0 // indirect
|
|
github.com/Masterminds/semver v1.5.0 // indirect
|
|
github.com/Masterminds/sprig v2.22.0+incompatible
|
|
github.com/Shopify/sarama v1.24.1
|
|
github.com/aws/aws-sdk-go v1.30.10
|
|
github.com/elastic/go-elasticsearch/v7 v7.4.1
|
|
github.com/gogo/protobuf v1.3.0 // indirect
|
|
github.com/googleapis/gax-go v2.0.2+incompatible // indirect
|
|
github.com/googleapis/gnostic v0.3.1 // indirect
|
|
github.com/gorilla/websocket v1.4.1 // indirect
|
|
github.com/hashicorp/golang-lru v0.5.3
|
|
github.com/huandu/xstrings v1.2.0 // indirect
|
|
github.com/imdario/mergo v0.3.8 // indirect
|
|
github.com/json-iterator/go v1.1.7 // indirect
|
|
github.com/klauspost/cpuid v1.2.3 // indirect
|
|
github.com/mitchellh/copystructure v1.0.0 // indirect
|
|
github.com/nlopes/slack v0.6.0
|
|
github.com/opsgenie/opsgenie-go-sdk-v2 v1.0.3
|
|
github.com/rs/zerolog v1.16.0
|
|
github.com/spf13/pflag v1.0.5 // indirect
|
|
github.com/stretchr/objx v0.2.0 // indirect
|
|
github.com/stretchr/testify v1.5.1
|
|
go.opencensus.io v0.22.3 // indirect
|
|
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf // indirect
|
|
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c // indirect
|
|
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
|
|
google.golang.org/api v0.15.0 // indirect
|
|
google.golang.org/genproto v0.0.0-20200128133413-58ce757ed39b // indirect
|
|
google.golang.org/grpc v1.27.0 // indirect
|
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
|
gopkg.in/yaml.v2 v2.2.7
|
|
k8s.io/api v0.0.0-20190819141258-3544db3b9e44
|
|
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d
|
|
k8s.io/client-go v0.0.0-20190819141724-e14f31a72a77
|
|
k8s.io/klog v1.0.0 // indirect
|
|
k8s.io/utils v0.0.0-20190923111123-69764acb6e8e // indirect
|
|
)
|