/
output_forward.go
113 lines (101 loc) · 2.66 KB
/
output_forward.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package functional
import (
"strings"
"github.com/openshift/cluster-logging-operator/internal/generator/url"
"github.com/openshift/cluster-logging-operator/internal/runtime"
log "github.com/ViaQ/logerr/v2/log/static"
logging "github.com/openshift/cluster-logging-operator/api/logging/v1"
"github.com/openshift/cluster-logging-operator/internal/constants"
"github.com/openshift/cluster-logging-operator/internal/utils"
)
const (
defaultFluentdforwardPort = "24224"
unsecureFluentConf = `
<system>
log_level debug
</system>
<source>
@type forward
port 24224
</source>
<filter **>
@type stdout
include_time_key true
</filter>
<match kubernetes.** var.log.**>
@type file
append true
path /tmp/app.logs
symlink_path /tmp/app-logs
<format>
@type json
</format>
<buffer>
@type file
append true
</buffer>
</match>
<match journal.system>
@type file
append true
path /tmp/infra.logs
symlink_path /tmp/infra-logs
<format>
@type json
</format>
<buffer>
@type file
append true
</buffer>
</match>
<filter linux-audit.log**>
@type parser
key_name @timestamp
reserve_data true
<parse>
@type regexp
expression (?<time>[^\]]*)
time_type string
time_key time
time_format %Y-%m-%dT%H:%M:%S.%N%z
</parse>
</filter>
<match linux-audit.log** k8s-audit.log** openshift-audit.log** ovn-audit.log**>
@type file
path /tmp/audit.logs
append true
symlink_path /tmp/audit-logs
<format>
@type json
</format>
</match>
<match **>
@type stdout
</match>`
)
func (f *CollectorFunctionalFramework) addForwardOutputWithConf(b *runtime.PodBuilder, output logging.OutputSpec, conf string) error {
log.V(2).Info("Adding forward output", "name", output.Name)
name := strings.ToLower(output.Name)
config := runtime.NewConfigMap(b.Pod.Namespace, name, map[string]string{
"fluent.conf": conf,
})
log.V(2).Info("Creating configmap", "namespace", config.Namespace, "name", config.Name, "fluent.conf", unsecureFluentConf)
if err := f.Test.Client.Create(config); err != nil {
return err
}
log.V(2).Info("Adding container", "name", name)
b.AddContainer(name, utils.GetComponentImage(constants.FluentdName)).
AddVolumeMount(config.Name, "/tmp/config", "", false).
WithCmd([]string{"fluentd", "-c", "/tmp/config/fluent.conf"}).
End().
AddConfigMapVolume(config.Name, config.Name)
return nil
}
func (f *CollectorFunctionalFramework) AddForwardOutput(b *runtime.PodBuilder, output logging.OutputSpec) error {
outURL, err := url.Parse(output.URL)
if err != nil {
return err
}
config := strings.Replace(unsecureFluentConf, defaultFluentdforwardPort, outURL.Port(), 1)
return f.addForwardOutputWithConf(b, output, config)
}