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

libbeat fmtstr tests fail outside of UTC #28472

Closed
hinchliff opened this issue Oct 15, 2021 · 1 comment · Fixed by #28473
Closed

libbeat fmtstr tests fail outside of UTC #28472

hinchliff opened this issue Oct 15, 2021 · 1 comment · Fixed by #28473
Labels
flaky-test Unstable or unreliable test cases. Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@hinchliff
Copy link
Contributor

Flaky Test

  • Test Name:
    • TestEventFormatString
    • TestTimestampFormatString
  • Link:
    • {
      "test timestamp formatter",
      "%{[key]}: %{+YYYY.MM.dd}",
      beat.Event{
      Timestamp: time.Date(2015, 5, 1, 20, 12, 34, 0, time.Local),
      Fields: common.MapStr{
      "key": "timestamp",
      },
      },
      "timestamp: 2015.05.01",
      []string{"key"},
      },
      {
      "test timestamp formatter",
      "%{[@timestamp]}: %{+YYYY.MM.dd}",
      beat.Event{
      Timestamp: time.Date(2015, 5, 1, 20, 12, 34, 0, time.Local),
      Fields: common.MapStr{
      "key": "timestamp",
      },
      },
      "2015-05-01T20:12:34.000Z: 2015.05.01",
      []string{"@timestamp"},
      },
    • {
      "test timestamp formatter",
      "%{[key]}: %{+YYYY.MM.dd}",
      common.MapStr{"key": "timestamp"},
      time.Date(2015, 5, 1, 20, 12, 34, 0, time.Local),
      "timestamp: 2015.05.01",
      },
      {
      "test timestamp formatter",
      "%{[@timestamp]}: %{+YYYY.MM.dd}",
      common.MapStr{"key": "timestamp"},
      time.Date(2015, 5, 1, 20, 12, 34, 0, time.Local),
      "2015-05-01T20:12:34.000Z: 2015.05.01",
      },
  • Branch: main
  • Artifact Link: n/a
  • Notes: There are four unit tests that seem to be about re-formatting a timestamp in UTC. However, the unit tests generate the expected time using time.Local, which produces inconsistent results based on the local timezone used by e.g. the developer. If my understanding of the purpose of the test cases is correct, then using time.UTC should resolve any potential inconsistencies.

Stack Trace

command [go test -cover -coverprofile /tmp/gotestcover-1560318489 github.com/elastic/beats/v7/libbeat/common/fmtstr]: exit status 1
--- FAIL: TestEventFormatString (0.00s)
    formatevents_test.go:135: test(0): empty string
    formatevents_test.go:135: test(1): no fields configured
    formatevents_test.go:135: test(2): expand event field
    formatevents_test.go:135: test(3): expand with default
    formatevents_test.go:135: test(4): expand nested event field
    formatevents_test.go:135: test(5): expand nested event field (alt. syntax)
    formatevents_test.go:135: test(6): multiple event fields
    formatevents_test.go:135: test(7): same fields
    formatevents_test.go:135: test(8): same fields with default (first)
    formatevents_test.go:135: test(9): same fields with default (second)
    formatevents_test.go:135: test(10): test timestamp formatter
    formatevents_test.go:135: test(11): test timestamp formatter
    formatevents_test.go:146: 
        	Error Trace:	formatevents_test.go:146
        	Error:      	Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual  : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test:       	TestEventFormatString
--- FAIL: TestTimestampFormatString (0.00s)
    formattimestamp_test.go:89: test(0): empty string
    formattimestamp_test.go:89: test(1): no fields configured
    formattimestamp_test.go:89: test(2): expand field
    formattimestamp_test.go:89: test(3): expand with default
    formattimestamp_test.go:89: test(4): expand nested field
    formattimestamp_test.go:89: test(5): test timestamp formatter
    formattimestamp_test.go:89: test(6): test timestamp formatter
    formattimestamp_test.go:106: 
        	Error Trace:	formattimestamp_test.go:106
        	Error:      	Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual  : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test:       	TestTimestampFormatString
FAIL
coverage: 83.9% of statements
FAIL	github.com/elastic/beats/v7/libbeat/common/fmtstr	0.442s
FAIL
command [go test -cover -coverprofile /tmp/gotestcover-165778516 github.com/elastic/beats/v7/libbeat/common/fmtstr]: exit status 1
--- FAIL: TestTimestampFormatString (0.00s)
    formattimestamp_test.go:89: test(0): empty string
    formattimestamp_test.go:89: test(1): no fields configured
    formattimestamp_test.go:89: test(2): expand field
    formattimestamp_test.go:89: test(3): expand with default
    formattimestamp_test.go:89: test(4): expand nested field
    formattimestamp_test.go:89: test(5): test timestamp formatter
    formattimestamp_test.go:89: test(6): test timestamp formatter
    formattimestamp_test.go:106: 
        	Error Trace:	formattimestamp_test.go:106
        	Error:      	Not equal: 
        	            	expected: "2015-05-01T20:12:34.000Z: 2015.05.01"
        	            	actual  : "2015-05-02T00:12:34.000Z: 2015.05.01"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-2015-05-01T20:12:34.000Z: 2015.05.01
        	            	+2015-05-02T00:12:34.000Z: 2015.05.01
        	Test:       	TestTimestampFormatString
FAIL
coverage: 83.9% of statements
FAIL	github.com/elastic/beats/v7/libbeat/common/fmtstr	0.327s
FAIL

See Also

https://discuss.elastic.co/t/test-suite-error-time-local-vs-time-utc/286735

@hinchliff hinchliff added the flaky-test Unstable or unreliable test cases. label Oct 15, 2021
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 15, 2021
hinchliff pushed a commit to hinchliff/beats that referenced this issue Oct 15, 2021
@andresrc andresrc added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Oct 21, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Oct 21, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

mergify bot pushed a commit that referenced this issue Nov 30, 2021
mergify bot pushed a commit that referenced this issue Nov 30, 2021
elasticmachine pushed a commit to nxei/beats that referenced this issue Dec 1, 2021
* upstream/master:
  [libbeat] Fix add_labels flattening of arrays values (elastic#29211)
  Change elastic-agent pprof default to false (elastic#29155)
  elastic#28472 fix flaky tests in libbeat fmtstr to use time.UTC instead of time.Local (elastic#28473)
  Adopt `parsers` in Filebeat's journald input (elastic#29070)
  [Elastic Agent] Add process error handling guidelines (elastic#29152)
  winlogbeat/sys/winevent: use reflect IsZero method (elastic#29190)
  Remove Journalbeat (elastic#29131)
  Add note that there is no warranty or support for generator code (elastic#28797)
  packetbeat: preparation for npcap addition (elastic#29017)
  Use the generic helper for opening file to read in filestream (elastic#29180)
  Workflow for macos (elastic#29174)
  Fix `decode_json_fields` processor to always add error key (elastic#29107)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flaky-test Unstable or unreliable test cases. Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants