Skip to content

Conversation

@r00tu53r
Copy link
Contributor

@r00tu53r r00tu53r commented Mar 21, 2022

Return error for system test cases where zero or no doc hits were found on a particular data stream. Without this error check the code panics and prevents proper cleanup of the system test containers which prevents subsequent system test runs.

Error before this fix:

....
2022/03/21 12:32:47 DEBUG found 0 hits in logs-cisco_meraki.events-ep data stream
2022/03/21 12:32:48 DEBUG found 0 hits in logs-cisco_meraki.events-ep data stream
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/elastic/elastic-package/internal/testrunner/runners/system.(*runner).runTest(0xc000142d80, 0xc000654480, {{0xc0001623d8, 0x14}, {0xc000444000, 0x2e}, {0x7bcce78, 0x0, 0x0}, 0x0, ...}, ...)
        /Users/saikiran/go/src/github.com/r00tu53r/elastic-package/internal/testrunner/runners/system/runner.go:454 +0x184f
github.com/elastic/elastic-package/internal/testrunner/runners/system.(*runner).runTestPerVariant(0xc000142d80, 0xc00011a0f0, 0x64b3520, {0xc00065c102, 0x1c}, {0xc00017c100, 0x0}, {0x0, 0x0})
        /Users/saikiran/go/src/github.com/r00tu53r/elastic-package/internal/testrunner/runners/system/runner.go:206 +0x5d8
github.com/elastic/elastic-package/internal/testrunner/runners/system.(*runner).run(0xc000142d80)
        /Users/saikiran/go/src/github.com/r00tu53r/elastic-package/internal/testrunner/runners/system/runner.go:176 +0x4fd
github.com/elastic/elastic-package/internal/testrunner/runners/system.(*runner).Run(0x0, {{{0xc00017c100, 0x71}, {0xc00005c0a5, 0xc}, {0xc00017c15a, 0x6}}, {0xc00005c064, 0x4d}, 0x1, ...})
        /Users/saikiran/go/src/github.com/r00tu53r/elastic-package/internal/testrunner/runners/system/runner.go:87 +0x65                                                                                                      github.com/elastic/elastic-package/internal/testrunner.Run({0x615a975, 0x6}, {{{0xc00017c100, 0x71}, {0xc00005c0a5, 0xc}, {0xc00017c15a, 0x6}}, {0xc00005c064, 0x4d}, ...})
        /Users/saikiran/go/src/github.com/r00tu53r/elastic-package/internal/testrunner/testrunner.go:250 +0x99
<... snipped ... >
main.main()

Messages after the fix:

2022/03/25 17:37:59 DEBUG found 0 hits in logs-cisco_meraki.events-ep data stream
2022/03/25 17:38:00 DEBUG found 0 hits in logs-cisco_meraki.events-ep data stream
2022/03/25 17:38:01 DEBUG reassigning original policy back to agent...
2022/03/25 17:38:01 DEBUG PUT http://127.0.0.1:5601/api/fleet/agents/a9acf647-b4a4-494a-b24a-c0eb661a315c/reassign
2022/03/25 17:38:03 DEBUG GET http://127.0.0.1:5601/api/fleet/agents/a9acf647-b4a4-494a-b24a-c0eb661a315c
2022/03/25 17:38:03 DEBUG Agent data: {"id":"a9acf647-b4a4-494a-b24a-c0eb661a315c","policy_id":"2016d7cc-135e-5583-9758-3ba01f5a06e5","local_metadata":{"host":{"name":"docker-fleet-agent"}}}
2022/03/25 17:38:03 DEBUG Wait until the policy (ID: 2016d7cc-135e-5583-9758-3ba01f5a06e5, revision: 1) is assigned to the agent (ID: a9acf647-b4a4-494a-b24a-c0eb661a315c)...
2022/03/25 17:38:05 DEBUG GET http://127.0.0.1:5601/api/fleet/agents/a9acf647-b4a4-494a-b24a-c0eb661a315c
2022/03/25 17:38:05 DEBUG Agent data: {"id":"a9acf647-b4a4-494a-b24a-c0eb661a315c","policy_id":"2016d7cc-135e-5583-9758-3ba01f5a06e5","local_metadata":{"host":{"name":"docker-fleet-agent"}}}
2022/03/25 17:38:05 DEBUG Wait until the policy (ID: 2016d7cc-135e-5583-9758-3ba01f5a06e5, revision: 1) is assigned to the agent (ID: a9acf647-b4a4-494a-b24a-c0eb661a315c)...
2022/03/25 17:38:07 DEBUG GET http://127.0.0.1:5601/api/fleet/agents/a9acf647-b4a4-494a-b24a-c0eb661a315c
2022/03/25 17:38:07 DEBUG Agent data: {"id":"a9acf647-b4a4-494a-b24a-c0eb661a315c","policy_id":"2016d7cc-135e-5583-9758-3ba01f5a06e5","local_metadata":{"host":{"name":"docker-fleet-agent"}}}
2022/03/25 17:38:07 DEBUG Wait until the policy (ID: 2016d7cc-135e-5583-9758-3ba01f5a06e5, revision: 1) is assigned to the agent (ID: a9acf647-b4a4-494a-b24a-c0eb661a315c)...
2022/03/25 17:38:09 DEBUG GET http://127.0.0.1:5601/api/fleet/agents/a9acf647-b4a4-494a-b24a-c0eb661a315c
2022/03/25 17:38:09 DEBUG Agent data: {"id":"a9acf647-b4a4-494a-b24a-c0eb661a315c","policy_id":"2016d7cc-135e-5583-9758-3ba01f5a06e5","policy_revision":1,"local_metadata":{"host":{"name":"docker-fleet-agent"}}}
2022/03/25 17:38:09 DEBUG Policy revision assigned to the agent (ID: a9acf647-b4a4-494a-b24a-c0eb661a315c)...
2022/03/25 17:38:09 DEBUG deleting test policy...
2022/03/25 17:38:09 DEBUG POST http://127.0.0.1:5601/api/fleet/agent_policies/delete
2022/03/25 17:38:12 DEBUG tearing down service...
...
...
2022/03/25 17:38:13 DEBUG deleting data in data stream...
Error: error running package system tests: could not complete test run: could not find hits in logs-cisco_meraki.events-ep data stream

@r00tu53r r00tu53r requested a review from mtojek March 21, 2022 02:55
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 21, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-25T06:41:52.815+0000

  • Duration: 17 min 22 sec

Test stats 🧪

Test Results
Failed 0
Passed 618
Skipped 1
Total 619

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@mtojek mtojek requested a review from a team March 21, 2022 08:47
@mtojek
Copy link
Contributor

mtojek commented Mar 21, 2022

@r00tu53r Could you please fix the linting issues?

[2022-03-21T02:59:56.552Z] internal/testrunner/runners/system/runner.go:656:5: should omit nil check; len() for nil slices is defined as zero (S1009)

// no hits were found for a data stream
if len(docs) == 0 {
multiErr = append(multiErr, fmt.Errorf("no documents found in %s data stream", dataStream))
return multiErr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that to make it correct, the code execution must reach line 676 (return testrunner.ErrTestCaseFailed{) to convert the multiErr.

I would leave the multiErr = append(...) in line 657, but wrap for-loop with if-clause.

Copy link
Contributor Author

@r00tu53r r00tu53r Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out @mtojek. Sorry missed that. I've made the change. I hope I understood it right.

// prevents panic and performs cleanup/teardown for cases where
// no hits were found for a data stream
if len(docs) == 0 {
multiErr = append(multiErr, fmt.Errorf("no documents found in %s data stream", dataStream))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. I'm trying to deduce what should be the logic here. Function validateFields checks if documents are valid according to the schema loaded to the FieldsValidator, so the question is how should it work if there are no documents passed?

Maybe it's possible to fail fast sooner and not call the validateFields?

WDYT?

cc @jsoriano

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm .. What I thought is - In this case where we run system tests if there are no documents passed it means there is an error in the pipeline. We have the data for sure in the files but it didn't match the conditions of the pipeline.

I'll have another look at the logic from a few calls above the call stack to understand how else this can be handled. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm .. What I thought is - In this case where we run system tests if there are no documents passed it means there is an error in the pipeline

My understanding is that if we can don't have any documents, we shouldn't call the validation of documents :)

Copy link
Contributor Author

@r00tu53r r00tu53r Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that if we can don't have any documents, we shouldn't call the validation of documents :)

Thanks :). I think I see what you mean. I agree validateFields needn't be invoked. The runner invokes tests per each variant. For a case where there were no doc hits if an error is returned then it would not run tests for other variants. As you see here - https://github.com/elastic/elastic-package/blob/main/internal/testrunner/runners/system/runner.go#L176-L179. Do you think that's acceptable behaviour?

I've modified the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's much shorter now :) If it fixes the panic, then it's 👍 . Thank you for the fix, Sai!

@r00tu53r r00tu53r requested a review from mtojek March 25, 2022 12:53
@r00tu53r r00tu53r merged commit 87d3cdd into elastic:main Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants