英文:
GCP Monitoring Alert Policy Using MQL Query
问题
我正在尝试在GCP监控中通过控制台创建一个MQL警报策略,但当我尝试保存时,它一直给我一个错误。 "错误:无法保存警报策略。请求包含无效参数。"
据我所见,我的查询是有效的。查询编辑器中没有报告任何问题,它显示了我期望的图表。
这是策略创建器生成的JSON视图:
{
"displayName": "kube_deployment_replicas_mismatch",
"documentation": {
"content": "The expected number of replicas have not been available for 15 minutes or longer",
"mimeType": "text/markdown"
},
"userLabels": {
"type": "application"
},
"conditions": [
{
"displayName": "kube_deployment_replicas_mismatch",
"conditionMonitoringQueryLanguage": {
"duration": "900s",
"trigger": {
"count": 1
},
"evaluationMissingData": "EVALUATION_MISSING_DATA_INACTIVE",
"query": "{ kubernetes.io/anthos/kube_deployment_spec_replicas\n; kubernetes.io/anthos/kube_deployment_status_replicas_available }\n| [metric.deployment]\n| ratio\n| condition val() != 1"
}
}
],
"alertStrategy": {
"autoClose": "604800s"
},
"combiner": "OR",
"enabled": true,
"notificationChannels": [
"projects/xxxxxxxxx/notificationChannels/xxxxxxxxxxx"
]
}
希望这有助于您解决问题。
英文:
I am trying to create an MQL alert policy in GCP monitoring via the console but when I try to save it it keeps giving me an error. "Error: Unable to save alerting policy. Request contains an invalid argument."
As far as I can see my query is valid. There are no issues reported in the query editor and it displays the chart I was expecting.
This is the json view, which is generated by the policy creator:
{
"displayName": "kube_deployment_replicas_mismatch",
"documentation": {
"content": "The expected number of replicas have not been available for 15 minutes or longer",
"mimeType": "text/markdown"
},
"userLabels": {
"type": "application"
},
"conditions": [
{
"displayName": "kube_deployment_replicas_mismatch",
"conditionMonitoringQueryLanguage": {
"duration": "900s",
"trigger": {
"count": 1
},
"evaluationMissingData": "EVALUATION_MISSING_DATA_INACTIVE",
"query": "{ kubernetes.io/anthos/kube_deployment_spec_replicas\n; kubernetes.io/anthos/kube_deployment_status_replicas_available }\n| [metric.deployment]\n| ratio\n| condition val() != 1"
}
}
],
"alertStrategy": {
"autoClose": "604800s"
},
"combiner": "OR",
"enabled": true,
"notificationChannels": [
"projects/xxxxxxxxx/notificationChannels/xxxxxxxxxxx"
]
}
答案1
得分: 2
某些MQL表操作要求输入数据对齐。
如果您向这些表操作传递了不对齐的输入数据,MQL会自动为您对齐数据。
但是在警报查询中,这可能会引发问题。在这些情况下,将无法创建使用这种类型查询的警报策略。
一种解决方法是在隐式对齐数据的操作之后添加 | window 30s
。
尝试对您提供的查询执行相同操作后,警报创建成功。
以下是示例查询:
fetch istio_canonical_service
| metric 'istio.io/service/server/request_count'
| { filter (metric.response_code < 499); ident }
| group_by [metric.destination_service_namespace]
| ratio
| fraction_less_than(0.50)
| condition val() > 0.20
| window 30s # 将窗口正确设置为30秒
在添加 | window 30s
之前,我也遇到了相同的问题。添加后,警报策略成功创建。
有关更多信息,请查阅官方文档 1。
英文:
Some MQL table operations require their inputs to be aligned.
If you pass unaligned input to these table operations,MQL automatically aligns the data for you.
But this can cause problems in an alerting query. In these cases, it will be prevented from creating an alerting policy that uses this type of query.
One solution is to add | window 30s
after the operation that implicitly aligns the data for you.
Trying the same for the query you provided works with the alert creation.
Here is the sample query:
fetch istio_canonical_service
| metric 'istio.io/service/server/request_count'
| { filter (metric.response_code < 499); ident }
| group_by [metric.destination_service_namespace]
| ratio
| fraction_less_than(0.50)
| condition val() > 0.20
| window 30s # correctly sets the window to 30s
Before adding | window 30s
I was also getting the same after adding it, the alert policy has been created successfully.
For more information follow this official doc.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论