Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
better default config to log to stdout, debug log added for involved …
Browse files Browse the repository at this point in the history
…object capturing
  • Loading branch information
mustafaakin committed Jun 22, 2020
1 parent 336fa39 commit fee8951
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.14 AS builder

ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO11MODULE=on go build -mod=vendor -v -a -o /main .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO11MODULE=on go build -mod=vendor -a -o /main .

FROM gcr.io/distroless/base
COPY --from=builder /main /kubernetes-event-exporter
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ SQS is an AWS service for message queuing that allows high throughput messaging.
```yaml
# ...
receivers:
- name: "file"
- name: "sqs"
sqs:
queueName: "/tmp/dump"
region: us-west-2
Expand Down
87 changes: 87 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
logLevel: debug
logFormat: json
route:
# Main route
routes:
# This route allows dumping all events because it has no fields to match and no drop rules.
- match:
- receiver: "dump"
# This starts another route, drops all the events in *test* namespaces and Normal events
# for capturing critical events
- drop:
- namespace: "*test*"
- type: "Normal"
match:
- receiver: "alert"
- receiver: "pipe"
# This a final route for user messages
- match:
- kind: "Pod|Deployment|ReplicaSet"
labels:
version: "dev"
receiver: "slack"
receivers:
- name: "dump"
elasticsearch:
hosts:
- "http://localhost:9200"
indexFormat: "kube-events-{2006-01-02}"
- name: "alert"
opsgenie:
apiKey: ""
priority: "P3"
message: "Event {{ .Reason }} for {{ .InvolvedObject.Namespace }}/{{ .InvolvedObject.Name }} on K8s cluster"
alias: "{{ .UID }}"
description: "<pre>{{ toPrettyJson . }}</pre>"
tags:
- "event"
- "{{ .Reason }}"
- "{{ .InvolvedObject.Kind }}"
- "{{ .InvolvedObject.Name }}"
- name: "slack"
slack:
token: ""
channel: "#mustafa-test"
message: "Received a Kubernetes Event {{ .Message}}"
fields:
message: "{{ .Message }}"
namespace: "{{ .Namespace }}"
reason: "{{ .Reason }}"
object: "{{ .Namespace }}"
- name: "pipe"
webhook:
endpoint: "http://localhost:3000"
headers:
X-API-KEY: "123-456-OPSGENIE-789-ABC"
User-Agent: "kube-event-exporter 1.0"
streamName: "applicationMetric"
layout:
endpoint: "localhost2"
eventType: "kube-event"
createdAt: "{{ .GetTimestampMs }}"
details:
message: "{{ .Message }}"
reason: "{{ .Reason }}"
tip: "{{ .Type }}"
count: "{{ .Count }}"
kind: "{{ .InvolvedObject.Kind }}"
name: "{{ .InvolvedObject.Name }}"
namespace: "{{ .Namespace }}"
component: "{{ .Source.Component }}"
host: "{{ .Source.Host }}"
labels: "{{ toJson .InvolvedObject.Labels}}"
- name: "kafka"
kafka:
topic: "kube-event"
brokers:
- "localhost:9092"
tls:
enable: false
certFile: "kafka-client.crt"
keyFile: "kafka-client.key"
caFile: "kafka-ca.crt"
- name: "pubsub"
pubsub:
gcloud_project_id: "my-project"
topic: "kube-event"
create_topic: False
83 changes: 3 additions & 80 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,87 +1,10 @@
logLevel: debug
logLevel: error
logFormat: json
route:
# Main route
routes:
# This route allows dumping all events because it has no fields to match and no drop rules.
- match:
- receiver: "dump"
# This starts another route, drops all the events in *test* namespaces and Normal events
# for capturing critical events
- drop:
- namespace: "*test*"
- type: "Normal"
match:
- receiver: "alert"
- receiver: "pipe"
# This a final route for user messages
- match:
- kind: "Pod|Deployment|ReplicaSet"
labels:
version: "dev"
receiver: "slack"
receivers:
- name: "dump"
elasticsearch:
hosts:
- "http://localhost:9200"
indexFormat: "kube-events-{2006-01-02}"
- name: "alert"
opsgenie:
apiKey: ""
priority: "P3"
message: "Event {{ .Reason }} for {{ .InvolvedObject.Namespace }}/{{ .InvolvedObject.Name }} on K8s cluster"
alias: "{{ .UID }}"
description: "<pre>{{ toPrettyJson . }}</pre>"
tags:
- "event"
- "{{ .Reason }}"
- "{{ .InvolvedObject.Kind }}"
- "{{ .InvolvedObject.Name }}"
- name: "slack"
slack:
token: ""
channel: "#mustafa-test"
message: "Received a Kubernetes Event {{ .Message}}"
fields:
message: "{{ .Message }}"
namespace: "{{ .Namespace }}"
reason: "{{ .Reason }}"
object: "{{ .Namespace }}"
- name: "pipe"
webhook:
endpoint: "http://localhost:3000"
headers:
X-API-KEY: "123-456-OPSGENIE-789-ABC"
User-Agent: "kube-event-exporter 1.0"
streamName: "applicationMetric"
layout:
endpoint: "localhost2"
eventType: "kube-event"
createdAt: "{{ .GetTimestampMs }}"
details:
message: "{{ .Message }}"
reason: "{{ .Reason }}"
tip: "{{ .Type }}"
count: "{{ .Count }}"
kind: "{{ .InvolvedObject.Kind }}"
name: "{{ .InvolvedObject.Name }}"
namespace: "{{ .Namespace }}"
component: "{{ .Source.Component }}"
host: "{{ .Source.Host }}"
labels: "{{ toJson .InvolvedObject.Labels}}"
- name: "kafka"
kafka:
topic: "kube-event"
brokers:
- "localhost:9092"
tls:
enable: false
certFile: "kafka-client.crt"
keyFile: "kafka-client.key"
caFile: "kafka-ca.crt"
- name: "pubsub"
pubsub:
gcloud_project_id: "my-project"
topic: "kube-event"
create_topic: False
file:
path: "/tmp/deneme1"
13 changes: 7 additions & 6 deletions deploy/01-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
namespace: monitoring
data:
config.yaml: |
logLevel: error
logFormat: json
route:
match:
- receiver: "dump"
routes:
- match:
- receiver: "dump"
receivers:
- name: "dump"
elasticsearch:
hosts:
- http://elasticsearch.monitoring.svc.cluster.local:9200
index: kube-events
file:
path: "/dev/stdout"
2 changes: 1 addition & 1 deletion deploy/02-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
serviceAccountName: event-exporter
containers:
- name: event-exporter
image: opsgenie/kubernetes-event-exporter:0.7
image: opsgenie/kubernetes-event-exporter:0.8
imagePullPolicy: IfNotPresent
args:
- -conf=/data/config.yaml
Expand Down
3 changes: 2 additions & 1 deletion pkg/kube/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (e *EventWatcher) onEvent(event *corev1.Event) {
Str("msg", event.Message).
Str("namespace", event.Namespace).
Str("reason", event.Reason).
Str("involvedObject", event.InvolvedObject.Name).
Msg("Received event")

ev := &EnhancedEvent{
Expand All @@ -77,7 +78,7 @@ func (e *EventWatcher) onEvent(event *corev1.Event) {
annotations, err := e.annotationCache.GetAnnotationsWithCache(&event.InvolvedObject)
if err != nil {
log.Error().Err(err).Msg("Cannot list annotations of the object")
}else {
} else {
ev.InvolvedObject.Annotations = annotations
ev.InvolvedObject.ObjectReference = *event.InvolvedObject.DeepCopy()
}
Expand Down

0 comments on commit fee8951

Please sign in to comment.