Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
SRE ignore_namespaces added, do not set namespace to labels if namesp…
…ace in involvedObject is empty
  • Loading branch information
nugored committed Oct 22, 2024
commit 5fd6b7d223cfbd6cfda0d9dc439f34a3f2505dcc
25 changes: 22 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ clusterName: my-super-local-cluster
route:
routes:
- match:
- receiver: "dump"
- receiver: "loki"

receivers:
- name: "dump"
stdout: {}
- name: "loki"
loki:
headers: # optional
Authorization: Basic $LOKI_BASIC_AUTH_BASE64
streamLabels:
stream: event
cluster: local-test
url: $LOKI_URL
layout:
namespace: "{{ .Namespace }}"
message: "{{ .Message }}"
type: "{{ .Type }}"
reason: "{{ .Reason }}"
kind: "{{ .InvolvedObject.Kind }}"
name: "{{.InvolvedObject.Name }}"
source: "{{ .Source.Component }}"
# ignore_namespaces:
# - namespace_one
# - namespace_two
# - namespace_three
25 changes: 19 additions & 6 deletions pkg/sinks/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"errors"
"fmt"
"github.com/resmoio/kubernetes-event-exporter/pkg/kube"
"github.com/rs/zerolog/log"
"io/ioutil"
"net/http"
"strconv"
"time"
"github.com/rs/zerolog/log"
)

type promtailStream struct {
Expand All @@ -24,11 +24,12 @@ type LokiMsg struct {
}

type LokiConfig struct {
Layout map[string]interface{} `yaml:"layout"`
StreamLabels map[string]string `yaml:"streamLabels"`
TLS TLS `yaml:"tls"`
URL string `yaml:"url"`
Headers map[string]string `yaml:"headers"`
Layout map[string]interface{} `yaml:"layout"`
StreamLabels map[string]string `yaml:"streamLabels"`
TLS TLS `yaml:"tls"`
URL string `yaml:"url"`
Headers map[string]string `yaml:"headers"`
IgnoreNamespaces []string `yaml:"ignore_namespaces"`
}

type Loki struct {
Expand Down Expand Up @@ -56,6 +57,18 @@ func (l *Loki) Send(ctx context.Context, ev *kube.EnhancedEvent) error {
if err != nil {
return err
}

for _, namespace := range l.cfg.IgnoreNamespaces {
if namespace == ev.InvolvedObject.Namespace {
log.Debug().Msgf("Skipping %s namespace, because it is in ignore list", ev.InvolvedObject.Namespace)
return nil
}
}

if ev.InvolvedObject.Namespace != "" {
l.cfg.StreamLabels["namespace"] = ev.InvolvedObject.Namespace
}

timestamp := generateTimestamp()
a := LokiMsg{
Streams: []promtailStream{{
Expand Down