对于一个golang开发者来说,牢固扎实的基础是十分重要的,编程网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《Google Cloud Monitoring - 警报策略:状态代码:4
对于一个golang开发者来说,牢固扎实的基础是十分重要的,编程网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《Google Cloud Monitoring - 警报策略:状态代码:409 - 对项目配置的并发编辑过多》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!
问题内容我正在尝试为 google cloud platfORM 中的 kubernetes 集群创建警报策略。以下是示例代码。
service, err := monitoring.newservice(context.background())
if err != nil {
log.panicln(err)
return
}
MQlcondition := &monitoring.monitoringquerylanguagecondition{
duration: "60s",
query: `fetch k8s_pod
| metric 'kubernetes.io/pod/volume/utilization'
| filter
(resource.cluster_name == 'test'
&& resource.pod_name =~ 'server.*')
&& (metric.volume_name =~ 'dat.*')
| align mean_aligner()
| window 10m
| condition value.utilization > 0.001 '10^2.%'
`,
trigger: &monitoring.trigger{
count: 1,
},
}
condition := monitoring.condition{
displayname: "mql-based condition",
conditionmonitoringquerylanguage: mqlcondition,
}
alertpolicy := &monitoring.alertpolicy{
displayname: "prakash1",
combiner: "or",
conditions: []*monitoring.condition{&condition},
notificationchannels: []string{"projects/abc-app/notificationchannels/16000000099515524778"},
}
p, err := service.projects.alertpolicies.create("projects/abc-app", alertpolicy).context(context.background()).do()
if err != nil {
log.panicln(err)
return
}
当我同时创建两个或多个警报策略时,出现以下错误:
"googleapi: Error 409: Too many concurrent edits to the project configuration. Please try again., aborted"
您能告诉我如何解决此错误吗?
正如错误所示,您无法同时添加策略。我建议您并行生成创建请求并序列化实际的 api 调用。您可以通过缓冲通道和多个 go 例程来实现这一点。例如:
var(
backlogSize = 3 //change as per your needs
requests = make(chan *monitoring.AlertPolicy, backlogSize)
)
func createPolicies(){
...
go func(){
//init the service
...
for policy := range requests {
p, err := service.Projects.AlertPolicies.Create("projects/abc-app", policy).Context(context.Background()).Do()
if err != nil {
log.Println(err)
}
}
}()
go func(){
newPolicy := &monitoring.AlertPolicy
//fill policy
...
requests <- newPolicy
}()
...
//wait for completion and close requests channel
}
另一种解决方案是使用指数退避+抖动来重试每个失败的并发请求
终于介绍完啦!小伙伴们,这篇关于《Google Cloud Monitoring - 警报策略:状态代码:409 - 对项目配置的并发编辑过多》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~编程网公众号也会发布Golang相关知识,快来关注吧!
--结束END--
本文标题: Google Cloud Monitoring - 警报策略:状态代码:409 - 对项目配置的并发编辑过多
本文链接: https://lsjlt.com/news/596374.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-04-05
2024-04-05
2024-04-05
2024-04-04
2024-04-05
2024-04-05
2024-04-05
2024-04-05
2024-04-04
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0