forked from kube-logging/logging-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fluentd plugin kube events timestamp support (kube-logging#839)
* fluentd plugin kube-events-timestamp support * header check script fix * autogenerated files regenerated with go 1.16.5 * rebase merge fixes
- Loading branch information
Showing
13 changed files
with
290 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.