go-feature-flag icon indicating copy to clipboard operation
go-feature-flag copied to clipboard

(bug) [relay-proxy] Override configuration via env variables in `retrievers` does not work

Open thomaspoignant opened this issue 9 months ago • 5 comments

Observed behaviour

When running the relayproxy it is possible to override the configuration file using environment variables. If the configuration to override is inside an array it is not possible to override it.

This is particularly true when dealing with secrets as mentioned in #1822.

With the current implementation of koanf this is not working well, we should consider following what is proposed in this issue https://github.com/knadh/koanf/issues/74.

Expected Behavior

We want to be able to override a property from the key retrievers with an environment variable.

Something like

export RETRIEVERS_0_HEADERS_AUTHORIZATION=Bearer xxx

thomaspoignant avatar May 03 '24 16:05 thomaspoignant

Hi @thomaspoignant , I try to fix it, but I've found a bug in local, when I set yaml in the local:

listen: 1031
pollingInterval: 1000
startWithRetrieverError: false
retriever:
  kind: http
  url: https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.goff.yaml
retrievers:
   - kind: file
     path: examples/retriever_file/flags.goff.yaml
  - kind: file
    path: examples/retriever_file/flags.goff.yaml

exporter:
  kind: log
enableSwagger: true
authorizedKeys:
  evaluation:
    - apikey1 # owner: userID1
    - apikey2 # owner: userID2
  admin:
    - apikey3

the retrievers of config can't load from the yaml file.

luanxuechao avatar May 15 '24 08:05 luanxuechao

@luanxuechao from your example I see an indentation issue in your file on the providers. Can you try this one instead?

listen: 1031
pollingInterval: 1000
startWithRetrieverError: false
retriever:
  kind: http
  url: https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/examples/retriever_file/flags.goff.yaml
retrievers:
  - kind: file
    path: examples/retriever_file/flags.goff.yaml
  - kind: file
    path: examples/retriever_file/flags.goff.yaml

exporter:
  kind: log
enableSwagger: true
authorizedKeys:
  evaluation:
    - apikey1 # owner: userID1
    - apikey2 # owner: userID2
  admin:
    - apikey3

Can you double check if this will solve your issue?

thomaspoignant avatar May 15 '24 09:05 thomaspoignant

Hi @thomaspoignant, it doesn't work. I run the relayproxy/main.go with goff-proxy.yaml, and debug it. I'm new developer of golang. I also can reproduce it with json config. go version is: go version go1.22.3 darwin/arm64 image

luanxuechao avatar May 15 '24 09:05 luanxuechao

@luanxuechao I've tried the same file as you and I don't reproduce. What I have done:

  1. copy/paste the file (the one edited by myself in the previous comment) in the root directory of go-feature-flag.
  2. Start the relay-proxy in IntelliJ (inside cmd/relay-proxy/main.go).
  3. Add a debugger point at this line: https://github.com/thomaspoignant/go-feature-flag/blob/c982515036ac93cf99312341fb3b7f2ef438e41e/cmd/relayproxy/main.go#L96
  4. Here is the output I got: Screenshot 2024-05-15 at 12 31 58

thomaspoignant avatar May 15 '24 10:05 thomaspoignant

@luanxuechao if you want you can also join the slack channel https://gofeatureflag.org/slack and we can discuss about your issue there.

thomaspoignant avatar May 15 '24 11:05 thomaspoignant