Now, I write messages to Pub/Sub by configuring Monitoring Alert, which triggers Cloud Function to patch the configuration of the backend service. The current method first can achieve, for example, after the appearance of the Http 5xx status code, automatically adjust the capacity of the back-end service.
The above is a method I tested, I do not know if GCP has other more convenient and faster methods can be used.
The following code is my reference to the GCP client library to use:
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
# Project ID for this request.
project = 'my-project' # TODO: Update placeholder value.
# Name of the BackendService resource to patch.
backend_service = 'my-backend-service' # TODO: Update placeholder value.
backend_service_body = {
# TODO: Add desired entries to the request body. Only assigned entries
# will be changed.
}
request = service.backendServices().patch(project=project, backendService=backend_service, body=backend_service_body)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)