Skip to content

Commit

Permalink
Merge "Fluent Bit log forwarding: fix erroneous labels, add container…
Browse files Browse the repository at this point in the history
… label"
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed Mar 5, 2024
2 parents a389c9d + 6a1a85f commit 2a6ae69
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
6 changes: 4 additions & 2 deletions controllers/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func createImageBuildLogForwarderSidecar(r *SFController, annotations map[string
MountPath: "/fluent-bit/etc/",
},
}
sidecar := logging.CreateFluentBitSideCarContainer("diskimage-builder", nodepoolFluentBitLabels, volumeMounts)
builderFluentBitLabels := append(nodepoolFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: BuilderIdent})
sidecar := logging.CreateFluentBitSideCarContainer("diskimage-builder", builderFluentBitLabels, volumeMounts)
annotations["dib-fluent-bit.conf"] = utils.Checksum([]byte(fbForwarderConfig["fluent-bit.conf"]))
annotations["dib-fluent-bit-parser"] = utils.Checksum([]byte(fbForwarderConfig["parsers.conf"]))
annotations["dib-fluent-bit-image"] = base.FluentBitImage
Expand Down Expand Up @@ -754,7 +755,8 @@ func (r *SFController) DeployNodepoolLauncher(statsdExporterVolume apiv1.Volume,
}
container.Env = r.getNodepoolConfigEnvs()

extraLoggingEnvVars := logging.SetupLogForwarding("nodepool-launcher", r.cr.Spec.FluentBitLogForwarding, nodepoolFluentBitLabels, annotations)
launcherFluentBitLabels := append(nodepoolFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: LauncherIdent})
extraLoggingEnvVars := logging.SetupLogForwarding("nodepool-launcher", r.cr.Spec.FluentBitLogForwarding, launcherFluentBitLabels, annotations)
container.Env = append(container.Env, extraLoggingEnvVars...)

nl.Spec.Template.Spec.Volumes = volumes
Expand Down
5 changes: 3 additions & 2 deletions controllers/static/mariadb/fluentbit/fluent-bit.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
name modify
match *
add namespace ${K8S_NAMESPACE}
add nodeName ${K8S_NODENAME}
add podName ${K8S_PODNAME}
add nodename ${K8S_NODENAME}
add podname ${K8S_PODNAME}
add ip ${K8S_PODIP}
add labels_run mariadb
add component mariadb
add container mariadb
{{- range .ExtraKeys }}
add {{ .Key }} ${K8S_{{ .Value -}}}
{{- end }}
Expand Down
5 changes: 3 additions & 2 deletions controllers/static/nodepool/fluentbit/fluent-bit.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
name modify
match *
add namespace ${K8S_NAMESPACE}
add nodeName ${K8S_NODENAME}
add podName ${K8S_PODNAME}
add nodename ${K8S_NODENAME}
add podname ${K8S_PODNAME}
add ip ${K8S_PODIP}
add labels_run dib
add component nodepool
add container nodepool-builder
{{- range .ExtraKeys }}
add {{ .Key }} ${K8S_{{ .Value -}}}
{{- end }}
Expand Down
5 changes: 3 additions & 2 deletions controllers/static/zookeeper/fluent-bit.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
name modify
match *
add namespace ${K8S_NAMESPACE}
add nodeName ${K8S_NODENAME}
add podName ${K8S_PODNAME}
add nodename ${K8S_NODENAME}
add podname ${K8S_PODNAME}
add ip ${K8S_PODIP}
add labels_run zookeeper
add component zookeeper
add container zookeeper
{{- range .ExtraKeys }}
add {{ .Key }} ${K8S_{{ .Value -}}}
{{- end }}
Expand Down
20 changes: 12 additions & 8 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (r *SFController) EnsureZuulScheduler(cfg *ini.File) bool {
"zuul-component-config": utils.IniSectionsChecksum(cfg, sections),
"zuul-image": base.ZuulImage("zuul-scheduler"),
"statsd_mapping": utils.Checksum([]byte(zuulStatsdMappingConfig)),
"serial": "7",
"serial": "8",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-scheduler"))),
"zuul-extra": utils.Checksum([]byte(sshConfig)),
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
Expand All @@ -418,7 +418,8 @@ func (r *SFController) EnsureZuulScheduler(cfg *ini.File) bool {

zuulContainers := r.mkZuulContainer(ZuulSchedulerIdent, corporateCMExists)

extraLoggingEnvVars := logging.SetupLogForwarding("zuul-scheduler", r.cr.Spec.FluentBitLogForwarding, zuulFluentBitLabels, annotations)
zsFluentBitLabels := append(zuulFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: "zuul-scheduler"})
extraLoggingEnvVars := logging.SetupLogForwarding("zuul-scheduler", r.cr.Spec.FluentBitLogForwarding, zsFluentBitLabels, annotations)
zuulContainers[0].Env = append(zuulContainers[0].Env, extraLoggingEnvVars...)

statsdSidecar := monitoring.MkStatsdExporterSideCarContainer("zuul", "statsd-config", relayAddress)
Expand Down Expand Up @@ -514,7 +515,7 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool {
"zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections),
"zuul-component-config": utils.IniSectionsChecksum(cfg, sections),
"zuul-image": base.ZuulImage("zuul-executor"),
"serial": "5",
"serial": "6",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-executor"))),
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
"corporate-ca-certs-version": getCMVersion(corporateCM, corporateCMExists),
Expand All @@ -524,7 +525,8 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool {
ze.Spec.Template.Spec.Containers = r.mkZuulContainer("zuul-executor", corporateCMExists)
ze.Spec.Template.Spec.Volumes = mkZuulVolumes("zuul-executor", r, corporateCMExists)

extraLoggingEnvVars := logging.SetupLogForwarding("zuul-executor", r.cr.Spec.FluentBitLogForwarding, zuulFluentBitLabels, annotations)
zeFluentBitLabels := append(zuulFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: "zuul-executor"})
extraLoggingEnvVars := logging.SetupLogForwarding("zuul-executor", r.cr.Spec.FluentBitLogForwarding, zeFluentBitLabels, annotations)
ze.Spec.Template.Spec.Containers[0].Env = append(ze.Spec.Template.Spec.Containers[0].Env, extraLoggingEnvVars...)

ze.Spec.Template.ObjectMeta.Annotations = annotations
Expand Down Expand Up @@ -585,7 +587,7 @@ func (r *SFController) EnsureZuulMerger(cfg *ini.File) bool {
"zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections),
"zuul-component-config": utils.IniSectionsChecksum(cfg, sections),
"zuul-image": base.ZuulImage(service),
"serial": "3",
"serial": "4",
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
"corporate-ca-certs-version": getCMVersion(corporateCM, corporateCMExists),
}
Expand All @@ -594,7 +596,8 @@ func (r *SFController) EnsureZuulMerger(cfg *ini.File) bool {
zm.Spec.Template.Spec.Containers = r.mkZuulContainer(service, corporateCMExists)
zm.Spec.Template.Spec.Volumes = mkZuulVolumes(service, r, corporateCMExists)

extraLoggingEnvVars := logging.SetupLogForwarding(service, r.cr.Spec.FluentBitLogForwarding, zuulFluentBitLabels, annotations)
zmFluentBitLabels := append(zuulFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: "zuul-merger"})
extraLoggingEnvVars := logging.SetupLogForwarding(service, r.cr.Spec.FluentBitLogForwarding, zmFluentBitLabels, annotations)
zm.Spec.Template.Spec.Containers[0].Env = append(zm.Spec.Template.Spec.Containers[0].Env, extraLoggingEnvVars...)

nodeExporterSidecar := monitoring.MkNodeExporterSideCarContainer(
Expand Down Expand Up @@ -640,7 +643,7 @@ func (r *SFController) EnsureZuulWeb(cfg *ini.File) bool {
"zuul-common-config": utils.IniSectionsChecksum(cfg, commonIniConfigSections),
"zuul-component-config": utils.IniSectionsChecksum(cfg, sections),
"zuul-image": base.ZuulImage("zuul-web"),
"serial": "5",
"serial": "6",
"zuul-logging": utils.Checksum([]byte(r.getZuulLoggingString("zuul-web"))),
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
}
Expand All @@ -649,7 +652,8 @@ func (r *SFController) EnsureZuulWeb(cfg *ini.File) bool {
zw.Spec.Template.Spec.Containers = r.mkZuulContainer("zuul-web", false)
zw.Spec.Template.Spec.Volumes = mkZuulVolumes("zuul-web", r, false)

extraLoggingEnvVars := logging.SetupLogForwarding("zuul-web", r.cr.Spec.FluentBitLogForwarding, zuulFluentBitLabels, annotations)
zwFluentBitLabels := append(zuulFluentBitLabels, logging.FluentBitLabel{Key: "CONTAINER", Value: "zuul-web"})
extraLoggingEnvVars := logging.SetupLogForwarding("zuul-web", r.cr.Spec.FluentBitLogForwarding, zwFluentBitLabels, annotations)
zw.Spec.Template.Spec.Containers[0].Env = append(zw.Spec.Template.Spec.Containers[0].Env, extraLoggingEnvVars...)

zw.Spec.Template.ObjectMeta.Annotations = annotations
Expand Down
1 change: 1 addition & 0 deletions doc/deployment/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The log JSON payload that is sent to your Fluent Bit collector is enriched with
| podname | the name of the pod where the service is running |
| log | the actual log line collected |
| component | the name of the component running the microservice; typically "zuul" or "nodepool" |
| container | the name of the container emitting the logs |
You can use these keys to define labels in your Fluent Bit pipeline.
Expand Down
2 changes: 1 addition & 1 deletion tools/loki/test-fluentbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data:
name loki
match *
host loki-http
labels namespace=$namespace, podIP=$podip, nodeName=$nodename, application=$component, podName=$podname, labels_run=$labels_run, labels_app=sf
labels namespace=$namespace, podIP=$podip, nodeName=$nodename, application=$component, podName=$podname, labels_run=$labels_run, labels_app=sf, container=$container
kind: ConfigMap
metadata:
creationTimestamp: null
Expand Down

0 comments on commit 2a6ae69

Please sign in to comment.