open-feature / go-sdk

Go SDK for OpenFeature
https://openfeature.dev
Apache License 2.0
145 stars 34 forks source link

[BUG] Cache isn't invalidated properly #173

Closed abtris closed 1 year ago

abtris commented 1 year ago

Observed behavior

I follow tutorial https://docs.openfeature.dev/docs/tutorials/getting-started/go

and when I change value in flags.flagd.json by tutorial.

{
  "flags": {
    "welcome-message": {
      "variants": {
        "on": true,
        "off": false
      },
      "state": "ENABLED",
      "defaultVariant": "off"
    }
  }
}

to

{
  "flags": {
    "welcome-message": {
      "variants": {
        "on": true,
        "off": false
      },
      "state": "ENABLED",
      "defaultVariant": "on"
    }
  }
}

I get by debug:

{"level":"debug","v":1,"flag":"welcome-message","details":{"Value":false,"FlagKey":"welcome-message","FlagType":0,"Variant":"off","Reason":"CACHED","ErrorCode":"","ErrorMessage":""},"type":"bool","caller":"/Users/abtris/go/pkg/mod/github.com/open-feature/go-sdk@v1.3.0/pkg/openfeature/client.go:669","time":1680885925233,"message":"evaluated flag"}

The request is cached, and cache wasn't invalidated after a change in the source JSON file.

The only way how to make it work is to disable cache using the following:

openfeature.SetProvider(flagd.NewProvider(flagd.WithoutCache()))

Expected Behavior

Invalidate cache after the change in file or possibility has a cache for a defined time.

Steps to reproduce

Follow the tutorial https://docs.openfeature.dev/docs/tutorials/getting-started/go. My version of the tutorial is https://github.com/abtris/openfeature-example (I disable that cache to make a working example).

odubajDT commented 1 year ago

Hi @abtris, thank you for reporting this issue! I am going to look into it.

odubajDT commented 1 year ago

Hi @abtris, I wasn't able to reproduce the issue locally on my machine with the code you provided (removed the flagd.WithoutCache()) when creating the provider. From my POV everything seems to be working correctly.

Do you still have this issue? If yes, can we have a online session where we look at it together?

Thank you!

abtris commented 1 year ago

Hi, I re-tested today and looks that problem is gone.

Line now looks:

{"level":"debug","v":1,"flag":"welcome-message","details":{"Value":true,"FlagKey":"welcome-message","FlagType":0,"Variant":"on","Reason":"STATIC","ErrorCode":"","ErrorMessage":""},"type":"bool","caller":"/Users/lprskavec/go/pkg/mod/github.com/open-feature/go-sdk@v1.3.0/pkg/openfeature/client.go:669","time":1682514569018,"message":"evaluated flag"}
odubajDT commented 1 year ago

Great, thank you for the info. Closing this ticket.

abtris commented 1 year ago

Sure, thanks for looking into.