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

Less helpful "Number of label descriptors must match number of label extractors" error #20872

Open
ensonic opened this issue Jan 10, 2025 · 4 comments

Comments

@ensonic
Copy link

ensonic commented Jan 10, 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.5.4
on linux_amd64

  • provider registry.terraform.io/hashicorp/google v6.12.0
  • provider registry.terraform.io/hashicorp/google-beta v6.12.0

Affected Resource(s)

google_logging_metric

Terraform Configuration

resource "google_logging_metric" "log_count_per_container_logging_metric" {
  project = var.project
  name    = "log-count-per-container/metric"
  filter  = "resource.type=k8s_container AND jsonPayload.kubernetes.namespace_name:app-"
  metric_descriptor {
    metric_kind  = "DELTA"
    value_type   = "INT64"
    display_name = "Number of log entries per container"
    #labels {
    #  key         = "container"
    #  value_type  = "STRING"
    #  description = "name of container"
    #}
  }
  label_extractors = {
    "container" = "EXTRACT(jsonPayload.kubernetes.container_name)"
  }
}

Debug Output

Error: Error creating Metric: googleapi: Error 400: Number of label descriptors must match number of label extractors

Expected Behavior

the error should probably say "Number of metric_descriptor.label blocks must match number of label_extractors" as there is no label_descriptor. Also I would assume terraform plan to complain about it and not terraform apply.

Actual Behavior

terraform validate and terraform plan works, apply fails with not so helpful error.

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

b/390469720

@ensonic ensonic added the bug label Jan 10, 2025
@github-actions github-actions bot added forward/review In review; remove label to forward service/logging labels Jan 10, 2025
@ggtisc
Copy link
Collaborator

ggtisc commented Jan 16, 2025

Perhaps the possibility of changing the error message to make it more intuitive for users and adding a warning to the terraform registry documentation indicating how the metric_descriptor argument should be used correctly with labels when using label_extractors could be evaluated.

@ggtisc ggtisc self-assigned this Jan 16, 2025
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Jan 16, 2025
@ggtisc ggtisc removed their assignment Jan 16, 2025
@ggtisc
Copy link
Collaborator

ggtisc 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.5.4 on linux_amd64

  • provider registry.terraform.io/hashicorp/google v6.12.0
  • provider registry.terraform.io/hashicorp/google-beta v6.12.0

Affected Resource(s)

google_logging_metric

Terraform Configuration

resource "google_logging_metric" "log_count_per_container_logging_metric" {
project = var.project
name = "log-count-per-container/metric"
filter = "resource.type=k8s_container AND jsonPayload.kubernetes.namespace_name:app-"
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
display_name = "Number of log entries per container"
#labels {
# key = "container"
# value_type = "STRING"
# description = "name of container"
#}
}
label_extractors = {
"container" = "EXTRACT(jsonPayload.kubernetes.container_name)"
}
}

Debug Output

Error: Error creating Metric: googleapi: Error 400: Number of label descriptors must match number of label extractors

Expected Behavior

the error should probably say "Number of metric_descriptor.label blocks must match number of label_extractors" as there is no label_descriptor. Also I would assume terraform plan to complain about it and not terraform apply.

Actual Behavior

terraform validate and terraform plan works, apply fails with not so helpful error.

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

To replicate the error just use the shared code, and to avoid errors uncomment the labels lines

@ensonic
Copy link
Author

ensonic commented Jan 16, 2025

The uncommented lines showed what I missed initially when I get the error. With those lines it works of course. My points were:

  • warn during terraform plan and not only during apply (I know it needs support from the api, but what's the point of plan otherwise?)
  • correctly address the missing parts in the error (aka be precise with the field names)

@ggtisc
Copy link
Collaborator

ggtisc commented Jan 16, 2025

Thanks for adding this so it can be considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants