我正在研究一种灾难恢复策略,如果服务不可用超过10分钟,我想自动化Google平台上的云运行基础设施部署。
要实现上述自动化,我希望检查我的云运行的获取公共API是否响应,并发送一个将触发自动化并提供资源的警报
问题
我无法在云运行的演示容器(hello-world)上生成503 error,我尝试使用python多处理和云运行上的1 concurrency一起发送10000 requests,使max实例保持在1,而最小实例在0、Memory- 128MB, CPU-1。
如何在云运行演示容器hello-world上生成503错误,并查看get public API的状态?
我不想做的事
我不想向容器应用程序添加健康检查,并使用该健康检查来确定容器云运行服务的可用性。
发布于 2021-08-28 18:21:29
更新我误解了您的问题,并假设您正在使用云存储。
以下是两个选择:
api_option在ClientOptions。嘲弄
from googleapiclient.discovery import build
from googleapiclient.http import HttpMockSequence
from google.api_core.client_options import ClientOptions
http = HttpMockSequence([
({"status":"503"},"")
])
service = build("run","v1",http=http)
namespace = "foo"
service = "bar"
name = "namespaces/{namespace}/services/{service}".format(
namespace=namespace,
service=service,
)
rqst = service.namespaces().services().get(name=name)
resp = rqst.execute(http=http)
print(resp)
service.close()然后运行它:
googleapiclient.errors.HttpError: <HttpError 503 when requesting https://run.googleapis.com/apis/serving.knative.dev/v1/namespaces/foo/services/bar?alt=json returned "Ok">ClientOptions
您可以使用始终返回503的ClientOptions将客户端指向您自己的API的“实现”:
from googleapiclient.discovery import build
from google.api_core.client_options import ClientOptions
client_options = ClientOptions(api_endpoint="http://{host}:{port}".format(
host="localhost",
port="8080",
)
service = build("run","v1",client_options=client_options)
namespace = "foo"
service = "bar"
name = "namespaces/{namespace}/services/{service}".format(
namespace=namespace,
service=service,
)
rqst = service.namespaces().services().get(name=name)
resp = rqst.execute(http=http)
print(resp)
service.close()然后运行它:
googleapiclient.errors.HttpError: <HttpError 503 when requesting http://localhost:8080/apis/serving.knative.dev/v1/namespaces/foo/services/bar?alt=json returned "Ok">注意到这次,我有一个
/处理程序的/服务器,它总是返回503(ServiceUnavailable)。错误来自于localhost:8080
原始
from google.api_core.client_options import ClientOptions
from google.cloud import storage
client_options = ClientOptions(
api_endpoint="[[ENDPOINT]]"
)
client = storage.Client(client_options=client_options)注意:您可能希望从
gcloud迁移到google.cloud
发布于 2021-08-28 09:41:42
这里有一个想法:试着上传一个大文件。在内存有限的情况下,自然会产生503。
from gcloud import storage
from oauth2client.service_account import ServiceAccountCredentials
import os
credentials_dict = {
'type': 'service_account',
'client_id': os.environ['BACKUP_CLIENT_ID'],
'client_email': os.environ['BACKUP_CLIENT_EMAIL'],
'private_key_id': os.environ['BACKUP_PRIVATE_KEY_ID'],
'private_key': os.environ['BACKUP_PRIVATE_KEY'],
}
credentials = ServiceAccountCredentials.from_json_keyfile_dict(
credentials_dict
)
client = storage.Client(credentials=credentials, project='myproject')
bucket = client.get_bucket('mybucket')
blob = bucket.blob('myfile')
blob.upload_from_filename('myfile')https://stackoverflow.com/questions/68963093
复制相似问题