Skip to content

Context-aware methods to ProviderClient and ServiceClient - #2883

Merged
pierreprinetti merged 1 commit into
gophercloud:masterfrom
shiftstack:context
Feb 2, 2024
Merged

pierreprinetti merged 1 commit into
gophercloud:masterfrom
shiftstack:context

Conversation

@pierreprinetti

@pierreprinetti pierreprinetti commented Jan 31, 2024 •

Copy link
Copy Markdown
Member

Provide new methods to leverage per-call context.Context.

In the http.Request resulting from using these new context-aware calls, the per-call context values take precendence over the ProviderClient's.

Cancellation obeys both the per-call context and the ProviderClient's.

@github-actions github-actions Bot added the semver:major Breaking change label Jan 31, 2024
@github-actions github-actions Bot added semver:major Breaking change and removed semver:major Breaking change labels Jan 31, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:major Breaking change labels Jan 31, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Jan 31, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Jan 31, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Jan 31, 2024
@coveralls

coveralls commented Jan 31, 2024 •

Copy link
Copy Markdown

Coverage Status

coverage: 77.863% (-0.04%) from 77.904%
when pulling b49ce37 on shiftstack:context
into d8db226 on gophercloud:master.

@pierreprinetti
pierreprinetti marked this pull request as ready for review January 31, 2024 13:23
@pierreprinetti
pierreprinetti requested a review from a team January 31, 2024 14:56
@pierreprinetti

Copy link
Copy Markdown
Member Author

EmilienM
EmilienM previously approved these changes Jan 31, 2024
@pierreprinetti
pierreprinetti marked this pull request as draft January 31, 2024 19:04
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
@pierreprinetti
pierreprinetti marked this pull request as ready for review February 1, 2024 12:26
@pierreprinetti

Copy link
Copy Markdown
Member Author

One last change: Moved the context-merging function to an internal package, so that it doesn't add to Gophercloud's API.

@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
@github-actions github-actions Bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 1, 2024
EmilienM
EmilienM previously approved these changes Feb 1, 2024

@mandre mandre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pierreprinetti, I don't think that dropping the values from the second context is a big problem in practice so I'm fine starting with the current implementation and revisit if we find this is a blocking issue. This is already a huge step forward.

Comment thread provider_client.go Outdated

// Context is the context passed to the HTTP request.
// Context is the context passed to the HTTP request. Values set on the
// per-call context, when available, override valus set on this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a nit, feel free to ignore.

Suggested change
// per-call context, when available, override valus set on this
// per-call context, when available, override values set on this

Comment thread internal/ctxt/merge_test.go Outdated
t.Run("returns values from both parents", func(t *testing.T) {
ctx, cancel := ctxt.Merge(
context.WithValue(context.Background(), "key1", "value1"),
context.WithValue(context.Background(), "key2", "value2"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you perhaps also check that the value from the first context takes precedence when the second context holds the same key? If this is a behavior that we're going to support, then we should have tests for it so that we avoid regressions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is a good idea, thanks

Provide new methods to leverage per-call `context.Context`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:minor Backwards-compatible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants