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

[Filebeat][httpjson] Fix date_cursor validation #21756

Merged
merged 2 commits into from
Oct 15, 2020
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
9 changes: 7 additions & 2 deletions x-pack/filebeat/input/httpjson/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ func (dc *dateCursorConfig) Validate() error {
if dc.DateFormat == "" {
return nil
}
now := time.Now().Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, now); err != nil {

const knownTimestamp = 1602601228 // 2020-10-13T15:00:28+00:00 RFC3339
knownDate := time.Unix(knownTimestamp, 0).UTC()

dateStr := knownDate.Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, dateStr); err != nil {
return errors.New("invalid configuration: date_format is not a valid date layout")
}

return nil
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/filebeat/input/httpjson/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func TestConfigOauth2Validation(t *testing.T) {
"url": "localhost",
},
},
/* Flaky test: https://github.com/elastic/beats/issues/21748
{
name: "date_cursor.date_format will fail if invalid",
expectedErr: "invalid configuration: date_format is not a valid date layout accessing 'date_cursor'",
Expand All @@ -371,7 +370,6 @@ func TestConfigOauth2Validation(t *testing.T) {
"url": "localhost",
},
},
*/
{
name: "date_cursor must work with a valid date_format",
input: map[string]interface{}{
Expand Down