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

Client can not connect to Proxy #68

Closed
dirsigler opened this issue Nov 28, 2023 · 3 comments
Closed

Client can not connect to Proxy #68

dirsigler opened this issue Nov 28, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@dirsigler
Copy link

Describe the bug

We are currently evaluating the use of the ConfigCat Proxy in our environment to reduce the network traffic and config download stress issued against the ConfigCat platform.

During the evaluation I faced some issues with basic connectivity with a sample Golang application.
As demonstrated in the Proxy documentation I started a local Proxy Container instance containing a demo SDK Key with identifier.
Then to verify the Client connection I wrote simple Golang application, initialising the ConfigCat client with the Proxy as BaseURL and my Key identifier.

During client registration I see following error message:

go run .
INFO[0000] [0] fetching from http://127.0.0.1:8050
ERRO[0000] [1103] config fetch failed: unexpected error occurred while trying to fetch config JSON: Get "http://127.0.0.1:8050/configuration-files/my_demo/config_v5.json": context canceled

To reproduce

Create a ConfigCat config with a FeatureFlag. In my case a TextFlag with "Hello World!" as string.

  1. First spin up the proxy locally
docker run -d --name configcat-proxy \
-p 8050:8050 -p 8051:8051 -p 50051:50051 \
-e CONFIGCAT_SDKS='{"my_demo":"YOUR_ORG/SOME_SECRET_KEY"}' \
-e CONFIGCAT_LOG_LEVEL="debug" \
configcat/proxy
  1. Start a Golang Client.
    In this example I made it a little HTTP server because it was further used in Docker Compose to verify the stack, but running as go run . should do fine.
package main

import (
	"fmt"
	"log"
	"net/http"

	configcat "github.com/configcat/go-sdk/v8"
)

type application struct {
	client *configcat.Client
}

func (app *application) featureFlagHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("received call")

	allVals := app.client.GetAllValues(nil)

	for k, v := range allVals {
		fmt.Fprintf(w, "Got Key: %s\n Got Value: %v", k, v)
	}

	app.client.Close()
}

func main() {
	mux := http.NewServeMux()

	client := configcat.NewCustomClient(
		configcat.Config{
			BaseURL: "http://127.0.0.1:8050",
			SDKKey:  "my_demo",
			Logger:  configcat.DefaultLogger(configcat.LogLevelDebug),
		},
	)

	app := application{
		client: client,
	}

	mux.HandleFunc("/flag", app.featureFlagHandler)

	err := http.ListenAndServe(":8080", mux)
	if err != nil {
		log.Fatalf("failed to start HTTP server")
	}
}

Expected behavior

The Golang application should connect to the proxy and access the FeatureFlag.

Currently solutions via curl and python work as expected locally:

curl http://127.0.0.1:8050/configuration-files/my_demo/config_v5.json -X GET
{"f":{}}%

curl -I http://127.0.0.1:8050/configuration-files/my_demo/config_v5.json -X GET
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Length,ETag,Date,Content-Encoding
Cache-Control: max-age=0, must-revalidate
Content-Type: application/json
Etag: W/"7cd89cdf0f515b44"
Date: Tue, 28 Nov 2023 12:05:35 GMT
Content-Length: 132
#!/usr/bin/env python3

import configcatclient

client = configcatclient.get('my_demo',
    configcatclient.ConfigCatOptions(
        polling_mode=configcatclient.PollingMode.auto_poll(),
        base_url='http://127.0.0.1:8050'
    )
)

value = client.get_value(
    'MY_FEATURE_FLAG',
    False,
)

print(value)
python main.py
Hello World!

Screenshots

@dirsigler dirsigler added the bug Something isn't working label Nov 28, 2023
@z4kn4fein
Copy link
Member

Hi @dirsigler, thank you for reporting this issue! I'm going to investigate what's going wrong and let you know here about the results.

@z4kn4fein
Copy link
Member

z4kn4fein commented Nov 29, 2023

Hi @dirsigler, I've released a new version from the Proxy (v0.2.4). I've identified an issue related to the GZip compression of HTTP responses which is utilized by Go's http client by default. Other platforms you mentioned possibly not requested the response compressed so they got it correctly.

Could you please check the latest Proxy version that it works on your end as expected? Thanks!

@dirsigler
Copy link
Author

Impressive work!

At least for my local test stack this solution works without any problems. Therefore I would assume this issue closed.
Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants