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

[Ingest Manager] Ensure at least default Error handling on all routes #77975

Merged
merged 4 commits into from
Sep 21, 2020

Conversation

jfsiii
Copy link
Contributor

@jfsiii jfsiii commented Sep 20, 2020

Summary

Fixes the error logging & HTTP status code portions of #66688 for all routes by using the defaultIngestErrorHandler introduced in #74409

  • In the request handler, if the caught error is instanceof IngestManagerError, use res.customError() to return the error to the caller. Pass the message, and get a suitable HTTP response code from the getHTTPResponseCode() helper.
  • In the request handler, also use the Kibana Logger to log the error message to the Kibana log.
  • In the request handler, if the error is not IngestManagerError, use status code 500. In that case, log an error to the console with the full error message, and also log the stack trace of the error.

/setup & /epm/* were implemented in #74409

Now the handlers look roughly like:

async function handler(context, request, response): KibanaResponse {
  try {
    const result = await something();
    return response.ok({ body: result });
  } catch (error) {
    return defaultIngestErrorHandler({ error, response });
  }
}

Checklist

Delete any items that are not applicable to this PR.

Update one test a1939d3 to reflect the change in result from 500 to 404.

I'm not sure if any more are needed/desired. There are tests for defaultIngestErrorHandler which sure the advertised behavior.

    IngestManagerError
      ✓ 502: RegistryError (7ms)
      ✓ 404: PackageNotFoundError (2ms)
      ✓ 400: IngestManagerError (2ms)
    Boom
      ✓ 500: constructor - one arg (2ms)
      ✓ custom: constructor - 2 args (1ms)
      ✓ 400: Boom.badRequest (2ms)
      ✓ 404: Boom.notFound (1ms)
    all other errors
      ✓ 500 (2ms)

Any non-default logic is still run before defaultIngestErrorHandler is called.

For maintainers

@jfsiii
Copy link
Contributor Author

jfsiii commented Sep 21, 2020

@elasticmachine merge upstream

await supertest
.post(`/api/ingest_manager/agent_policies/INVALID_POLICY_ID/copy`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Copied policy',
description: '',
})
.expect(500);
.expect(404);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is consistent with what we do elsewhere, and I prefer 4xx over 500 here, but we can easily keep the 500 behavior if that's desired.

Copy link
Member

Choose a reason for hiding this comment

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

I think 400 make sense here 👍

@jfsiii jfsiii marked this pull request as ready for review September 21, 2020 13:40
@jfsiii jfsiii requested a review from a team September 21, 2020 13:40
@jfsiii jfsiii changed the title [Ingest Manager] Add remaining default Error handlers [Ingest Manager] Ensure at least default Error handling on all routes Sep 21, 2020
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Sep 21, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@jfsiii jfsiii added release_note:skip Skip the PR/issue when compiling release notes v7.10.0 v7.9.3 v8.0.0 labels Sep 21, 2020
@jfsiii jfsiii self-assigned this Sep 21, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

@jfsiii jfsiii merged commit 06d1436 into elastic:master Sep 21, 2020
jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Sep 21, 2020
…elastic#77975)

* res.customError -> defaultIngestErrorHandler

* Missed a variable rename in prior commit

* copying an invalid policy will 404; not 500

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Sep 21, 2020
…elastic#77975)

* res.customError -> defaultIngestErrorHandler

* Missed a variable rename in prior commit

* copying an invalid policy will 404; not 500

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/ingest_manager/server/routes/agent/acks_handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/agent/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/package_policy/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/settings/index.ts
#	x-pack/test/ingest_manager_api_integration/apis/agent_policy/agent_policy.ts
jfsiii pushed a commit that referenced this pull request Sep 22, 2020
…routes (#77975) (#78086)

* [Ingest Manager] Ensure at least default Error handling on all routes (#77975)

* res.customError -> defaultIngestErrorHandler

* Missed a variable rename in prior commit

* copying an invalid policy will 404; not 500

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

* Add import missed by backport script

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
jfsiii pushed a commit that referenced this pull request Sep 22, 2020
…routes (#77975) (#78088)

* [Ingest Manager] Ensure at least default Error handling on all routes (#77975)

* res.customError -> defaultIngestErrorHandler

* Missed a variable rename in prior commit

* copying an invalid policy will 404; not 500

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/ingest_manager/server/routes/agent/acks_handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/agent/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/agent_policy/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/package_policy/handlers.ts
#	x-pack/plugins/ingest_manager/server/routes/settings/index.ts
#	x-pack/test/ingest_manager_api_integration/apis/agent_policy/agent_policy.ts

* Remove any 7.x references to *_policy vs *_config

* 404, not 500, on invalid id
@ghost
Copy link

ghost commented Oct 20, 2020

Hi @jfsiii

We have gone through the ticket and observed it required DEV_Validation to test the ticket .

Please let us know if anything is missing from our end.

@jfsiii
Copy link
Contributor Author

jfsiii commented Oct 20, 2020

@rahulgupta-qasource I don't know what DEV_Validation is. Are you unable to make GET and POST requests to the /api/fleet/* endpoints?

@EricDavisX
Copy link
Contributor

@jfsiii hi. I can chime in, we're implementing process as we go - thanks for the support. :) This DEV_Validate label is a carry over from process the QA team had with other teams. It's use was intended to specify the test team believed it was beyond regular test duty (usually beyond the ability of the test team to handle it without more input and possibly without more expertise developed). It was used to indicate that and to close the loop back that the dev team would handle it or elaborate further on what we shall do.

Allow me to follow through now:
We are in a place where we are developing more automated tests routinely, and this change is best handled with our Kibana automation FTR framework. I know we have some tests in place, but with this modification I see only 1 test adjusted so I presume you've or another engineer has done representative testing enough (perhaps one manual test from each distinct api group enhanced) to feel confident in the merge and we can open a new test ticket to cover the test enhancements, if we think it warrants the test. We'd clearly be more confident if we had those, but I can't judge the value proposition versus other automation we need to develop. I'll leave that to you and you can log a ticket as you see best.

The QA validation we've done over the 7.9.3 build shows that the merge was sane and we can call the testing side done as I see it.

Very happy to discourse any topic or specific item about this pr or test need and to figure out how to assign any further test work. I know we have an OAS api file in Kibana, we can use that to do manual review if we think it is warranted. The test team understands Postman usage to make API calls, but Rahul has not specifically done much API tests until now so it will include some ramp up time and discourse about which APIs need coverage.

@jfsiii
Copy link
Contributor Author

jfsiii commented Oct 20, 2020

@EricDavisX Thanks for the explanation. I'm lacking context for why I was pinged about this, but I'm not asking for any different testing here. Let me know if you need anything from me, but I'm fine leaving this closed and covered by our existing approach(es).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.9.3 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants