@@ -25,11 +25,12 @@ type LokiMsg struct {
2525}
2626
2727type LokiConfig struct {
28- Layout map [string ]interface {} `yaml:"layout"`
29- StreamLabels map [string ]string `yaml:"streamLabels"`
30- TLS TLS `yaml:"tls"`
31- URL string `yaml:"url"`
32- Headers map [string ]string `yaml:"headers"`
28+ Layout map [string ]interface {} `yaml:"layout"`
29+ StreamLabels map [string ]string `yaml:"streamLabels"`
30+ TLS TLS `yaml:"tls"`
31+ URL string `yaml:"url"`
32+ Headers map [string ]string `yaml:"headers"`
33+ IgnoreNamespaces []string `yaml:"ignore_namespaces"`
3334}
3435
3536type Loki struct {
@@ -66,14 +67,35 @@ func convertStreamTemplate(layout map[string]string, ev *kube.EnhancedEvent) (ma
6667}
6768
6869func (l * Loki ) Send (ctx context.Context , ev * kube.EnhancedEvent ) error {
70+ if ev .InvolvedObject .Kind == "Node" {
71+ l .cfg .StreamLabels ["host" ] = ev .InvolvedObject .Name
72+ delete (l .cfg .Layout , "name" )
73+ } else {
74+ l .cfg .Layout ["name" ] = "{{ .InvolvedObject.Name }}"
75+ }
76+
6977 eventBody , err := serializeEventWithLayout (l .cfg .Layout , ev )
7078 if err != nil {
7179 return err
7280 }
81+
82+ for _ , namespace := range l .cfg .IgnoreNamespaces {
83+ if namespace == ev .InvolvedObject .Namespace {
84+ log .Debug ().Msgf ("Skipping %s namespace, because it is in ignore list" , ev .InvolvedObject .Namespace )
85+ return nil
86+ }
87+ }
88+
89+ if ev .InvolvedObject .Namespace != "" {
90+ l .cfg .StreamLabels ["namespace" ] = ev .InvolvedObject .Namespace
91+ l .cfg .StreamLabels ["index" ] = l .cfg .StreamLabels ["cluster" ] + "-" + ev .InvolvedObject .Namespace
92+ }
93+
7394 streamLabels , err := convertStreamTemplate (l .cfg .StreamLabels , ev )
7495 if err != nil {
7596 return err
7697 }
98+
7799 timestamp := generateTimestamp ()
78100 a := LokiMsg {
79101 Streams : []promtailStream {{
@@ -110,6 +132,10 @@ func (l *Loki) Send(ctx context.Context, ev *kube.EnhancedEvent) error {
110132 return err
111133 }
112134
135+ delete (l .cfg .StreamLabels , "namespace" )
136+ delete (l .cfg .StreamLabels , "index" )
137+ delete (l .cfg .StreamLabels , "host" )
138+
113139 defer resp .Body .Close ()
114140
115141 body , err := io .ReadAll (resp .Body )
0 commit comments