首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何生成在Google云运行中不可用的503服务?

如何生成在Google云运行中不可用的503服务?
EN

Stack Overflow用户
提问于 2021-08-28 09:35:37
回答 2查看 475关注 0票数 2

我正在研究一种灾难恢复策略,如果服务不可用超过10分钟,我想自动化Google平台上的云运行基础设施部署。

要实现上述自动化,我希望检查我的云运行的获取公共API是否响应,并发送一个将触发自动化并提供资源的警报

问题

我无法在云运行的演示容器(hello-world)上生成503 error,我尝试使用python多处理和云运行上的1 concurrency一起发送10000 requests,使max实例保持在1,而最小实例在0Memory- 128MB, CPU-1

如何在云运行演示容器hello-world上生成503错误,并查看get public API的状态?

我不想做的事

我不想向容器应用程序添加健康检查,并使用该健康检查来确定容器云运行服务的可用性。

EN

回答 2

Stack Overflow用户

发布于 2021-08-28 18:21:29

更新我误解了您的问题,并假设您正在使用云存储。

以下是两个选择:

嘲弄

代码语言:javascript
复制
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()

然后运行它:

代码语言:javascript
复制
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的“实现”:

代码语言:javascript
复制
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()

然后运行它:

代码语言:javascript
复制
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

原始

代码语言:javascript
复制
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

票数 1
EN

Stack Overflow用户

发布于 2021-08-28 09:41:42

这里有一个想法:试着上传一个大文件。在内存有限的情况下,自然会产生503。

代码语言:javascript
复制
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')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68963093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档