Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

feat: add GetRootContextByID call #93

Merged
merged 2 commits into from
Nov 14, 2020

Conversation

wouterposdijk
Copy link
Contributor

I would like to add this GetRootContextByID call, so that configuration stored in the root context can be read by the child context.

Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

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

nit: I agree this function maybe useful, but you can manage root_context_id -> context_id mapping in your code because the parent root_id is given in callbacks set by SetNewHttpContext and SetNewStreamContext. If you use your own mappings, you don't need to cast proxywasm.RootContext (returned by this function) to your specific struct.

sorry, I was mistaken. nvm

func GetRootContextByID(rootContextID uint32) (RootContext, error) {
rootContextState, ok := currentState.rootContexts[rootContextID]
if !ok {
return nil, types.ErrorStatusNotFound
Copy link
Member

Choose a reason for hiding this comment

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

types.ErrorStatusNotFound corresponds to the error status code returned by the "host" in any hostcall

so I think we can just do like:

Suggested change
return nil, types.ErrorStatusNotFound
return nil, fmt.Errorf("root context not found: %d", rootContextID)

Copy link
Contributor Author

@wouterposdijk wouterposdijk Nov 13, 2020

Choose a reason for hiding this comment

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

Maybe it would be better to define a static error then:
var ErrorRootContextNotFound = errors.New("root context not found")
and then wrap it with fmt.Errorf("%w: %d", ErrorRootContextNotFound, rootContextID)? That way, the error can be identified by the caller using errors.Is.

If you agree: I'm not sure where you would want to place this static error, though; there does not seem to be a standard for it in this project yet. Do you have a preference, or should I just place it above the function?

Copy link
Member

Choose a reason for hiding this comment

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

agree with static error! Go ahead 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've added it. I've also added a unit test, unfortunately I can't seem to get the e2e tests to run locally.

Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

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

@wouterposdijk LGTM! Thanks always 👍

@mathetake mathetake merged commit 0894850 into tetratelabs:main Nov 14, 2020
mathetake added a commit that referenced this pull request Mar 9, 2021
This is kind of an improvement from #93 in favor of proxy-wasm/proxy-wasm-rust-sdk#34 and proxy-wasm/proxy-wasm-rust-sdk#67

Note that this is a breaking change, though the fix is trivial.

Signed-off-by: Takeshi Yoneda [email protected]
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.

2 participants