GoogleCloudPlatform / esp-v2

A service proxy that provides API management capabilities using Google Service Infrastructure.
https://cloud.google.com/endpoints/
Apache License 2.0
268 stars 167 forks source link

HTTP endpoint with google.api.http annotation doesn't transcode locally #906

Open danielmahon opened 4 months ago

danielmahon commented 4 months ago

Hello there! I’m running into an issue when locally testing an ESPv2 endpoint deployed in docker when using http endpoints. We use this setup frequently for app/web based gRPC client testing with no issue. This is the first time we are using the google.api.http annotation to define http endpoints though. Everything works as expected in Postman when accessing the endpoint via secure gRPC or the GRPC_SERVICE_FULL_NAME/METHOD_NAME. No errors and the backend node container receives the request. However, when accessing via the http path (ex /v1/generate), we get a 404 error. No errors in Envoy (ESPv2) but hard to tell where its failing. This works as intended in production with the reverse-proxy image and the endpoint does indeed get transposed to the GRPC_SERVICE_FULL_NAME/METHOD_NAME. However with the sidecar image locally the request passes through envoy as /v1/generate and doesnt get matched to the handler causing a 404.

HTTP POST https://localhost:8080/cfg.main.v1.MainService/Generate (works) gRPC grpcs://localhost:8080 Generate (works) HTTP POST https://localhost:8080/v1/generate (fails 404)

(api key enabled on all)

proto

service MainService {
  rpc Generate(GenerateRequest) returns (GenerateResponse) {
    option (google.api.http) = {
      post: "/v1/generate"
      body: "*"
    };
  }
}

message GenerateRequest {
  string id = 1;
  string type = 2;
}

api_config.yaml

type: google.api.Service
config_version: '3'
name: **********
title: Google Cloud Run ESPv2 gRPC Endpoint
apis:
  - name: cfg.main.v1.MainService
usage:
  rules:
    - selector: '*'
      allow_unregistered_calls: false
backend:
  rules:
    - selector: cfg.main.v1.MainService.*
      address: grpc://main:8081
      deadline: 1800

docker-compose.yaml

  main:
  # ...
  endpoint:
    platform: linux/amd64
    image: gcr.io/endpoints-release/endpoints-runtime:2
    command: [
        '--listener_port=8080',
        '--service_json_path=/usr/src/service_config.json',
        '--service_account_key=/usr/src/endpoint.key',
        # '--disable_tracing',
        '--non_gcp',
        '--cors_preset=basic',
        '--generate_self_signed_cert',
        # '--cors_allow_headers=x-user-agent,x-grpc-web,authorization,content-type',
        # '--enable_debug',
      ]
    ports:
      - 8080:8080
    volumes:
      - ./apps/endpoint/service_config.json:/usr/src/service_config.json
      - ./apps/endpoint/endpoint.key:/usr/src/endpoint.key