toefel18 / transcoding-grpc-to-http-json

Example of transcoding gRPC to HTTP/JSON using Envoy
https://blog.jdriven.com/2018/11/transcoding-grpc-to-http-json-using-envoy/
44 stars 15 forks source link

Connection refused #1

Open hanoisteve opened 5 years ago

hanoisteve commented 5 years ago

Im on Mac OS 10.13.6 and I get connection refused when I do any request against the services. I have tried changing the listener port number but still get error.

curl: (7) Failed to connect to localhost port 51051: Connection refused.

I still get this error after checking port etc. Im guessing this might be a docker thing or changes in the way envoy handles GRPC but not sure. Can someone clarify how connection refused occurs and how I can troubleshoot this?

hanoisteve commented 5 years ago

This was on my side. I had not started the ServerMain.

hanoisteve commented 5 years ago

After doing ./gradlew idea User needs to reopen the project using the generated .ipr file.

This is clear for those who have used this command before but many of us have not.

hanoisteve commented 5 years ago

After checking that Server is running. I am still seeing connection refused. I have tried various different ports without luck. Is this and Envoy issue or a docker issue. In either case, from a practical perspective this is stopping me from running the demo.

hanoisteve commented 5 years ago

Update: On a Mac running envoy with host network mode docker discards the published port numbers so that was causing the problem connecting, plus the ports were not published so not visible at all on a Mac. I am at least able to get envoy up and running with the following change to start-envoy.sh

sudo docker run -it --rm --name envoy -p 9901:9901 -p 10000:10000 \ -v "$(pwd)/reservation_service_definition.pb:/data/reservation_service_definition.pb:ro" \ -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" \ envoyproxy/envoy

However, I am not seeing that the RPC service is reached. Listing the reservations is now empty. Could you please comment on how I can get this demo running on a Mac with current envoy version?

hanoisteve commented 5 years ago

I was able to get it working reservation creation working on the MAC with the following command:

sudo docker run -it --rm --name envoy -p 15000:15000 -p 10000:10000 -v "$(pwd)/reservation_service_definition.pb:/data/reservation_service_definition.pb:ro" -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" envoyproxy/envoy

This publishes the port admin and port number but not the host port number 530000 where the Java server is running. I also removed the hosts network mode because this prevents publishing of the port. Here is the updated yaml: Note that I had to use host.docker.internal for the backend cluster rather than 127.0.0.1 due to visibility of the cluster.

access_log_path: /tmp/admin_access.log address: socket_address: { address: 0.0.0.0, port_value: 15000 }

1

static_resources: listeners:

hanoisteve commented 5 years ago

I am able to add reservations ok, but reservation list is returning empty. coffee:Downloads Steven$ curl -v -X GET http://localhost:10000/v1/reservations Note: Unnecessary use of -X or --request, GET is already inferred.

toefel18 commented 5 years ago

Hi, sorry for the late response, I'll look into this later!

toefel18 commented 5 years ago

could you issue a PR with the changes you made, I don't have a MAC but I can ask colleagues to test it on theirs. I would like to get it working on MAC, Linux and maybe windows as well :).

klebersouza87 commented 2 years ago

Hello. What version did you use to run envoy? I'm trying "envoyproxy/envoy:v1.21.0" docker image and get an error below.

Protobuf message (type envoy.config.bootstrap.v3.Bootstrap reason INVALID_ARGUMENT:(static_resources.clusters[0]) hosts: Cannot find field.) has unknown fields

Can you help me? Thanks.

toefel18 commented 2 years ago

Hello @klebersouza87 the command I used appeared to be:

    docker run -it --rm --name envoy --network="host" \
             -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" \
             envoyproxy/envoy

This was done at 2018-11-04, so if possible, I would look for an envoy image around that time.

https://hub.docker.com/r/envoyproxy/envoy/tags?ordering=-last_updated

random old image: docker pull envoyproxy/envoy:0cb60a38150212c1c64cc3f75b8f814e918d4c47

klebersouza87 commented 2 years ago

With this image I can run envoy container, but ports is not mapped. Did you have this problem? I'm using your project without any changes.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 02c35de95c78 envoyproxy/envoy:0cb60a38150212c1c64cc3f75b8f814e918d4c47 "/bin/bash" 35 seconds ago Up 34 seconds envoy

toefel18 commented 2 years ago

Hi, sorry for the slow response. I was busy this weekend.

The ports are indeed not mapped that way I guess. In this file I see that I use --network="host" which means it does not get a separate network but just runs on the host net, so it would be accessible on localhost without port mapping. Not sure if this is still supported due to security, but you could try that.

https://github.com/toefel18/transcoding-grpc-to-http-json/blob/master/start-envoy.sh


# check if sudo is required to run docker
if [ "$(groups | grep -c docker)" -gt "0" ]; then
    echo "Envoy will run at port 51051 (see envoy-config.yml)"
    docker run -it --rm --name envoy --network="host" \
             -v "$(pwd)/reservation_service_definition.pb:/data/reservation_service_definition.pb:ro" \
             -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" \
             envoyproxy/envoy
else
    echo "you are not in the docker group, running with sudo"
    echo "Envoy will run at port 51051 (see envoy-config.yml)"
    sudo docker run -it --rm --name envoy --network="host"\
             -v "$(pwd)/reservation_service_definition.pb:/data/reservation_service_definition.pb:ro" \
             -v "$(pwd)/envoy-config.yml:/etc/envoy/envoy.yaml:ro" \
             envoyproxy/envoy
fi