Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot override "__name__" in google_monitoring_alert_policy, condition_prometheus_query_language block using the labels option. #20938

Open
nick-lawrence opened this issue Jan 16, 2025 · 0 comments
Labels

Comments

@nick-lawrence
Copy link

nick-lawrence commented Jan 16, 2025

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v1.9.8
on linux_amd64

  • provider registry.terraform.io/hashicorp/google v6.16.0
  • provider registry.terraform.io/hashicorp/google-beta v6.16.0
  • provider registry.terraform.io/hashicorp/random v3.6.3
  • provider registry.terraform.io/hashicorp/time v0.12.1
  • provider registry.terraform.io/hashicorp/tls v4.0.6

Affected Resource(s)

google_monitoring_alert_policy

within that resource condition_prometheus_query_language

Terraform Configuration

This a cut and paste of my partial configuration. The labels doesn't let me set "__name__", the documentation implies that I should be able to set it. I want to be able to set it so that google incident notifications include a metric name for complex queries where 'name' is removed from the query.

resource "google_monitoring_alert_policy" "promql_policies" {
  project      = var.project_id
  for_each     = { for i, policy in local.policies["promql_policies"] : i => policy }
  display_name = each.value["display_name"]
  combiner     = each.value["combiner"]

  dynamic "conditions" {
    for_each = { for i, condition in each.value["conditions"] : i => condition }
    content {
      display_name = conditions.value["display_name"]
      condition_prometheus_query_language {
        query                     = conditions.value["query"]
        duration                  = conditions.value["duration"]
        disable_metric_validation = true

        # >>>>>>> This is the important part
        # >>>>>>> Overriding "__name__" causes the apply to fail
        labels = { "__name__" = conditions.value["metric_name"] }
      }
    }
  }

  severity = each.value["severity"]
  enabled  = each.value["enabled"]
  documentation {
    subject   = "${each.value["documentation"]["subject"]} (${var.project_id})"
    mime_type = "text/markdown"
    content   = each.value["documentation"]["content"]

  }

Debug Output

No response

Expected Behavior

Intending to override/set the "__name__" label for my query.

The reason is when goggle sends me a notification email, it includes a
metric : missing

label.

I believe that 'metric' is the "__name__" from the query, because my query is complex, the label is not in the result, and thus it's reported as missing.

I'd like to set that to avoid confusion when reading the notification.

Documentation implies that I should be able to do this:

labels - (Optional) Labels to add to or overwrite in the PromQL query result. Label names must be valid. Label values can be templatized by using variables. The only available variable names are the names of the labels in the PromQL result, including "name" and "value". "labels" may be empty. This field is intended to be used for organizing and identifying the AlertPolicy

Actual Behavior

Apply fails with:

"__name__": PromQL names beginning with __ are reserved for internal use.

Steps to reproduce

  1. terraform apply

Important Factoids

I tried using "name", but this just created another label. Same thing with "metric" which is how google displays this.

It seems like "name" should be allowed, but is being blocked.

References

No response

@github-actions github-actions bot added forward/review In review; remove label to forward service/monitoring-alerting labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant