Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove timezone conditionals from pipeline template #12253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- New module `palo_alto` for Palo Alto Networks PAN-OS logs. {pull}11999[11999]
- Add RabbitMQ module. {pull}12032[12032]
- Add new `container` input. {pull}12162[12162]
- Add specific date processor to convert timezones so same pipeline can be used when convert_timezone is enabled or disabled. {pull}12253[12253]

*Heartbeat*

Expand Down
48 changes: 0 additions & 48 deletions filebeat/fileset/fileset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
package fileset

import (
"encoding/json"
"fmt"
"path/filepath"
"runtime"
"testing"
"text/template"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)

func getModuleForTesting(t *testing.T, module, fileset string) *Fileset {
Expand Down Expand Up @@ -232,51 +229,6 @@ func TestGetPipelineNginx(t *testing.T) {
assert.Contains(t, pipeline.contents, "processors")
}

func TestGetPipelineConvertTS(t *testing.T) {
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
logp.TestingSetup(logp.WithSelectors("fileset", "modules"))

// load system/syslog
modulesPath, err := filepath.Abs("../module")
assert.NoError(t, err)
fs, err := New(modulesPath, "syslog", &ModuleConfig{Module: "system"}, &FilesetConfig{
Var: map[string]interface{}{
"convert_timezone": true,
},
})
assert.NoError(t, err)
assert.NoError(t, fs.Read("6.1.0"))

cases := map[string]struct {
Beat string
Timezone bool
}{
"6.0.0": {Timezone: false},
"6.1.0": {Timezone: true},
"6.2.0": {Timezone: true},
}

for esVersion, cfg := range cases {
pipelineName := "filebeat-6.1.0-system-syslog-pipeline"

t.Run(fmt.Sprintf("es=%v", esVersion), func(t *testing.T) {
ver := common.MustNewVersion(esVersion)
pipelines, err := fs.GetPipelines(*ver)
require.NoError(t, err)

pipeline := pipelines[0]
assert.Equal(t, pipelineName, pipeline.id)

marshaled, err := json.Marshal(pipeline.contents)
require.NoError(t, err)
if cfg.Timezone {
assert.Contains(t, string(marshaled), "event.timezone")
} else {
assert.NotContains(t, string(marshaled), "event.timezone")
}
})
}
}

func TestGetTemplateFunctions(t *testing.T) {
vars := map[string]interface{}{
"builtin": map[string]interface{}{},
Expand Down
10 changes: 9 additions & 1 deletion filebeat/module/system/syslog/ingest/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
"MMM dd HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
],
{< if .convert_timezone >}"timezone": "{{ event.timezone }}",{< end >}
"ignore_failure": true
}
},
{
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
"date": {
"if": "ctx.event.timezone != null",
"field": "@timestamp",
"formats": ["ISO8601"],
"timezone": "{{ event.timezone }}",
"on_failure": [{"append": {"field": "error.message", "value": "{{ _ingest.on_failure_message }}"}}]
}
},
{
"remove": {
"field": "system.syslog.timestamp"
Expand Down