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

cortextool prepare produces invalid query #196

Open
gotjosh opened this issue Jul 1, 2021 · 3 comments
Open

cortextool prepare produces invalid query #196

gotjosh opened this issue Jul 1, 2021 · 3 comments

Comments

@gotjosh
Copy link
Collaborator

gotjosh commented Jul 1, 2021

When running cortextool prepare on a query such as:

(sum by (node, resource) (kube_node_status_capacity{}))
          * on(node) group_left(cluster, nodepool) nodepool:node:{} < %(threshold)0.2f
      )

I'll produce

(sum by (node, resource, cluster) (kube_node_status_capacity{}))
          * on(node,cluster) group_left(cluster, nodepool) nodepool:node:{} < %(threshold)0.2f
      )

But this is invalid given: could not parse expression: 1:301: parse error: label \"cluster\" must not occur in ON and GROUP clause at once

@Duologic
Copy link
Member

Duologic commented Mar 4, 2022

I had another instance of this. The follow query intends to derive the cluster label
form the kube_node_annotations query. The grouping should not occur on the first part
of the query.

Intended query:

100 *
sum by (instance_id, nat_gateway_name, project_id) (
  stackdriver_gce_instance_compute_googleapis_com_nat_port_usage
) /
sum by (instance_id, nat_gateway_name, project_id) (
  stackdriver_gce_instance_compute_googleapis_com_nat_allocated_ports
)
* on(instance_id) group_left(node, cluster)
count by (instance_id, node, cluster) (
  label_replace(
   kube_node_annotations{annotation_container_googleapis_com_instance_id!=""},
   'instance_id', '$1',
   'annotation_container_googleapis_com_instance_id', '(.*)'
  )
)  > 90

This forced me to remove the cluster label from group_left(), eventually rendering
a wrong query:


100 *
sum by(instance_id, nat_gateway_name, project_id, cluster) (
  stackdriver_gce_instance_compute_googleapis_com_nat_port_usage
) /
sum by(instance_id, nat_gateway_name, project_id, cluster) (
  stackdriver_gce_instance_compute_googleapis_com_nat_allocated_ports
)
* on(instance_id, cluster) group_left(node)
count by(instance_id, node, cluster) (
  label_replace(
   kube_node_annotations{annotation_container_googleapis_com_instance_id!=""},
   "instance_id", "$1",
   "annotation_container_googleapis_com_instance_id", "(.*)"
  )
)  > 90

@Duologic
Copy link
Member

Duologic commented Mar 4, 2022

Perhaps we can have a HeadComment (for ex: # cortextool: skip rule aggregation to indicate the aggregation should not be applied.

wdyt?

@dohnto
Copy link

dohnto commented Apr 13, 2022

Elaborating on @Duologic 's comments. The query is still wrong for us as the on(instance_id, **cluster**) part is causing issues - the metrics were generated in different clusters, therefore we don't want to join on the label.

friedrichg pushed a commit to cortexproject/cortex-tools that referenced this issue Aug 1, 2023
* Update MAINTAINERS.md

Signed-off-by: ShuzZzle <niclas.schad@gmail.com>

* add kd7lxl

Signed-off-by: Tom Hayward <thayward@infoblox.com>

* Update MAINTAINERS.md

Signed-off-by: ShuzZzle <niclas.schad@gmail.com>

Co-authored-by: Tom Hayward <thayward@infoblox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants