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

Using getFlag and findFlags in python and go clients returns non-matching objects #294

Closed
wildefires opened this issue Oct 10, 2019 · 2 comments

Comments

@wildefires
Copy link

wildefires commented Oct 10, 2019

Expected Behavior

What should happen:

In go, the following two blocks of code should set flag to be an identical object

	ffo := goflagr.FindFlagsOpts{
		Key: optional.NewString("my_test_flag"),
	}

	flags, _, err := apiClient.FlagApi.FindFlags(nil, &ffo)
        flag := flags[0]
	flag, _, err := apiClient.FlagApi.GetFlag(nil, 3)

Current Behavior

The first block of code above, using the FindFlags returns the same flag. However, the object returned does not have its Variants field populated when used with FindFlags (but it is populated with GetFlag)

Possible Solution

Steps to Reproduce (for bugs)

The following main.go file, when run will error out in FlagByName with the error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.FlagByName()
        .../main.go:51 +0x464
main.main()
       .../main.go:9 +0x37

Debugger finished with exit code 0

If you comment out the call to FlagByName, it will succeed (and the code after flag := flags[0] is identical between the two)

package main

import (
	"github.com/antihax/optional"
	"github.com/checkr/goflagr"
)

func main() {
	FlagByName()
	flagrConfig := goflagr.NewConfiguration()
	flagrConfig.BasePath = "http://localhost:8080/api/v1"
	apiClient := goflagr.NewAPIClient(flagrConfig)

	myFlagEnabled := ""
	flag, _, err := apiClient.FlagApi.GetFlag(nil, 3)

	if err != nil{
		// Default to a reasonable default in case Flagr is down
		myFlagEnabled = "false"
	} else {
		myVariant := flag.Variants[0]
		myAttachment := (*myVariant.Attachment).(map[string]interface {})
		myFlagEnabled = myAttachment["value"].(string)
	}

	if myFlagEnabled == "true"{
		doMyNewThing()
	} else {
		doMyOldThing()
	}
}

func FlagByName(){
	flagrConfig := goflagr.NewConfiguration()
	flagrConfig.BasePath = "http://localhost:8080/api/v1"
	apiClient := goflagr.NewAPIClient(flagrConfig)

	ffo := goflagr.FindFlagsOpts{
		Key: optional.NewString("my_test_flag"),
	}

	flags, _, err := apiClient.FlagApi.FindFlags(nil, &ffo)
	flag := flags[0]

	myFlagEnabled := ""

	if err != nil{
		// Default to a reasonable default in case Flagr is down
		myFlagEnabled = "false"
	} else {
		myVariant := flag.Variants[0]
		myAttachment := (*myVariant.Attachment).(map[string]interface {})
		myFlagEnabled = myAttachment["value"].(string)
	}

	if myFlagEnabled == "true"{
		doMyNewThing()
	} else {
		doMyOldThing()
	}
}

func doMyNewThing(){
	return
}

func doMyOldThing(){
	return
}



Context

Your Environment

  • Version used (flagr version): Current available docker container on checkr/flagr; postgres RDS backend
  • Server type and version: running as an AWS ECS Fargate deploy
  • Operating System and version (uname -a):
  • Link to your project:
@zhouzhuojie
Copy link
Collaborator

Hey, please use the preload query param for findFlags, because preloading flags with variants and segments are expensive, thus we didn't include it in findFlags by default.

https://checkr.github.io/flagr/api_docs/#operation/findFlags

@wildefires
Copy link
Author

Thanks for that! I seem to have missed those API docs, that'll be a good resource for me going forwards.

Using Preload: optional.NewBool(true), in the options works like a charm. Thanks again!

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

2 participants