Stack Overflow message
I am making a project on Google Cloud Run. It is a microservice architecture with different Go services communicating with each other via gRPC. The project has HTTP endpoints exposed with ESPv2 which handles the transcoding of HTTP to gRPC.
When I send gRPC messages to the services directly, they work correctly. I’m able to do all CRUD functions successfully. When I send an HTTP request to the service URL, I get an error:
{
"code": 12,
"message": "unknown service <package>.<MyAPIGateway>"
}
This is my simplified api_config.yaml in Api Gateway service
type: google.api.Service
config_version: 3
name: <service url>.a.run.app
title: My Microservices
apis:
- name: package.MyAPIGateway
usage:
rules:
# Methods can be called without an API Key.
- selector: package.MyAPIGateway.*
allow_unregistered_calls: true
backend:
rules:
- selector: package.MyAPIGateway.GetUser
address: grpcs://user-service.a.run.app
#
# HTTP rules define translation from HTTP/REST/JSON to gRPC. With these rules
# HTTP/REST/JSON clients will be able to call the service.
#
http:
rules:
- selector: package.MyAPIGateway.GetUser
get: /user
In User service, I register a gRPC service
// Create gRPC server
grpcServer := grpc.NewServer()
// Register service with gRPC server
userpb.RegisterUserServiceServer(grpcServer, userService)
However, the API Gateway has no Go code, so it is never registered, which I believe causes the error. Does API Gateway need to have code to handle requests? The intent was for API Gateway to just configure the project and the User Service would handle the business logic.
I attempted to update the api_config.yaml to assign the rules directly to the User Service
backend:
rules:
- selector: userpb.UserService.GetUser
address: grpcs://user-service.a.run.app
#
# HTTP rules define translation from HTTP/REST/JSON to gRPC. With these rules
# HTTP/REST/JSON clients will be able to call the service.
#
http:
rules:
- selector: userpb.UserService.GetUser
get: /user
But this resulted in the error:
{
"code": 503,
"message": "upstream connect error or disconnect/reset before headers. retried and the latest reset reason: connection failure, transport failure reason: delayed connect error: 111"
}
Any guidance for resolving this communication error would be much appreciated. Thanks!
Here is the log entry for the 501 request
{
"insertId": "<ID>",
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "https://<URL>.a.run.app/user",
"requestSize": "649",
"status": 501,
"responseSize": "1273",
"userAgent": "PostmanRuntime/7.32.2",
"remoteIp": "<IP>",
"serverIp": "<IP>",
"latency": "3.539549s",
"protocol": "H2C"
},
"resource": {
"type": "cloud_run_revision",
"labels": {
"project_id": "<project ID>",
"location": "us-central1",
"revision_name": "<Project Revision>",
"configuration_name": "<project>",
"service_name": "<project>"
}
},
"timestamp": "2023-06-03T18:04:22.158774Z",
"severity": "ERROR",
"labels": {
"instanceId": "<instance id>"
},
"logName": "projects/<project ID>/logs/run.googleapis.com%2Frequests",
"trace": "projects/<project ID>/traces/ff037d1ab301a770ab20f3d74eb68d5f",
"receiveTimestamp": "2023-06-03T18:04:25.862194414Z",
"spanId": "<span id>",
"traceSampled": true
}