Skip to content

Commit

Permalink
feat: add dedot option to stdout and pipe sinks (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redlinkk authored Mar 17, 2023
1 parent 9aa12cf commit 3355305
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# kubernetes-event-exporter

> **Note**: This is an active fork of [Opsgenie Kubernetes Event Exporter](https://github.com/opsgenie/kubernetes-event-exporter)
> **Note**: This is an active fork of [Opsgenie Kubernetes Event Exporter](https://github.com/opsgenie/kubernetes-event-exporter)
since that is not maintained since November 2021. Development is sponsored by [Resmo](https://www.resmo.com).

> This tool is presented at [KubeCon 2019 San Diego](https://kccncna19.sched.com/event/6aa61eca397e4ff2bdbb2845e5aebb81).
Expand Down Expand Up @@ -65,14 +65,14 @@ receivers:

## Troubleshoot "Events Discarded" warning:

- If there are `client-side throttling` warnings in the event-exporter log:
Adjust the following values in configuration:
- If there are `client-side throttling` warnings in the event-exporter log:
Adjust the following values in configuration:
```
kubeQPS: 100
kubeBurst: 500
```
> `Burst` to roughly match your events per minute
> `QPS` to be 1/5 of the burst
> `Burst` to roughly match your events per minute
> `QPS` to be 1/5 of the burst
- If there is no request throttling, but events are still dropped:
Consider increasing events cut off age
```
Expand Down Expand Up @@ -152,7 +152,7 @@ receivers:
tls: # optional, advanced options for tls
insecureSkipVerify: true|false # optional, if set to true, the tls cert won't be verified
serverName: # optional, the domain, the certificate was issued for, in case it doesn't match the hostname used for the connection
caFile: # optional, path to the CA file of the trusted authority the cert was signed with
caFile: # optional, path to the CA file of the trusted authority the cert was signed with
```
### OpenSearch
Expand Down Expand Up @@ -183,7 +183,7 @@ receivers:
tls: # optional, advanced options for tls
insecureSkipVerify: true|false # optional, if set to true, the tls cert won't be verified
serverName: # optional, the domain, the certificate was issued for, in case it doesn't match the hostname used for the connection
caFile: # optional, path to the CA file of the trusted authority the cert was signed with
caFile: # optional, path to the CA file of the trusted authority the cert was signed with
```
### Slack
Expand Down Expand Up @@ -298,7 +298,8 @@ route:
- receiver: "dump"
receivers:
- name: "dump"
stdout: { }
stdout:
deDot: true|false
```

### Kafka
Expand Down Expand Up @@ -470,6 +471,7 @@ receivers:
- name: "my_pipe"
pipe:
path: "/dev/stdout"
deDot: true|false
```

# AWS EventBridge
Expand Down
15 changes: 11 additions & 4 deletions pkg/sinks/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

type PipeConfig struct {
Path string `yaml:"path"`
// DeDot all labels and annotations in the event. For both the event and the involvedObject
DeDot bool `yaml:"deDot"`
Layout map[string]interface{} `yaml:"layout"`
}

Expand All @@ -21,7 +23,7 @@ func (f *PipeConfig) Validate() error {
type Pipe struct {
writer io.WriteCloser
encoder *json.Encoder
layout map[string]interface{}
cfg *PipeConfig
}

func NewPipeSink(config *PipeConfig) (*Pipe, error) {
Expand All @@ -33,7 +35,7 @@ func NewPipeSink(config *PipeConfig) (*Pipe, error) {
return &Pipe{
writer: f,
encoder: json.NewEncoder(f),
layout: config.Layout,
cfg: config,
}, nil
}

Expand All @@ -42,11 +44,16 @@ func (f *Pipe) Close() {
}

func (f *Pipe) Send(ctx context.Context, ev *kube.EnhancedEvent) error {
if f.layout == nil {
if f.cfg.DeDot {
de := ev.DeDot()
ev = &de
}

if f.cfg.Layout == nil {
return f.encoder.Encode(ev)
}

res, err := convertLayoutTemplate(f.layout, ev)
res, err := convertLayoutTemplate(f.cfg.Layout, ev)
if err != nil {
return err
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/sinks/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

type StdoutConfig struct {
// DeDot all labels and annotations in the event. For both the event and the involvedObject
DeDot bool `yaml:"deDot"`
Layout map[string]interface{} `yaml:"layout"`
}

Expand All @@ -21,7 +23,7 @@ func (f *StdoutConfig) Validate() error {
type Stdout struct {
writer io.Writer
encoder *json.Encoder
layout map[string]interface{}
cfg *StdoutConfig
}

func NewStdoutSink(config *StdoutConfig) (*Stdout, error) {
Expand All @@ -31,7 +33,7 @@ func NewStdoutSink(config *StdoutConfig) (*Stdout, error) {
return &Stdout{
writer: writer,
encoder: json.NewEncoder(writer),
layout: config.Layout,
cfg: config,
}, nil
}

Expand All @@ -40,11 +42,16 @@ func (f *Stdout) Close() {
}

func (f *Stdout) Send(ctx context.Context, ev *kube.EnhancedEvent) error {
if f.layout == nil {
if f.cfg.DeDot {
de := ev.DeDot()
ev = &de
}

if f.cfg.Layout == nil {
return f.encoder.Encode(ev)
}

res, err := convertLayoutTemplate(f.layout, ev)
res, err := convertLayoutTemplate(f.cfg.Layout, ev)
if err != nil {
return err
}
Expand Down

0 comments on commit 3355305

Please sign in to comment.