Skip to content

Commit

Permalink
Fluentd plugin kube events timestamp support (kube-logging#839)
Browse files Browse the repository at this point in the history
* fluentd plugin kube-events-timestamp support

* header check script fix

* autogenerated files regenerated with go 1.16.5

* rebase merge fixes
  • Loading branch information
bshifter authored Sep 27, 2021
1 parent 75edac6 commit 51a8efe
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -1080,6 +1089,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
18 changes: 18 additions & 0 deletions charts/logging-operator/crds/logging.banzaicloud.io_flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -1076,6 +1085,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
18 changes: 18 additions & 0 deletions charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -3902,6 +3911,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
18 changes: 18 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_clusterflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -1080,6 +1089,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
18 changes: 18 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -1076,6 +1085,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
18 changes: 18 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down Expand Up @@ -3902,6 +3911,15 @@ spec:
type: object
type: array
type: object
kube_events_timestamp:
properties:
mapped_time_key:
type: string
timestamp_fields:
items:
type: string
type: array
type: object
parser:
properties:
emit_invalid_record_to_error:
Expand Down
29 changes: 15 additions & 14 deletions pkg/sdk/api/v1beta1/flow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ type Exclude struct {

// Filter definition for FlowSpec
type Filter struct {
StdOut *filter.StdOutFilterConfig `json:"stdout,omitempty"`
Parser *filter.ParserConfig `json:"parser,omitempty"`
TagNormaliser *filter.TagNormaliser `json:"tag_normaliser,omitempty"`
Dedot *filter.DedotFilterConfig `json:"dedot,omitempty"`
RecordTransformer *filter.RecordTransformer `json:"record_transformer,omitempty"`
RecordModifier *filter.RecordModifier `json:"record_modifier,omitempty"`
GeoIP *filter.GeoIP `json:"geoip,omitempty"`
Concat *filter.Concat `json:"concat,omitempty"`
DetectExceptions *filter.DetectExceptions `json:"detectExceptions,omitempty"`
Grep *filter.GrepConfig `json:"grep,omitempty"`
Prometheus *filter.PrometheusConfig `json:"prometheus,omitempty"`
Throttle *filter.Throttle `json:"throttle,omitempty"`
SumoLogic *filter.SumoLogic `json:"sumologic,omitempty"`
EnhanceK8s *filter.EnhanceK8s `json:"enhanceK8s,omitempty"`
StdOut *filter.StdOutFilterConfig `json:"stdout,omitempty"`
Parser *filter.ParserConfig `json:"parser,omitempty"`
TagNormaliser *filter.TagNormaliser `json:"tag_normaliser,omitempty"`
Dedot *filter.DedotFilterConfig `json:"dedot,omitempty"`
RecordTransformer *filter.RecordTransformer `json:"record_transformer,omitempty"`
RecordModifier *filter.RecordModifier `json:"record_modifier,omitempty"`
GeoIP *filter.GeoIP `json:"geoip,omitempty"`
Concat *filter.Concat `json:"concat,omitempty"`
DetectExceptions *filter.DetectExceptions `json:"detectExceptions,omitempty"`
Grep *filter.GrepConfig `json:"grep,omitempty"`
Prometheus *filter.PrometheusConfig `json:"prometheus,omitempty"`
Throttle *filter.Throttle `json:"throttle,omitempty"`
SumoLogic *filter.SumoLogic `json:"sumologic,omitempty"`
EnhanceK8s *filter.EnhanceK8s `json:"enhanceK8s,omitempty"`
KubeEventsTimestamp *filter.KubeEventsTimestampConfig `json:"kube_events_timestamp,omitempty"`
}

// FlowStatus defines the observed state of Flow
Expand Down
5 changes: 5 additions & 0 deletions pkg/sdk/api/v1beta1/zz_generated.deepcopy.go

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

89 changes: 89 additions & 0 deletions pkg/sdk/model/filter/kube_events_timestamp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright © 2019 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package filter

import (
"github.com/banzaicloud/logging-operator/pkg/sdk/model/types"
"github.com/banzaicloud/operator-tools/pkg/secret"
)

// +name:"Kubernetes Events Timestamp"
// +weight:"200"
type _hugoKubeEventsTimestamp interface{}

// +kubebuilder:object:generate=true
// +docName:"[Kubernetes Events Timestamp Filter](https://github.com/banzaicloud/fluentd-filter-kube-events-timestamp)"
// Fluentd Filter plugin to select particular timestamp into an additional field
type _docKubeEventsTimestamp interface{}

// +name:"Kubernetes Events Timestamp"
// +url:"https://github.com/banzaicloud/fluentd-filter-kube-events-timestamp"
// +version:"0.1.4"
// +description:"Fluentd Filter plugin to select particular timestamp into an additional field"
// +status:"GA"
type _metaKubeEventsTimestamp interface{}

// +kubebuilder:object:generate=true
type KubeEventsTimestampConfig struct {
// Time field names in order of relevance (default: event.eventTime, event.lastTimestamp, event.firstTimestamp)
TimestampFields []string `json:"timestamp_fields,omitempty"`
// Added time field name (default: triggerts)
MappedTimeKey string `json:"mapped_time_key,omitempty"`
}

// #### Example `Kubernetes Events Timestamp` filter configurations
// ```yaml
//apiVersion: logging.banzaicloud.io/v1beta1
//kind: Flow
//metadata:
// name: es-flow
//spec:
// filters:
// - kube_events_timestamp:
// timestamp_fields:
// - "event.eventTime"
// - "event.lastTimestamp"
// - "event.firstTimestamp"
// mapped_time_key: mytimefield
// selectors: {}
// localOutputRefs:
// - es-output
// ```
//
// #### Fluentd Config Result
// ```yaml
// <filter **>
// @type kube_events_timestamp
// @id test-kube-events-timestamp
// timestamp_fields ["event.eventTime","event.lastTimestamp","event.firstTimestamp"]
// mapped_time_key mytimefield
// </filter>
// ```
type _expKubeEventsTimestamp interface{}

func NewKubeEventsTimestampConfig() *KubeEventsTimestampConfig {
return &KubeEventsTimestampConfig{}
}

func (c *KubeEventsTimestampConfig) ToDirective(secretLoader secret.SecretLoader, id string) (types.Directive, error) {
const pluginType = "kube_events_timestamp"

return types.NewFlatDirective(types.PluginMeta{
Type: pluginType,
Directive: "filter",
Tag: "**",
Id: id,
}, c, secretLoader)
}
46 changes: 46 additions & 0 deletions pkg/sdk/model/filter/kube_events_timestamp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2019 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package filter_test

import (
"testing"

"github.com/banzaicloud/logging-operator/pkg/sdk/model/filter"
"github.com/banzaicloud/logging-operator/pkg/sdk/model/render"
"github.com/ghodss/yaml"
)

func TestKubeEventsTimestamp(t *testing.T) {
CONFIG := []byte(`
timestamp_fields:
- "event.eventTime"
- "event.lastTimestamp"
- "event.firstTimestamp"
mapped_time_key: mytimefield
`)
expected := `
<filter **>
@type kube_events_timestamp
@id test
mapped_time_key mytimefield
timestamp_fields ["event.eventTime","event.lastTimestamp","event.firstTimestamp"]
</filter>
`
parser := &filter.KubeEventsTimestampConfig{}
yaml.Unmarshal(CONFIG, parser)
test := render.NewOutputPluginTest(t, parser)
test.DiffResult(expected)
}
Loading

0 comments on commit 51a8efe

Please sign in to comment.