-
Notifications
You must be signed in to change notification settings - Fork 30
feat: flagd provider basic functionality #31
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: flagd provider basic functionality #31
Conversation
Signed-off-by: Benjamin Evenson <[email protected]> Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
2bb8961
to
aa8b6ca
Compare
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
I'll be looking at this today/tomorrow. Thanks @bacherfl ! |
Signed-off-by: Todd Baert <[email protected]>
47f7160
to
b6cfdb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow @bacherfl and @benjiro ! Nice work. I think this looks good for a alpha release. I think the only thing I would like to see addressed in this PR would be changes to just throw in error conditions instead of manually returning the default - the SDK does that for us. Your tests look good to me as well. Quick question - did you manually test this as well with a small sample app of some kind? We will soon write integration tests using this provider in the dotnet SDK, so it will get tested rigorously eventually... I'm just wondering.
One other thing I will do is make sure to set this as a - this is already done.0.0.1
release (if I don't do that, it will default to 1.0.0
, which I'm sure we don't want at the moment). I can do this with changes to the release manifest, so don't worry and let me handle that part once we are otherwise set to merge!
The other things to do are:
- automatically generate the grpc assets
- add an LRU cache
- automatic config via environment variables
- Unix socket support
- TLS support
I will create separate issues for these, and anyone can do them. Really great work, again!
// <auto-generated> | ||
// Generated by the protocol buffer compiler. DO NOT EDIT! | ||
// source: schema/v1/schema.proto | ||
// </auto-generated> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you see some reason not to, I would .gitignore all this generated code and simply make sure the build reliably produces it. Again something we don't have to do now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, having this in the .gitignore definitely makes sense! I will try to get the files being generated on demand by the build and will let you know if I manage to do it in this PR, or if i need to do some more research + an extra PR to set this up in a more tidy way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, I think I managed to do it :) the Grpc client is now generated during the build, based on the .proto file in the imported submodule. @toddbaert do you know if in the build pipeline all git submodules are pulled when checking out the code? If not, i think this might need to be adapted to make the build + tests pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done it.
} | ||
catch (Grpc.Core.RpcException e) | ||
{ | ||
return GetDefaultWithException<bool>(e, flagKey, defaultValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify the logic here a bit just to throw an informative error (you still make need to set the correct error code). The SDK itself will always handle any errors by defaulting. The most straightforward thing for a provider to do is simply throw an error with the correct code. https://github.com/open-feature/dotnet-sdk/blob/main/src/OpenFeature/Error/FeatureProviderException.cs
https://docs.openfeature.dev/docs/reference/concepts/provider#how-should-i-handle-error-conditions
This will be slightly easier when this is done, but you can do it now by just setting the right error type on the existing generic error class.
Hi @toddbaert thanks a lot for the review! I will address your comments as soon as possible and will keep you updated when I have pushed my changes! Regarding your question: I did do a quick manual test by running flagd locally and using the SDK with the Flagd provider registered (i.e. the example from the readme) - will do that again once I have made all adaptations to make sure everything works as expected :) |
Signed-off-by: Florian Bacher <[email protected]>
…codes Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
<PackageReference Include="Grpc.Tools" Version="2.51.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this!
My only (minor) suggestion here is to move this and the ItemGroup
element referencing the .proto
file together, and add a little comment on how this generates the sources.
# Flagd Feature Flag .NET Provider | ||
|
||
Coming soon! | ||
The Flagd Flag provider allows you to connect to your Flagd instance. | ||
|
||
# .Net SDK usage | ||
|
||
## Install dependencies | ||
|
||
The first things we will do is install the **Open Feature SDK** and the **GO Feature Flag provider**. | ||
|
||
### .NET Cli | ||
```shell | ||
dotnet add package OpenFeature.Contrib.Providers.Flagd | ||
``` | ||
### Package Manager | ||
|
||
```shell | ||
NuGet\Install-Package OpenFeature.Contrib.Providers.Flagd | ||
``` | ||
### Package Reference | ||
|
||
```xml | ||
<PackageReference Include="OpenFeature.Contrib.Providers.Flagd" /> | ||
``` | ||
### Packet cli | ||
|
||
```shell | ||
paket add OpenFeature.Contrib.Providers.Flagd | ||
``` | ||
|
||
### Cake | ||
|
||
```shell | ||
// Install OpenFeature.Contrib.Providers.Flagd as a Cake Addin | ||
#addin nuget:?package=OpenFeature.Contrib.Providers.Flagd | ||
|
||
// Install OpenFeature.Contrib.Providers.Flagd as a Cake Tool | ||
#tool nuget:?package=OpenFeature.Contrib.Providers.Flagd | ||
``` | ||
|
||
## Using the FlagdProvider with the OpenFeature SDK | ||
|
||
This example assumes that the flagd server is running locally | ||
For example, you can start flagd with the following example configuration: | ||
|
||
```shell | ||
flagd start --uri https://raw.githubusercontent.com/open-feature/flagd/main/config/samples/example_flags.json | ||
``` | ||
|
||
When the flagd service is running, you can use the SDK with the FlagdProvider as in the following example console application: | ||
|
||
```csharp | ||
using OpenFeature.Contrib.Providers.Flagd; | ||
|
||
namespace OpenFeatureTestApp | ||
{ | ||
class Hello { | ||
static void Main(string[] args) { | ||
var flagdProvider = new FlagdProvider(new Uri("http://localhost:8013")); | ||
|
||
// Set the flagdProvider as the provider for the OpenFeature SDK | ||
OpenFeature.Api.Instance.SetProvider(flagdProvider); | ||
|
||
var client = OpenFeature.Api.Instance.GetClient("my-app"); | ||
|
||
var val = client.GetBooleanValue("myBoolFlag", false, null); | ||
|
||
// Print the value of the 'myBoolFlag' feature flag | ||
System.Console.WriteLine(val.Result.ToString()); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Configuring the FlagdProvider | ||
|
||
The URI of the flagd server to which the `FlagdProvider` connects to can either be passed directly to the constructor, or be configured using the following environment variables: | ||
|
||
| Option name | Environment variable name | Type | Default | Values | | ||
| --------------------- | ------------------------------- | ------- | --------- | ------------- | | ||
| host | FLAGD_HOST | string | localhost | | | ||
| port | FLAGD_PORT | number | 8013 | | | ||
| tls | FLAGD_TLS | boolean | false | | | ||
|
||
So for example, if you would like to pass the URI directly, you can initialise it as follows: | ||
|
||
```csharp | ||
var flagdProvider = new FlagdProvider(new Uri("http://localhost:8013")); | ||
``` | ||
|
||
Or, if you rely on the environment variables listed above, you can use the empty costructor: | ||
|
||
|
||
```csharp | ||
var flagdProvider = new FlagdProvider(); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to say except great work!
Signed-off-by: Todd Baert <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
d734bfc
to
27f592f
Compare
Signed-off-by: Todd Baert <[email protected]>
c7e13b1
to
8877ada
Compare
@bacherfl Amazing work! Everything seems to work great. I made very some small changes (and one suggestion above):
I think we are done here 😎 . I can't thank you enough for your help. |
#if NETSTANDARD2_0 | ||
return new Service.ServiceClient(GrpcChannel.ForAddress(url)); | ||
#else | ||
return new Service.ServiceClient(GrpcChannel.ForAddress(url, new GrpcChannelOptions | ||
{ | ||
HttpHandler = new WinHttpHandler() | ||
})); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjiro does this look right to you? It seems to pass in all the test scenarios now (462 was previously failing).
Signed-off-by: Florian Bacher <[email protected]>
Thanks @toddbaert for the review and your help! I just pushed the suggested changes with regards to the .csproj file, so the PR should be good to go :) |
feat: implement the flagd provider Signed-off-by: Florian Bacher <[email protected]> Co-authored-by: Benjamin Evenson <[email protected]> Co-authored-by: Todd Baert <[email protected]> Signed-off-by: Vladimir Petrusevici <[email protected]>
This PR builds upon the work that @benjiro did with regards to the Flagd implementation. In this PR, I added the Readme, added the remaining xml doc comments and added Unit tests.