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] Create default Error handler. Use on /setup & EPM routes #74409

Merged
merged 5 commits into from
Sep 4, 2020

Conversation

jfsiii
Copy link
Contributor

@jfsiii jfsiii commented Aug 5, 2020

Summary

This adds an IngestErrorHandler type/function. It has same output as a RequestHandler and its inputs are the 3 RequestHandler inputs + error.

type IngestErrorHandler = (
  params: IngestErrorHandlerParams
) => IKibanaResponse | Promise<IKibanaResponse>;

interface IngestErrorHandlerParams {
  error: IngestManagerError | Boom | Error;
  response: KibanaResponseFactory;
  request?: KibanaRequest;
  context?: RequestHandlerContext;
}

It maps an Error and ResponseFactory to an IKibanaResponse. 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 });
  }
}

I've started with defaultIngestErrorHandler and we can add different Error handlers when/if needed.

Checklist

  • The tests added in ensure the POST /setup case didn't regress, but I'm not sure what additional tests we want.
  • I'll add tests to confirm defaultIngestErrorHandler behaves as advertised
  defaultIngestErrorHandler
    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)

@jfsiii
Copy link
Contributor Author

jfsiii commented Aug 20, 2020

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

@jfsiii jfsiii force-pushed the ingest-default-error-handler branch from 0c4d44a to cefb62c Compare August 20, 2020 20:51
@jfsiii jfsiii added the Team:Fleet Team label for Observability Data Collection Fleet team label Aug 20, 2020
@jfsiii jfsiii marked this pull request as ready for review August 21, 2020 12:51
@jfsiii jfsiii requested a review from a team August 21, 2020 12:51
@elasticmachine
Copy link
Contributor

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

@jfsiii jfsiii marked this pull request as draft August 21, 2020 14:32
@jfsiii
Copy link
Contributor Author

jfsiii commented Aug 24, 2020

@elasticmachine merge upstream

@jfsiii
Copy link
Contributor Author

jfsiii commented Aug 26, 2020

@elasticmachine merge upstream

2 similar comments
@jfsiii
Copy link
Contributor Author

jfsiii commented Aug 27, 2020

@elasticmachine merge upstream

@jfsiii
Copy link
Contributor Author

jfsiii commented Sep 2, 2020

@elasticmachine merge upstream

@jfsiii jfsiii force-pushed the ingest-default-error-handler branch from 1019605 to d7ad578 Compare September 3, 2020 14:42
@jfsiii jfsiii marked this pull request as ready for review September 3, 2020 19:30
@jfsiii jfsiii force-pushed the ingest-default-error-handler branch from 0ca52aa to b94cd78 Compare September 3, 2020 19:31
@jfsiii jfsiii requested a review from skh September 3, 2020 20:17
@jfsiii jfsiii added release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Sep 3, 2020
@jfsiii jfsiii changed the title [Ingest Manager] Create default Error handler. Use on POST /setup [Ingest Manager] Create default Error handler. Use on /setup & EPM routes Sep 3, 2020
@jfsiii jfsiii requested review from a team and neptunian September 3, 2020 20:32
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@jfsiii jfsiii merged commit fc22c7d into elastic:master Sep 4, 2020
jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Sep 4, 2020
…utes (elastic#74409)

* Add default Error handler. Try on /*setup & /epm/*

* Add return type. Rename interface

* Export error handler type & add comments

* use default error handler in installPackageHandler

* (re)-add comment
jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Sep 4, 2020
…utes (elastic#74409)

* Add default Error handler. Try on /*setup & /epm/*

* Add return type. Rename interface

* Export error handler type & add comments

* use default error handler in installPackageHandler

* (re)-add comment
# Conflicts:
#	x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts
jfsiii pushed a commit that referenced this pull request Sep 5, 2020
…utes (#74409) (#76754)

* Add default Error handler. Try on /*setup & /epm/*

* Add return type. Rename interface

* Export error handler type & add comments

* use default error handler in installPackageHandler

* (re)-add comment
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Sep 8, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Sep 8, 2020
jfsiii pushed a commit that referenced this pull request Sep 8, 2020
…utes (#74409) (#76770)

* Add default Error handler. Try on /*setup & /epm/*

* Add return type. Rename interface

* Export error handler type & add comments

* use default error handler in installPackageHandler

* (re)-add comment
# Conflicts:
#	x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
dgieselaar pushed a commit to dgieselaar/kibana that referenced this pull request Sep 9, 2020
…utes (elastic#74409) (elastic#76770)

* Add default Error handler. Try on /*setup & /epm/*

* Add return type. Rename interface

* Export error handler type & add comments

* use default error handler in installPackageHandler

* (re)-add comment
# Conflicts:
#	x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts

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

ghost commented Sep 18, 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.

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.2 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants