flagr icon indicating copy to clipboard operation
flagr copied to clipboard

[Feature Request] GetFlagByKey (or similar) endpoint

Open wildefires opened this issue 5 years ago • 4 comments

Expected Behavior

There should be an endpoint, and corresponding functions in the various client libraries, that allows you to get a flag based on its unique key.

Current Behavior

Currently, as far as I know, the only way to 'get' a single flag is by its numeric ID. The only other alternative is to use the FindFlags function, which has a lot more overhead (FindFlagsOpts, pulling the first entry, checking yourself that there aren't more than one)

Possible Solution

New func that either:

  • More or less reimplements GetFlag but for a string on the key instead of the ID
  • Calls FindFlags and returns the singular result or returns an error if no results
    • This solution would require more processing since FindFlags uses like so we may get multiple results where 0 or many of them match the query string

Context

Want a more concise way (in terms of lines of code) to find a flag based on its key.

Basically would turn

	ffo := goflagr.FindFlagsOpts{
		Key:     optional.NewString("flagr/test-flag"),
		Preload: optional.NewBool(true),
	}
	
	flags, _, _ := apiClient.FlagApi.FindFlags(nil, &ffo)
	myFlag = flags[0]

Into

	myFlag = apiClient.FlagApi.GetFlagByKey(nil, "flagr/test-flag")

wildefires avatar Jan 31 '20 23:01 wildefires

Willing to take this on myself, but curious about your thoughts on approach @zhouzhuojie

wildefires avatar Feb 01 '20 00:02 wildefires

Thinking of the API design, there are many options (see below), and / in the flagKey can cause some confusion in the URL, wondering if URL encoded string is needed here.

GET /api/v1/flag_keys/<key>
GET /api/v1/flag_by_key/<key>
GET /api/v1/flags?key=<key>

The other option is to keep the api, but add your own utility function and consolidate several lines of FindFlags into a single function. flagKey is already indexed, so I think the performance is not a problem.

zhouzhuojie avatar Feb 01 '20 01:02 zhouzhuojie

and / in the flagKey can cause some confusion in the URL

I agree. It'll either need to be properly URL encoded or we could make this particular GET endpoint accept a JSON body with the string as part of that body

add your own utility function

I'm not opposed to this idea necessarily, but it does require more processing overhead on both the client side and server side to do so - as the server has to get more items from the DB than it needs and then the client has to filter through them

wildefires avatar Feb 04 '20 20:02 wildefires

add your own utility function

I'm not opposed to this idea necessarily, but it does require more processing overhead on both the client side and server side to do so - as the server has to get more items from the DB than it needs and then the client has to filter through them

Do you have high volume of traffic that needs to use GET flag by key? Usually, this endpoint is used by admins to look at the dashboard. The high volume of traffic should directly go to the evaluation endpoints.

zhouzhuojie avatar Feb 05 '20 01:02 zhouzhuojie

Stale issue message

github-actions[bot] avatar Aug 26 '22 21:08 github-actions[bot]