Code Monkey home page Code Monkey logo

go-sdk's People

Contributors

beeme1mr avatar davejohnston avatar davidphirsch avatar diegomarangoni avatar github-actions[bot] avatar james-milligan avatar kavindu-dodan avatar kunde21 avatar odubajdt avatar paddycarver avatar rcrowe avatar renovate[bot] avatar rgrassian-split avatar skyerus avatar thomaspoignant avatar toddbaert avatar yongruilin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sdk's Issues

Evaluation Context Handling

In previous versions of the Golang-sdk EvaluationContext has been defined as an interface{}. In this commit it has been updated to a struct containing required fields (currently just TargetingKey but likely to grow) with a nested map[string]interface{} under the Attributes field, to better comply to the spec.

I believe this may cause issues down the line for client applications needing to know if their properties are on the base struct or in the additional properties.

if evCtx.Yellow == true {
    return 'yellow'
}

turns into

if evCtx.Attributes.Yellow == true {
    return 'yellow'
}

Following conversations with @skyerus we have identified 3 possible ways to resolve this, though this list likely isn't exhaustive:

  1. Do nothing and handle the nesting within providers
  2. Flatten the structure into a map[string]interface{} as standard and update the provider interface method signatures to reflect this
  3. Offer a before hook that will flatten the structure (would require provider hooks), similar outcome to doing nothing, but the hook would be directly linked to the sdk

Please let me know your thoughts

EDIT by @toddbaert :

Seems like we have a consensus, I will take this issue and action it.

Add `context.Context` as first parameters to client/provider calls

Apologies if this has already been discussed.

I may be missing something, but is it possible to add Go's context.Context as a first parameter to all client/provider methods (interface definitions)?

Ex:

BooleanValue(flag string, defaultValue bool, evalCtx EvaluationContext, options EvaluationOptions) (bool, error)

would become something like:

BooleanValue(ctx context.Context, flag string, defaultValue bool, evalCtx EvaluationContext, options EvaluationOptions) (bool, error)

It seems as a user of this SDK that I would want to be able to use context to pass request timeouts upstream to the provider (ie: in case request to provider is taking too long to return, error which would return the 'default' value).

Is this meant to be done via a Hook per request? If so would it be possible to document this usage?

Although it still seems that passing context.Context as a first class (first) parameter would be ideal IMO since it is a Go convention.

[FEATURE] Split hook interfaces

Requirements

Currently, anyone who wants to create a new hook is forced to implement all of the hook interface

type Hook interface {
	Before(hookContext HookContext, hookHints HookHints) (*EvaluationContext, error)
	After(hookContext HookContext, flagEvaluationDetails EvaluationDetails, hookHints HookHints) error
	Error(hookContext HookContext, err error, hookHints HookHints)
	Finally(hookContext HookContext, hookHints HookHints)
}

This is cumbersome, an alternative is to split this into an interface for each func and assert the given hook to each interface.
This makes application author's lives easier at the cost of marginally more complexity in the sdk and some type assertions.

I think this is a worthwhile trade, thoughts? @beeme1mr @toddbaert @james-milligan

[FEATURE] Improve default error logging

Requirements

By default the leveled logger is only outputting errors, via log.Println(err), which in turn calls the ProviderResolutionDetail.Error().

This combination means you end up with logs that look like 2022/10/07 09:09:08 GENERAL because only the error code is returned by Error().

My preference would be to not log anything like the other levels do; Error(...) would be noop, leaving this to userland to decide what they want logging using SetLogger. If not, perhaps the message should include more details & make it clear(er) where it originates from, as when interleaved with other logs it makes hunting the cause down tricky.

Wanted to gather any thoughts & opinions first, but I'd be happy to attempt a PR depending on the outcome of this issue. Felt like a sharp edge and we could improve the out-of-the-box experience.

[BUG] When calling client.ObjectValueDetails with a value as nil the ResolutionDetail are not accessible.

Observed behavior

I am using nil as a default value while calling client.ObjectValueDetails but when doing this everytime if the default value is used we receive no ResolutionDetail from the SDK.

After looking a bit at the SDK it seems that we add the ResolutionDetail only if the value is not nil.

if resolution.Value != nil {

It means that we cannot use nil as value in the SDK.

Expected Behavior

I would like to be able to use nil as value for my flag.

Steps to reproduce

SDK return a flag with a nil value.

Automate Release Process

Requirements

  • Create a GitHub release automatically based on a git tag
  • The git tag should match v*.*.* and follow semver guidelines.
  • Breaking changes should be represented in PRs and Release notes
  • Breaking changes should NOT bump major version numbers until a 1.0 release
  • #89

Golang 1.18 Upgrade Discussion

Overview

Golang 1.18 introduces generics, which would be useful for the Golang OpenFeature SDK. However, since1.18 is only a few months old we need to way the pros and cons of switching.

Golang Alpha SDK

Alpha Checklist:

  • spec compliant
  • contains test suite which verifies behavior consistent with spec
  • #10
  • #11
  • comprehensive readme

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/pr-checks.yml
  • actions/setup-go v4
  • actions/checkout v4
  • actions/cache v4
  • actions/setup-go v4
  • actions/checkout v4
  • actions/cache v4
  • codecov/codecov-action v3
.github/workflows/pr-lint.yml
  • amannn/action-semantic-pull-request v5
  • marocchino/sticky-pull-request-comment v2
  • marocchino/sticky-pull-request-comment v2
.github/workflows/release-please.yml
  • google-github-actions/release-please-action v3
  • actions/checkout v4
  • actions/setup-go v4
  • CycloneDX/gh-gomod-generate-sbom v1
  • goreleaser/goreleaser-action v4
gomod
go.mod
  • go 1.19
  • github.com/cucumber/godog v0.14.0
  • github.com/go-logr/logr v1.4.1
  • github.com/golang/mock v1.6.0
  • golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3@2c58cdc269a3
  • golang.org/x/text v0.14.0

  • Check this box to trigger a request for Renovate to run again on this repository

Evaluation Details Value Type

The evaluation details value type should correspond to the method called by the user. For example, if the user is calling the bool details method, the value should be a boolean.

[FEATURE] Support logging

Requirements

Define a logger interface that conforms to Go's most prevalent logging idioms (look at most popular libraries).

Allow an application author to set the sdk's logger at global level (and client level?).

Add logging at all levels in the sdk (debug, info, warn, error).

cc @beeme1mr @toddbaert

[BUG] Typed ResolutionDetail structs have mulitple different `Value` values

Observed behavior

Looking at https://github.com/open-feature/golang-sdk/blob/main/pkg/openfeature/provider.go#L65-L68 and running the code, it is possible for a provider to return a struct for BoolResolutionDetail where there are two different Value elements, with different values.

eg
image

It's been a while since I've done go coding, and this may be idiomatic, but to me it's confusing

Expected Behavior

You should only be able to set one Value value

Steps to reproduce

	thing := openfeature.BoolResolutionDetail{
		Value: true,
		ResolutionDetail: openfeature.ResolutionDetail{
			Value: false,
		},
	}

[FEATURE] Ensure thread safety of sdk

Requirements

Inspired by open-feature/dotnet-sdk#56

The global singletons (e.g. provider, evaluationContext, logger) all share a mutex to ensure thread safety, however a client doesn't use a mutex so there's a concern if two processes want to set an evaluation context for example.

The EvaluationContext type has the field Attributes of type map[string]interface{}. In go, maps are always passed by reference, this means that in theory one could pass an EvaluationContext to a client's flag evaluation call and continue to alter the Attributes' map in another process.
This could be avoided by making the Attributes field unexported with an exported constructor for EvaluationContext, this would mean that an application author couldn't change the field once constructed. However, an author could still alter the map they passed as a parameter to the constructor, which is the same map used in struct (passed by reference). In order to avoid this the constructor would need to initialise a new map and copy the map passed as a parameter.

Is this overkill? Is there a better solution we can come up with?

cc @beeme1mr @toddbaert @james-milligan

Update SDK to be compliant with spec v0.5.0

Update the SDK to be compliant with the v0.5.0 spec.

What's Changed

โš  BREAKING CHANGES

Additional changes

General

  • Add/update a spec version badge on the readme.

Specification

Full Changelog: open-feature/spec@v0.4.0...v0.5.0

Add error code test

Add a test that ensures an error code is included in the evaluation details when the provider has an issue.

#67

Add requirement definition from spec to each test as a comment

The current test suite names each test like so:

func TestRequirement_1_2_1(t *testing.T) {}

We'd like to change this to include a comment of the spec requirement:

// The client MUST provide a method to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks.
// When new hooks are added, previously added hooks are not removed.
func TestRequirement_1_2_1(t *testing.T) {}

Rename getters to be more inline with Golang idioms

Currently there are getters defined that are prefixed with Get e.g.

GetBooleanValue(flag string, defaultValue bool, evalCtx EvaluationContext, options EvaluationOptions) (bool, error)

This goes against Golang convention. Renaming this example to just BooleanValue would be better practice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.