googleapis / googleapis/google-cloud-node
[google-cloud-monitoring] cannot create log-based alerting policy
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
#### Environment details
- which product (packages/*): google-cloud-monitoring
- OS: mac / not relevant
- Node.js version: 18
- npm version: 9.5.1
- google-cloud-node version: 3.0.4
#### Steps to reproduce
```ts
const createAlertInGcp = async () => {
const alertPolicy: google.monitoring.v3.AlertPolicy = {
displayName: "Timed out (api)",
documentation: {
content:
"${log.extracted_label.user}'s request timed out.\n\nIt happened in ${resource.labels.cluster_name}. The url was ${log.extracted_label.url}",
mimeType: "text/markdown",
},
conditions: [
{
displayName: "Timed out (api)",
conditionMatchedLog: {
filter:
'resource.type="k8s_container"\nresource.labels.namespace_name="default"\nresource.labels.container_name="engine"\njsonPayload.message=~"Timed out"\njsonPayload.msg="Returning a 500 error"',
labelExtractors: {
user: "EXTRACT(jsonPayload.options.user)",
url: "EXTRACT(jsonPayload.options.url)",
},
},
},
],
alertStrategy: {
notificationRateLimit: {
period: "3600s",
},
autoClose: "1800s",
},
combiner: "OR",
enabled: { value: true },
notificationChannels: [
"projects/project/notificationChannels/1209803...",
],
};
const alertPolicyRequest: google.monitoring.v3.ICreateAlertPolicyRequest = {
name: client.projectPath(projectId),
alertPolicy,
};
// client.create
let res = await client.createAlertPolicy(alertPolicyRequest);
console.log(res);
```
The error in the response is:
```
'Field alert_policy.conditions[0].condition_case had an invalid value of "0": Condition subtype (e.g. "condition_absent","condition_threshold", etc.) is absent or unknown.',
```
So it seems that the `conditionMatchedLog` subtype is not supported yet by the nodejs client, only the metric-based alerts seem to be supported.
Following this: https://cloud.google.com/monitoring/alerts/policies-in-api#log-polices
and this: https://cloud.google.com/logging/docs/alerting/log-based-alerts#lba-api-create
it does seem to be supported through the API using the gcloud cli.
Contributor guide
Assessment
This issue has not been assessed yet.