Skip to content

Commit 2e43881

Browse files
mhuinmorucci
authored andcommitted
Log Forwarding: enable forwarding nodepool build logs
If log forwarding is enabled, create a fluent bit sidecar on the nodepool-builder statefulset that forwards logs a json payloads, ie the way Nodepool and Zuul process do too. Include a simple Ansible output callback plugin to timestamp each line in ansible-playbook's output, which allows these log lines to be queried in order in the log collector. Change-Id: I5b4779b58f72aab41de3dd3262f0e1d8f90d5566
1 parent 9371484 commit 2e43881

File tree

9 files changed

+611
-1
lines changed

9 files changed

+611
-1
lines changed

controllers/libs/base/images.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
HTTPDImage = ImageToString(Image{Path: "registry.access.redhat.com/ubi8/httpd-24", Version: "1-284.1696531168"})
3333
NodeExporterImage = ImageToString(Image{Path: "quay.io/prometheus/node-exporter", Version: "v1.6.1"})
3434
StatsdExporterImage = ImageToString(Image{Path: "quay.io/prometheus/statsd-exporter", Version: "v0.24.0"})
35+
FluentBitImage = ImageToString(Image{Path: "cr.fluentbit.io/fluent/fluent-bit", Version: "2.1.10-debug"})
3536
)
3637

3738
func ZuulImage(service string) string {

controllers/libs/logging/logging.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ func SetupLogForwarding(serviceName string, forwarderSpec *v1.FluentBitForwarder
5353
return []apiv1.EnvVar{}
5454
}
5555
}
56+
57+
func CreateFluentBitSideCarContainer(serviceName string, extraLabels []FluentBitLabel, volumeMounts []apiv1.VolumeMount) apiv1.Container {
58+
container := base.MkContainer("fluentbit", base.FluentBitImage)
59+
container.Env = CreateForwarderEnvVars(serviceName, extraLabels)
60+
ports := []apiv1.ContainerPort{
61+
{
62+
Name: "fb-http-server",
63+
ContainerPort: 2020,
64+
},
65+
}
66+
container.Ports = ports
67+
container.VolumeMounts = volumeMounts
68+
return container
69+
}

controllers/nodepool.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ var nodepoolStatsdMappingConfigTemplate string
4141
//go:embed static/nodepool/httpd-build-logs-dir.conf
4242
var httpdBuildLogsDirConfig string
4343

44+
//go:embed static/nodepool/fluentbit/parsers.conf
45+
var fluentBitForwarderParsersConfig string
46+
47+
//go:embed static/nodepool/fluentbit/fluent-bit.conf.tmpl
48+
var fluentBitForwarderConfig string
49+
50+
// ansible.cfg and the timestamp callback could be hard-coded in the nodepool builder container.
51+
//
52+
//go:embed static/nodepool/ansible/ansible.cfg
53+
var ansibleConfiguration string
54+
55+
//go:embed static/nodepool/ansible/timestamp.py
56+
var timestampOutputCallback string
57+
4458
const (
4559
nodepoolIdent = "nodepool"
4660
launcherIdent = nodepoolIdent + "-launcher"
@@ -69,11 +83,47 @@ var nodepoolFluentBitLabels = []logging.FluentBitLabel{
6983
},
7084
}
7185

86+
func createImageBuildLogForwarderSidecar(r *SFController, annotations map[string]string) (apiv1.Volume, apiv1.Container) {
87+
fbForwarderConfig := make(map[string]string)
88+
fbForwarderConfig["fluent-bit.conf"], _ = utils.ParseString(
89+
fluentBitForwarderConfig,
90+
struct {
91+
ExtraKeys []logging.FluentBitLabel
92+
FluentBitHTTPInputHost string
93+
FluentBitHTTPInputPort string
94+
}{[]logging.FluentBitLabel{}, r.cr.Spec.FluentBitLogForwarding.HTTPInputHost, strconv.Itoa(int(r.cr.Spec.FluentBitLogForwarding.HTTPInputPort))})
95+
fbForwarderConfig["parsers.conf"] = fluentBitForwarderParsersConfig
96+
r.EnsureConfigMap("fluentbit-dib-cfg", fbForwarderConfig)
97+
98+
volume := base.MkVolumeCM("dib-log-forwarder-config",
99+
"fluentbit-dib-cfg-config-map")
100+
101+
volumeMounts := []apiv1.VolumeMount{
102+
{
103+
Name: builderIdent,
104+
SubPath: "builds",
105+
MountPath: "/watch/",
106+
},
107+
{
108+
Name: "dib-log-forwarder-config",
109+
MountPath: "/fluent-bit/etc/",
110+
},
111+
}
112+
sidecar := logging.CreateFluentBitSideCarContainer("diskimage-builder", nodepoolFluentBitLabels, volumeMounts)
113+
annotations["dib-fluent-bit.conf"] = utils.Checksum([]byte(fbForwarderConfig["fluent-bit.conf"]))
114+
annotations["dib-fluent-bit-parser"] = utils.Checksum([]byte(fbForwarderConfig["parsers.conf"]))
115+
annotations["dib-fluent-bit-image"] = base.FluentBitImage
116+
return volume, sidecar
117+
118+
}
119+
72120
func (r *SFController) setNodepoolTooling() {
73121
toolingData := make(map[string]string)
74122
toolingData["generate-config.sh"] = generateConfigScript
75123
toolingData["dib-ansible.py"] = dibAnsibleWrapper
76124
toolingData["ssh_config"] = builderSSHConfig
125+
toolingData["timestamp.py"] = timestampOutputCallback
126+
toolingData["ansible.cfg"] = ansibleConfiguration
77127
r.EnsureConfigMap("nodepool-tooling", toolingData)
78128
}
79129

@@ -437,6 +487,18 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume,
437487
MountPath: "/etc/nodepool-logging/logging.yaml",
438488
ReadOnly: true,
439489
},
490+
{
491+
Name: "nodepool-tooling-vol",
492+
SubPath: "ansible.cfg",
493+
MountPath: "/etc/ansible/ansible.cfg",
494+
ReadOnly: true,
495+
},
496+
{
497+
Name: "nodepool-tooling-vol",
498+
SubPath: "timestamp.py",
499+
MountPath: "/usr/share/ansible/plugins/callback/timestamp.py",
500+
ReadOnly: true,
501+
},
440502
}
441503

442504
nodepoolProvidersSecrets, volumeMount, ready := r.setProviderSecretsVolumeMounts(volumeMount)
@@ -488,6 +550,11 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume,
488550

489551
extraLoggingEnvVars := logging.SetupLogForwarding("nodepool-builder", r.cr.Spec.FluentBitLogForwarding, nodepoolFluentBitLabels, annotations)
490552
nb.Spec.Template.Spec.Containers[0].Env = append(nb.Spec.Template.Spec.Containers[0].Env, extraLoggingEnvVars...)
553+
if r.cr.Spec.FluentBitLogForwarding != nil {
554+
fbVolume, fbSidecar := createImageBuildLogForwarderSidecar(r, annotations)
555+
nb.Spec.Template.Spec.Containers = append(nb.Spec.Template.Spec.Containers, fbSidecar)
556+
nb.Spec.Template.Spec.Volumes = append(nb.Spec.Template.Spec.Volumes, fbVolume)
557+
}
491558

492559
nb.Spec.Template.ObjectMeta.Annotations = annotations
493560

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
stdout_callback=timestamp

0 commit comments

Comments
 (0)