Skip to content

Commit 2887538

Browse files
authored
Merge branch 'master' into fix/issue-1871-disableLogVolumes-quote
2 parents eab0391 + b2d9757 commit 2887538

9 files changed

Lines changed: 190 additions & 0 deletions

File tree

apis/fluentbit/v1alpha2/clusterfilter_types_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,133 @@ func TestClusterFilterList_Load_With_Ordinals(t *testing.T) {
293293
}
294294
}
295295

296+
func TestClusterFilterList_Load_Grep_LogicalOp(t *testing.T) {
297+
filtersExpected := `[Filter]
298+
Name grep
299+
Match *
300+
Regex log aa
301+
Exclude log bb
302+
Logical_Op and
303+
`
304+
305+
g := NewGomegaWithT(t)
306+
sl := plugins.NewSecretLoader(nil, "testnamespace")
307+
308+
filterObj := &ClusterFilter{
309+
TypeMeta: metav1.TypeMeta{
310+
APIVersion: "fluentbit.fluent.io/v1alpha2",
311+
Kind: "ClusterFilter",
312+
},
313+
ObjectMeta: metav1.ObjectMeta{
314+
Name: "filter-grep-logical-op",
315+
},
316+
Spec: FilterSpec{
317+
Match: "*",
318+
FilterItems: []FilterItem{
319+
{
320+
Grep: &filter.Grep{
321+
Regex: "log aa",
322+
Exclude: "log bb",
323+
LogicalOp: "and",
324+
},
325+
},
326+
},
327+
},
328+
}
329+
330+
filters := ClusterFilterList{
331+
Items: []ClusterFilter{*filterObj},
332+
}
333+
334+
clusterFilters, err := filters.Load(sl)
335+
g.Expect(err).NotTo(HaveOccurred())
336+
g.Expect(clusterFilters).To(Equal(filtersExpected))
337+
}
338+
339+
func TestClusterFilterList_Load_Grep_LogicalOp_Or(t *testing.T) {
340+
filtersExpected := `[Filter]
341+
Name grep
342+
Match *
343+
Regex log aa
344+
Exclude log bb
345+
Logical_Op or
346+
`
347+
348+
g := NewGomegaWithT(t)
349+
sl := plugins.NewSecretLoader(nil, "testnamespace")
350+
351+
filterObj := &ClusterFilter{
352+
TypeMeta: metav1.TypeMeta{
353+
APIVersion: "fluentbit.fluent.io/v1alpha2",
354+
Kind: "ClusterFilter",
355+
},
356+
ObjectMeta: metav1.ObjectMeta{
357+
Name: "filter-grep-logical-op-or",
358+
},
359+
Spec: FilterSpec{
360+
Match: "*",
361+
FilterItems: []FilterItem{
362+
{
363+
Grep: &filter.Grep{
364+
Regex: "log aa",
365+
Exclude: "log bb",
366+
LogicalOp: "or",
367+
},
368+
},
369+
},
370+
},
371+
}
372+
373+
filters := ClusterFilterList{
374+
Items: []ClusterFilter{*filterObj},
375+
}
376+
377+
clusterFilters, err := filters.Load(sl)
378+
g.Expect(err).NotTo(HaveOccurred())
379+
g.Expect(clusterFilters).To(Equal(filtersExpected))
380+
}
381+
382+
func TestClusterFilterList_Load_Grep_LogicalOp_Empty(t *testing.T) {
383+
filtersExpected := `[Filter]
384+
Name grep
385+
Match *
386+
Regex log aa
387+
Exclude log bb
388+
`
389+
390+
g := NewGomegaWithT(t)
391+
sl := plugins.NewSecretLoader(nil, "testnamespace")
392+
393+
filterObj := &ClusterFilter{
394+
TypeMeta: metav1.TypeMeta{
395+
APIVersion: "fluentbit.fluent.io/v1alpha2",
396+
Kind: "ClusterFilter",
397+
},
398+
ObjectMeta: metav1.ObjectMeta{
399+
Name: "filter-grep-no-logical-op",
400+
},
401+
Spec: FilterSpec{
402+
Match: "*",
403+
FilterItems: []FilterItem{
404+
{
405+
Grep: &filter.Grep{
406+
Regex: "log aa",
407+
Exclude: "log bb",
408+
},
409+
},
410+
},
411+
},
412+
}
413+
414+
filters := ClusterFilterList{
415+
Items: []ClusterFilter{*filterObj},
416+
}
417+
418+
clusterFilters, err := filters.Load(sl)
419+
g.Expect(err).NotTo(HaveOccurred())
420+
g.Expect(clusterFilters).To(Equal(filtersExpected))
421+
}
422+
296423
func TestClusterFilter_RecordModifier_Generated(t *testing.T) {
297424
filtersExpected := `[Filter]
298425
Name record_modifier

apis/fluentbit/v1alpha2/plugins/filter/grep_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Grep struct {
1717
// Exclude records which field matches the regular expression.
1818
// Value Format: FIELD REGEX
1919
Exclude string `json:"exclude,omitempty"`
20+
// Specify the logical operator for multiple regex/exclude rules.
21+
// +kubebuilder:validation:Enum:=and;or
22+
LogicalOp string `json:"logicalOp,omitempty"`
2023
}
2124

2225
func (*Grep) Name() string {
@@ -35,5 +38,8 @@ func (g *Grep) Params(_ plugins.SecretLoader) (*params.KVs, error) {
3538
if g.Exclude != "" {
3639
kvs.Insert("Exclude", g.Exclude)
3740
}
41+
if g.LogicalOp != "" {
42+
kvs.Insert("Logical_Op", g.LogicalOp)
43+
}
3844
return kvs, nil
3945
}

charts/fluent-bit-crds/templates/fluentbit.fluent.io_clusterfilters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ spec:
126126
Exclude records which field matches the regular expression.
127127
Value Format: FIELD REGEX
128128
type: string
129+
logicalOp:
130+
description: Specify the logical operator for multiple regex/exclude
131+
rules.
132+
enum:
133+
- and
134+
- or
135+
type: string
129136
regex:
130137
description: |-
131138
Keep records which field matches the regular expression.

charts/fluent-bit-crds/templates/fluentbit.fluent.io_filters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ spec:
126126
Exclude records which field matches the regular expression.
127127
Value Format: FIELD REGEX
128128
type: string
129+
logicalOp:
130+
description: Specify the logical operator for multiple regex/exclude
131+
rules.
132+
enum:
133+
- and
134+
- or
135+
type: string
129136
regex:
130137
description: |-
131138
Keep records which field matches the regular expression.

config/crd/bases/fluentbit.fluent.io_clusterfilters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ spec:
123123
Exclude records which field matches the regular expression.
124124
Value Format: FIELD REGEX
125125
type: string
126+
logicalOp:
127+
description: Specify the logical operator for multiple regex/exclude
128+
rules.
129+
enum:
130+
- and
131+
- or
132+
type: string
126133
regex:
127134
description: |-
128135
Keep records which field matches the regular expression.

config/crd/bases/fluentbit.fluent.io_filters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ spec:
123123
Exclude records which field matches the regular expression.
124124
Value Format: FIELD REGEX
125125
type: string
126+
logicalOp:
127+
description: Specify the logical operator for multiple regex/exclude
128+
rules.
129+
enum:
130+
- and
131+
- or
132+
type: string
126133
regex:
127134
description: |-
128135
Keep records which field matches the regular expression.

docs/plugins/fluentbit/filter/grep.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ The Grep Filter plugin allows to match or exclude specific records based in regu
77
| ----- | ----------- | ------ |
88
| regex | Keep records which field matches the regular expression. Value Format: FIELD REGEX | string |
99
| exclude | Exclude records which field matches the regular expression. Value Format: FIELD REGEX | string |
10+
| logicalOp | Specify the logical operator for multiple regex/exclude rules. | string |

manifests/setup/fluent-operator-crd.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ spec:
122122
Exclude records which field matches the regular expression.
123123
Value Format: FIELD REGEX
124124
type: string
125+
logicalOp:
126+
description: Specify the logical operator for multiple regex/exclude
127+
rules.
128+
enum:
129+
- and
130+
- or
131+
type: string
125132
regex:
126133
description: |-
127134
Keep records which field matches the regular expression.
@@ -15351,6 +15358,13 @@ spec:
1535115358
Exclude records which field matches the regular expression.
1535215359
Value Format: FIELD REGEX
1535315360
type: string
15361+
logicalOp:
15362+
description: Specify the logical operator for multiple regex/exclude
15363+
rules.
15364+
enum:
15365+
- and
15366+
- or
15367+
type: string
1535415368
regex:
1535515369
description: |-
1535615370
Keep records which field matches the regular expression.

manifests/setup/setup.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ spec:
122122
Exclude records which field matches the regular expression.
123123
Value Format: FIELD REGEX
124124
type: string
125+
logicalOp:
126+
description: Specify the logical operator for multiple regex/exclude
127+
rules.
128+
enum:
129+
- and
130+
- or
131+
type: string
125132
regex:
126133
description: |-
127134
Keep records which field matches the regular expression.
@@ -15351,6 +15358,13 @@ spec:
1535115358
Exclude records which field matches the regular expression.
1535215359
Value Format: FIELD REGEX
1535315360
type: string
15361+
logicalOp:
15362+
description: Specify the logical operator for multiple regex/exclude
15363+
rules.
15364+
enum:
15365+
- and
15366+
- or
15367+
type: string
1535415368
regex:
1535515369
description: |-
1535615370
Keep records which field matches the regular expression.

0 commit comments

Comments
 (0)