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

Better example? #24

Open
HenrikDK opened this issue Feb 5, 2024 · 3 comments
Open

Better example? #24

HenrikDK opened this issue Feb 5, 2024 · 3 comments

Comments

@HenrikDK
Copy link

HenrikDK commented Feb 5, 2024

Hi

I'm evaluating using Flipt.io for use with my C# apps, while im somewhat dissapointed that a C# sdk didn't get first billing like python or java. I'm glad to see that a Grpc SDK is underway :)

I am confused by the example provided though:

using Grpc.Net.Client;
using Flipt;

var channel = GrpcChannel.ForAddress("http://localhost:9000");
var client = new Flipt.Flipt.FliptClient(channel);
var result = client.ListFlags(new Flipt.ListFlagRequest());

System.Console.WriteLine("Available Flags:");
foreach (var flag in result.Flags)
{
    System.Console.WriteLine(flag.Key);
}

It hard to get an idea of how the client works in a real usecase, as a typical client isn't interested in listing all flags and iterating through them?

Normally you would evaluate a specific flag that you address by name, and maybe provide other variables.

I had expected an example like the python one here https://github.com/flipt-io/flipt-server-sdks/tree/main/flipt-python

from flipt import FliptClient
from flipt.evaluation import BatchEvaluationRequest, EvaluationRequest

fliptClient = FliptClient()

v = fliptClient.evaluation.variant(
    EvaluationRequest(
        namespace_key="default",
        flag_key="flagll",
        entity_id="entity",
        context={"fizz": "buzz"},
    )
)

print(v)
@GeorgeMac
Copy link
Member

GeorgeMac commented Feb 5, 2024

Hey @HenrikDK 👋 Thanks for raising the issue and apologies for the lack of clarity in our docs. We lack any C# experience on the Flipt team, so could do with any and all help in getting something correct together.

I've just taken a stab at an alternative, which is more inline with our Python example you linked here.
What do you think of it:

using Grpc.Net.Client;
using Flipt;

namespace dotnetexperiment;

class Program
{
    static void Main(string[] args)
    {
        var channel = GrpcChannel.ForAddress("http://localhost:9000");
        var client = new Flipt.Evaluation.EvaluationService.EvaluationServiceClient(channel);
        var request = new Flipt.Evaluation.EvaluationRequest {
            NamespaceKey = "default",
            FlagKey      = "flag",
            EntityId     = "entity",
        };
        request.Context.Add("fizz", "buzz");

        System.Console.WriteLine(client.Variant(request));
    }
}

I tested it locally and it evaluated as expected. If you think it fits the bill, I can get the docs and example updated.

@HenrikDK
Copy link
Author

HenrikDK commented Feb 5, 2024

That looks better, much clearer :) 👍 from here.

It could also be an idea to very explicitly illustrate usage in application code, ie how you fork your code based on a usage flag:

Something like this.

using Grpc.Net.Client;
using Flipt;

var channel = GrpcChannel.ForAddress("http://localhost:9000");
var flipt= new Flipt.Evaluation.EvaluationService.EvaluationServiceClient(channel);
var newHotFeature = new Flipt.Evaluation.EvaluationRequest {
            NamespaceKey = "default",
            FlagKey      = "NewHotFeature",
            EntityId     = "entity",
};
newHotFeature.Context.Add("fizz", "buzz");


if(flipt.Variant(newHotFeature).Match)
{
  //new code
}
else
{
  //old code
}

While not quite as elegant as other feature toggle solutions out there, it's not unworkable :)

@markphelps
Copy link
Contributor

Thanks for the feedback and for raising this issue @HenrikDK 🙌🏻

We will update the readme now!

Re @GeorgeMac 's comment:

We lack any C# experience on the Flipt team, so could do with any and all help in getting something correct together.

If you can help contribute a REST evaluation SDK or potentially help us get started that would be amazing! As we have done very little C# dev on the team and would want someone with greater C# expertise to make it idiomatic

See: flipt-io/flipt-server-sdks#86

GeorgeMac added a commit that referenced this issue Feb 5, 2024
Supports #24

Update the README to focus the illustration on how to evaluation a feature flag.
GeorgeMac added a commit that referenced this issue Feb 5, 2024
Supports #24 

Update the basic example in line withe the README update.
This centers the example around evaluation, instead of listing flags.
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

No branches or pull requests

3 participants