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

feat!: add CancellationTokens, ValueTasks hooks #268

Merged
merged 11 commits into from
Jun 17, 2024
Merged

feat!: add CancellationTokens, ValueTasks hooks #268

merged 11 commits into from
Jun 17, 2024

Conversation

toddbaert
Copy link
Member

@toddbaert toddbaert commented May 1, 2024

This PR is a combination of #184 and #185. Changes include:

  • adding cancellation tokens
    • in all cases where async operations include side-effects (setProviderAsync, InitializeAsync, I've specified in the in-line doc that the cancellation token's purpose is to cancel such side-effects - so setting a provider and canceling that operation still results in that provider's being set, but async side-effect should be cancelled. I'm interested in feedback here, I think we need to consider the semantics around this... I suppose the alternative would be to always ensure any state changes only occur after async side-effects, if they weren't cancelled beforehand.
  • adding "Async" suffix to all async methods
  • remove deprecated sync SetProvider methods
  • Using ValueTask for hook methods

    the default choice for any asynchronous method that does not return a result should be to return a Task. Only if performance analysis proves it worthwhile should a ValueTask be used instead of a Task.

    • I think for hooks, ValueTask especially makes sense since often hooks are synchronous, in fact async hooks are probably the less likely variant.
    • I've kept the resolver methods as Task, but there could be an argument for making them ValueTask, since some providers resolve asynchronously.
    • I'm still a bit dubious on the entire idea of ValueTask, so I'm really interested in feedback here
  • associated test updates

UPDATE:

After chewing on this for a night, I'm starting to feel:

  • We should simply remove cancellation tokens from Init/Shutdown. We can always add them later, which would be non-breaking. I think the value is low and the complexity is potentially high.
  • ValueTask is only a good idea for hooks, because:
    • Hooks will very often be synchronous under the hood
    • We (SDK authors) await the hooks, not consumer code, so we can be careful of the potential pitfalls of ValueTask. I think everywhere else we should stick to Task.

@toddbaert toddbaert requested a review from a team as a code owner May 1, 2024 18:34
@toddbaert toddbaert changed the title Value task feat!: add CancellationTokens, ValueTasks to various interfaces May 1, 2024
Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

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

I left a few comments. It is a big diff, but most of it is just renaming.

Overall it looks good but I added some of my concerns.

README.md Show resolved Hide resolved
src/OpenFeature/Api.cs Outdated Show resolved Hide resolved
src/OpenFeature/Api.cs Outdated Show resolved Hide resolved
src/OpenFeature/EventExecutor.cs Show resolved Hide resolved
src/OpenFeature/Model/EvaluationContext.cs Outdated Show resolved Hide resolved
@toddbaert toddbaert requested a review from askpt May 2, 2024 13:42
@toddbaert
Copy link
Member Author

toddbaert commented May 2, 2024

After chewing on this for a night, I'm starting to feel:

  • We should simply remove cancellation tokens from Init/Shutdown. We can always add them later, which would be non-breaking. I think the value is low and the complexity is potentially high.
  • ValueTask is only a good idea for hooks, because:
    • Hooks will very often be synchronous under the hood
    • We (SDK authors) await the hooks, not consumer code, so we can be careful of the potential pitfalls of ValueTask. I think everywhere else we should stick to Task.

@toddbaert toddbaert changed the title feat!: add CancellationTokens, ValueTasks to various interfaces feat!: add CancellationTokens, ValueTasks hooks May 3, 2024
Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

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

I think that we should probably have tests which have a dummy async provider that blocks evaluations until cancelled, then we should start an evaluation and cancel it to make sure all the steps happen. Maybe something similar with a hook implementation.

@toddbaert
Copy link
Member Author

I think that we should probably have tests which have a dummy async provider that blocks evaluations until cancelled, then we should start an evaluation and cancel it to make sure all the steps happen. Maybe something similar with a hook implementation.

That's a good idea. Will add.

@toddbaert toddbaert requested a review from kinyoklion May 13, 2024 18:46
austindrenski and others added 6 commits May 13, 2024 14:46
Signed-off-by: Austin Drenski <austin@austindrenski.io>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert
Copy link
Member Author

I think that we should probably have tests which have a dummy async provider that blocks evaluations until cancelled, then we should start an evaluation and cancel it to make sure all the steps happen. Maybe something similar with a hook implementation.

That's a good idea. Will add.

I've added tests for cancellation (evaluation/resolution and hooks): 036d7a4

Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

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

I left a few suggestions around the tests.
We should await the async operations, and we should not use async void but async Task.

@askpt askpt self-requested a review May 14, 2024 07:41
Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

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

Resetting my approval. Sorry! 😃

Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
toddbaert and others added 3 commits May 14, 2024 09:04
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert toddbaert merged commit 33154d2 into main Jun 17, 2024
11 checks passed
toddbaert added a commit that referenced this pull request Aug 21, 2024
🤖 I have created a release *beep* *boop*
---


##
[2.0.0](v1.5.0...v2.0.0)
(2024-08-21)

Today we're announcing the release of the OpenFeature SDK for .NET,
v2.0! This release contains several ergonomic improvements to the SDK,
which .NET developers will appreciate. It also includes some performance
optimizations brought to you by the latest .NET primitives.

For details and migration tips, check out:
https://openfeature.dev/blog/dotnet-sdk-v2

### ⚠ BREAKING CHANGES

* domain instead of client name
([#294](#294))
* internally maintain provider status
([#276](#276))
* add CancellationTokens, ValueTasks hooks
([#268](#268))
* Use same type for flag metadata and event metadata
([#241](#241))
* Enable nullable reference types
([#253](#253))

### 🐛 Bug Fixes

* Add missing error message when an error occurred
([#256](#256))
([949d53c](949d53c))
* Should map metadata when converting from ResolutionDetails to
FlagEvaluationDetails
([#282](#282))
([2f8bd21](2f8bd21))


### ✨ New Features

* add CancellationTokens, ValueTasks hooks
([#268](#268))
([33154d2](33154d2))
* back targetingKey with internal map
([#287](#287))
([ccc2f7f](ccc2f7f))
* domain instead of client name
([#294](#294))
([4c0592e](4c0592e))
* Drop net7 TFM
([#284](#284))
([2dbe1f4](2dbe1f4))
* internally maintain provider status
([#276](#276))
([63faa84](63faa84))
* Use same type for flag metadata and event metadata
([#241](#241))
([ac7d7de](ac7d7de))


### 🧹 Chore

* cleanup code
([#277](#277))
([44cf586](44cf586))
* **deps:** Project file cleanup and remove unnecessary dependencies
([#251](#251))
([79def47](79def47))
* **deps:** update actions/upload-artifact action to v4.3.3
([#263](#263))
([7718649](7718649))
* **deps:** update actions/upload-artifact action to v4.3.4
([#278](#278))
([15189f1](15189f1))
* **deps:** update actions/upload-artifact action to v4.3.5
([#291](#291))
([00e99d6](00e99d6))
* **deps:** update codecov/codecov-action action to v4
([#227](#227))
([11a0333](11a0333))
* **deps:** update codecov/codecov-action action to v4.3.1
([#267](#267))
([ff9df59](ff9df59))
* **deps:** update codecov/codecov-action action to v4.5.0
([#272](#272))
([281295d](281295d))
* **deps:** update dependency benchmarkdotnet to v0.14.0
([#293](#293))
([aec222f](aec222f))
* **deps:** update dependency coverlet.collector to v6.0.2
([#247](#247))
([ab34c16](ab34c16))
* **deps:** update dependency coverlet.msbuild to v6.0.2
([#239](#239))
([e654222](e654222))
* **deps:** update dependency dotnet-sdk to v8.0.204
([#261](#261))
([8f82645](8f82645))
* **deps:** update dependency dotnet-sdk to v8.0.301
([#271](#271))
([acd0385](acd0385))
* **deps:** update dependency dotnet-sdk to v8.0.303
([#275](#275))
([871dcac](871dcac))
* **deps:** update dependency dotnet-sdk to v8.0.400
([#295](#295))
([bb4f352](bb4f352))
* **deps:** update dependency githubactionstestlogger to v2.4.1
([#274](#274))
([46c2b15](46c2b15))
* **deps:** update dependency microsoft.net.test.sdk to v17.10.0
([#273](#273))
([581ff81](581ff81))
* **deps:** update dotnet monorepo
([#218](#218))
([bc8301d](bc8301d))
* **deps:** update xunit-dotnet monorepo
([#262](#262))
([43f14cc](43f14cc))
* **deps:** update xunit-dotnet monorepo
([#279](#279))
([fb1cc66](fb1cc66))
* **deps:** update xunit-dotnet monorepo to v2.8.1
([#266](#266))
([a7b6d85](a7b6d85))
* Enable nullable reference types
([#253](#253))
([5a5312c](5a5312c))
* in-memory UpdateFlags to UpdateFlagsAsync
([#298](#298))
([390205a](390205a))
* prompt 2.0
([9b9c3fd](9b9c3fd))
* Support for determining spec support for the repo
([#270](#270))
([67a1a0a](67a1a0a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants