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

Fix error when raw error is retrieved #2079

Merged
merged 6 commits into from
Nov 14, 2022

Conversation

michalpristas
Copy link
Contributor

What is the problem this PR solves?

Enrollment or any other operation fails when error returned by elastic is a raw string instead of json

How does this PR solve the problem?

This PR adds ability to parse error either as a ErrorT type or string as a secondary option.

For string it tries to guess error type based on some well known occurrences of Exception names or error messages in retrieved error message.

How to test this PR locally

Disable detailed_errors in ES and try everything works.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

Fixes: elastic/elastic-agent#931

@michalpristas michalpristas added bug Something isn't working Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Nov 14, 2022
@michalpristas michalpristas requested a review from a team as a code owner November 14, 2022 13:52
@michalpristas michalpristas self-assigned this Nov 14, 2022
@elasticmachine
Copy link
Contributor

elasticmachine commented Nov 14, 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-11-14T14:01:58.404+0000

  • Duration: 12 min 56 sec

Test stats 🧪

Test Results
Failed 0
Passed 387
Skipped 1
Total 388

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

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

  • /test : Re-trigger the build.

Copy link
Member

@aleksmaus aleksmaus left a comment

Choose a reason for hiding this comment

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

lgtm

}

// try decoding detailed error by default
detailedError := &ErrorT{}
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe?

var detailedError ErrorT

@@ -66,12 +74,77 @@ var (
ErrIndexNotFound = errors.New("index not found")
ErrTimeout = errors.New("timeout")
ErrNotFound = errors.New("not found")

knownErrorTypes = [3]string{
Copy link
Member

Choose a reason for hiding this comment

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

nit: could omit the size (easier to add more elements later without updating the size)

knownErrorTypes = [...]string{

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

func TestErrorTranslation(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[elastic_agent] Agent enrolment fails when ES detailed_errors is switched off
3 participants