github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/application/applications/logcollection/logging/flow.go (about) 1 package logging 2 3 type FlowConfig struct { 4 Name string 5 Namespace string 6 SelectLabels map[string]string 7 Outputs []string 8 ClusterOutputs []string 9 ParserType string 10 ParserExpression string 11 RemoveKeys string 12 } 13 14 type Parse struct { 15 Type string `yaml:"type"` 16 Expression string `yaml:"expression"` 17 } 18 type Parser struct { 19 RemoveKeyNameField bool `yaml:"remove_key_name_field"` 20 ReserveData bool `yaml:"reserve_data"` 21 Parse *Parse `yaml:"parse"` 22 } 23 type TagNormaliser struct { 24 Format string 25 } 26 27 type Filter struct { 28 Parser *Parser `yaml:"parser,omitempty"` 29 TagNormaliser *TagNormaliser `yaml:"tag_normaliser,omitempty"` 30 RecordTransformer *RecordTransformer `yaml:"record_transformer,omitempty"` 31 } 32 33 type RecordTransformer struct { 34 RemoveKeys string `yaml:"remove_keys,omitempty"` 35 } 36 37 type FlowSpec struct { 38 Filters []*Filter `yaml:"filters,omitempty"` 39 Match []*Match `yaml:"match,omitempty"` 40 OutputRefs []string `yaml:"localOutputRefs"` 41 ClusterOutputRefs []string `yaml:"globalOutputRefs"` 42 } 43 type Match struct { 44 Select *Select `yaml:"select"` 45 Exclude *Select `yaml:"exlcude"` 46 } 47 type Select struct { 48 Labels map[string]string `yaml:"labels,omitempty"` 49 Hosts []string `yaml:"hosts,omitempty"` 50 Namespaces []string `yaml:"namespaces,omitempty"` 51 } 52 53 type Flow struct { 54 APIVersion string `yaml:"apiVersion"` 55 Kind string `yaml:"kind"` 56 Metadata *Metadata `yaml:"metadata"` 57 Spec *FlowSpec `yaml:"spec"` 58 } 59 60 func NewFlow(conf *FlowConfig) *Flow { 61 filters := make([]*Filter, 0) 62 63 if conf.ParserType != "" { 64 filters = append(filters, &Filter{ 65 Parser: &Parser{ 66 RemoveKeyNameField: true, 67 ReserveData: true, 68 Parse: &Parse{ 69 Type: conf.ParserType, 70 Expression: conf.ParserExpression, 71 }, 72 }, 73 }) 74 } 75 if conf.RemoveKeys != "" { 76 filters = append(filters, &Filter{ 77 RecordTransformer: &RecordTransformer{ 78 RemoveKeys: conf.RemoveKeys, 79 }, 80 }) 81 } 82 83 return &Flow{ 84 APIVersion: "logging.banzaicloud.io/v1beta1", 85 Kind: "Flow", 86 Metadata: &Metadata{ 87 Name: conf.Name, 88 Namespace: conf.Namespace, 89 }, 90 Spec: &FlowSpec{ 91 Filters: filters, 92 Match: []*Match{ 93 { 94 Select: &Select{ 95 Labels: conf.SelectLabels, 96 }, 97 }, 98 }, 99 OutputRefs: conf.Outputs, 100 ClusterOutputRefs: conf.ClusterOutputs, 101 }, 102 } 103 }