Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

CreateNamespace: do not hide error from lower call #116

Closed
wants to merge 1 commit into from

Conversation

okartau
Copy link
Contributor

@okartau okartau commented Jan 4, 2019

This simple change fixes error hiding issue described in #115.
But note that it also changes semantics on failure:
now we return after 1st attempt failure, but original code would try creation in other remaining regions.
If we want to keep original semantics, we have to choose which error to report/return,
in case we try multiple times and there are multiple errors.
Perhaps should add log stmt showing error, in addition to returning error?

@@ -66,6 +66,8 @@ func (ctx *Context) CreateNamespace(opts CreateNamespaceOpts) (*Namespace, error
for _, r := range bus.ActiveRegions() {
if ns, err := r.CreateNamespace(opts); err == nil {
return ns, nil
} else {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

As of i remember, it was intentional, to try with all available regions to serve the creation request. If upper layers are interested in error would call Region.CreateNamespace().

Copy link
Contributor

Choose a reason for hiding this comment

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

As @avalluri pointed out, this changes the semantic.

Otherwise a shorter way to write this if/else would be
return r.CreateNamespace(opts).

But even better is to wrap errors with errors.Wrap from https://github.com/pkg/errors because then additional information and a stack trace gets added at each level.

gRPC logging however currently doesn't show the stack trace, so that part isn't useful at the moment.

@okartau okartau force-pushed the dont-hide-nscreate-error branch from 6a49330 to 27ddb0d Compare January 7, 2019 08:48
@okartau
Copy link
Contributor Author

okartau commented Jan 7, 2019

Thanks for Wrap idea, it really seems good solution for multiple/nested errors case. I force-pushed change to use Wrap, fixes the issue without changing semantics.
If there are multiple Regions involved, the output may get crowded, but the most important part is not to miss any information, I think.
There are few wrapping choices here, we can either:

  • use empty addition in the loop and add one at the end (current code),
  • wrap with added string in the loop, and not string add at the end (can use plain wrappederr var there then)
  • add some string in both places (makes output even more messy so I think we should not).

The current code produces this message in case of one Region:

CreateNamespace returned error:Failed to create namespace: : pfn: failed to set namespace

extra colon mark(s) seems result of Wrap() with empty string, but this is just cosmetic problem

@okartau okartau force-pushed the dont-hide-nscreate-error branch from 27ddb0d to 3f41ab0 Compare January 7, 2019 09:02
@okartau
Copy link
Contributor Author

okartau commented Jan 7, 2019

another minor thing, should we use import() block instead of multiple import statements

@okartau okartau force-pushed the dont-hide-nscreate-error branch 3 times, most recently from ee35751 to 2f8600b Compare January 7, 2019 12:13
@okartau
Copy link
Contributor Author

okartau commented Jan 7, 2019

I tried this on a system with 6 Regions were same error happens, and contrary to my expectation (to see 6 times same message repeated) there is just single one:

GRPC error: rpc error: code = Internal desc = CreateVolume: failed to create volume: Failed to create namespace: : pfn: failed to set namespace

Does error.Wrap avoid repeating same msg? or is there something wrong with how Wrap is used here.

@okartau
Copy link
Contributor Author

okartau commented Jan 7, 2019

what about instead creating more complex error msg manipulation and analyzing there, we just log errors after we get them from lower/layer call, and we return single (new) error, as it was originally. Thats actually much simpler than wrap/analyze. The potential issue with that will be, list of per-Region errors is not returned via RPC but written in log instead. But it's still better than original state where error was not shown at all.

@pohly
Copy link
Contributor

pohly commented Jan 7, 2019 via email

@okartau
Copy link
Contributor Author

okartau commented Jan 8, 2019

k8s log info in general is not easy to discover IMHO, but if msg is logged, it can be retrieved, easy or less easy.
So my plan now is: 1. emit error-level log from failed attempts, stating region and error, 2. Wrap most recent error message and return it.

@okartau okartau force-pushed the dont-hide-nscreate-error branch 4 times, most recently from 27aaba3 to df19ed0 Compare January 10, 2019 12:44
@okartau
Copy link
Contributor Author

okartau commented Jan 10, 2019

can we merge this now? At least I am happy with how error messages are shown

@okartau okartau force-pushed the dont-hide-nscreate-error branch from df19ed0 to a1520b6 Compare January 15, 2019 11:44
@okartau
Copy link
Contributor Author

okartau commented Jan 15, 2019

How easily can the error be discovered in the log? This probably needs to go into an "admin cookbook" section in the README.md.

we don't have "admin cookbook" section in README. Should we create one?

@pohly
Copy link
Contributor

pohly commented Jan 15, 2019 via email

@okartau
Copy link
Contributor Author

okartau commented Jan 15, 2019

I change the style towards "less PRs" so that I dont create separate PR for small changes. Thus moving this change into new #133 , closing this PR

@okartau okartau closed this Jan 15, 2019
@okartau okartau deleted the dont-hide-nscreate-error branch January 25, 2019 08:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants