Skip to content

Commit

Permalink
refactor selectors in clusterfluentdconfig/fluentdconfig
Browse files Browse the repository at this point in the history
Signed-off-by: zhu733756 <zhu733756@kubesphere.io>
  • Loading branch information
zhu733756 committed Feb 11, 2022
1 parent 0c9e805 commit 3602475
Show file tree
Hide file tree
Showing 16 changed files with 425 additions and 124 deletions.
4 changes: 2 additions & 2 deletions apis/fluentd/v1alpha1/clusterfluentdconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type ClusterFluentdConfigSpec struct {
// Use this field to filter the logs, will make no effect if EnableFilterKubernetes is set false.
WatchedLabels map[string]string `json:"watchedLabels,omitempty"`
// Select filter plugins
FilterSelector metav1.LabelSelector `json:"filterSelector,omitempty"`
ClusterFilterSelector *metav1.LabelSelector `json:"clusterFilterSelector,omitempty"`
// Select output plugins
OutputSelector metav1.LabelSelector `json:"outputSelector,omitempty"`
ClusterOutputSelector *metav1.LabelSelector `json:"clusterOutputSelector,omitempty"`
}

// ClusterFluentdConfigStatus defines the observed state of ClusterFluentdConfig
Expand Down
12 changes: 8 additions & 4 deletions apis/fluentd/v1alpha1/fluentdconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ type FluentdConfigSpec struct {
WatchedContainers []string `json:"watchedConstainers,omitempty"`
// Use this field to filter the logs, will make no effect if EnableFilterKubernetes is set false.
WatchedLabels map[string]string `json:"watchedLabels,omitempty"`
// Select filter plugins
FilterSelector metav1.LabelSelector `json:"filterSelector,omitempty"`
// Select output plugins
OutputSelector metav1.LabelSelector `json:"outputSelector,omitempty"`
// Select namespaced filter plugins
FilterSelector *metav1.LabelSelector `json:"filterSelector,omitempty"`
// Select namespaced output plugins
OutputSelector *metav1.LabelSelector `json:"outputSelector,omitempty"`
// Select clusterfilter plugins
ClusterFilterSelector *metav1.LabelSelector `json:"clusterFilterSelector,omitempty"`
// Select clusteroutput plugins
ClusterOutputSelector *metav1.LabelSelector `json:"clusterOutputSelector,omitempty"`
}

// FluentdConfigStatus defines the observed state of FluentdConfig
Expand Down
4 changes: 2 additions & 2 deletions apis/fluentd/v1alpha1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (pgr *PluginResources) PatchAndFilterNamespacedLevelResources(sl plugins.Se
func (r *CfgResources) filterForFilters(cfgId, namespace, name, crdtype string,
sl plugins.SecretLoader, filters []filter.Filter) error {
for n, filter := range filters {
filterId := fmt.Sprintf("%s-%s-%s-%s-%d", cfgId, namespace, crdtype, name, n)
filterId := fmt.Sprintf("%s::%s::%s::%s-%d", cfgId, namespace, crdtype, name, n)
filter.FilterCommon.Id = &filterId
filter.FilterCommon.Tag = &params.DefaultTag

Expand All @@ -188,7 +188,7 @@ func (r *CfgResources) filterForFilters(cfgId, namespace, name, crdtype string,
func (r *CfgResources) filterForOutputs(cfgId, namespace, name, crdtype string,
sl plugins.SecretLoader, outputs []output.Output) error {
for n, output := range outputs {
outputId := fmt.Sprintf("%s-%s-%s-%s-%d", cfgId, namespace, crdtype, name, n)
outputId := fmt.Sprintf("%s::%s::%s::%s-%d", cfgId, namespace, crdtype, name, n)
output.OutputCommon.Id = &outputId
output.OutputCommon.Tag = &params.DefaultTag

Expand Down
28 changes: 14 additions & 14 deletions apis/fluentd/v1alpha1/tests/expected-main-cfgs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
</match>
<label @77325a720438bcf8ce64b8843429c689>
<filter **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusterfilter-clusterfilter1-0
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusterfilter::clusterfilter1-0
@type record_transformer
<record>
avg ${record["total"] / record["count"]}
message yay, ${record["message"]}
</record>
</filter>
<filter **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusterfilter-clusterfilter1-1
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusterfilter::clusterfilter1-1
@type grep
<exclude>
key message
Expand All @@ -58,14 +58,14 @@
</regexp>
</filter>
<filter **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusterfilter-clusterfilter2-1
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusterfilter::clusterfilter2-1
@type stdout
<format>
@type json
</format>
</filter>
<filter **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusterfilter-clusterfilter3-0
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusterfilter::clusterfilter3-0
@type parser
<parse>
@type regexp
Expand All @@ -74,7 +74,7 @@
</parse>
</filter>
<match **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusteroutput-clusteroutput1-0
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusteroutput::clusteroutput1-0
@type forward
<buffer buffertag.*>
@id common_buffer
Expand All @@ -92,7 +92,7 @@
</service_discovery>
</match>
<match **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusteroutput-clusteroutput1-1
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusteroutput::clusteroutput1-1
@type kafka2
brokers broker1,broker2
<buffer buffertag.*>
Expand All @@ -106,7 +106,7 @@
</format>
</match>
<match **>
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0-cluster-clusteroutput-clusteroutput2-1
@id ClusterFluentdConfig-cluster-clusterfluentdconfig0::cluster::clusteroutput::clusteroutput2-1
@type http
endpoint http://logserver.com:9000/api
open_timeout 2
Expand All @@ -125,15 +125,15 @@
</label>
<label @7c5eaa432199cc1c1a547dff0dcdef83>
<filter **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-filter-filter1-0
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::filter::filter1-0
@type record_transformer
<record>
avg ${record["total"] / record["count"]}
message yay, ${record["message"]}
</record>
</filter>
<filter **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-filter-filter1-1
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::filter::filter1-1
@type grep
<exclude>
key message
Expand All @@ -153,14 +153,14 @@
</regexp>
</filter>
<filter **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-filter-filter2-1
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::filter::filter2-1
@type stdout
<format>
@type json
</format>
</filter>
<filter **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-filter-filter3-0
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::filter::filter3-0
@type parser
<parse>
@type regexp
Expand All @@ -169,7 +169,7 @@
</parse>
</filter>
<match **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-output-output1-0
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::output::output1-0
@type forward
<buffer buffertag.*>
@id common_buffer
Expand All @@ -187,7 +187,7 @@
</service_discovery>
</match>
<match **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-output-output1-1
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::output::output1-1
@type kafka2
brokers broker1,broker2
<buffer buffertag.*>
Expand All @@ -201,7 +201,7 @@
</format>
</match>
<match **>
@id FluentdConfig-testnamespace-fluentdconfig0-testnamespace-output-output2-1
@id FluentdConfig-testnamespace-fluentdconfig0::testnamespace::output::output2-1
@type http
endpoint http://logserver.com:9000/api
open_timeout 2
Expand Down
49 changes: 38 additions & 11 deletions apis/fluentd/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions config/crd/bases/fluentd.fluent.io_clusterfluentdconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ spec:
spec:
description: ClusterFluentdConfigSpec defines the desired state of ClusterFluentdConfig
properties:
emit_mode:
description: 'Emit mode. If batch, the plugin will emit events per
labels matched. Enum: record, batch. will make no effect if EnableFilterKubernetes
is set false.'
enum:
- record
- batch
type: string
filterSelector:
clusterFilterSelector:
description: Select filter plugins
properties:
matchExpressions:
Expand Down Expand Up @@ -91,7 +83,7 @@ spec:
are ANDed.
type: object
type: object
outputSelector:
clusterOutputSelector:
description: Select output plugins
properties:
matchExpressions:
Expand Down Expand Up @@ -135,6 +127,14 @@ spec:
are ANDed.
type: object
type: object
emit_mode:
description: 'Emit mode. If batch, the plugin will emit events per
labels matched. Enum: record, batch. will make no effect if EnableFilterKubernetes
is set false.'
enum:
- record
- batch
type: string
stickyTags:
description: Sticky tags will match only one record from an event
stream. The same tag will be treated the same way. will make no
Expand Down
Loading

0 comments on commit 3602475

Please sign in to comment.