Skip to content

Prettify functionality for the binary operations adds additional braces #54

Open
@dmitryk-dk

Description

@dmitryk-dk

If you try to prettify the query

(1 - (node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes + node_memory_SReclaimable_bytes) / node_memory_MemTotal_bytes) * 100

You will get the result:

(
  1
    -
  (
    (
      (
        (node_memory_MemFree_bytes + node_memory_Cached_bytes)
          +
        node_memory_Buffers_bytes
      )
        +
      node_memory_SReclaimable_bytes
    )
      /
    node_memory_MemTotal_bytes
  )
)
  *
100

It happens because braces are always add if it is BinaryOpExpr
https://github.com/VictoriaMetrics/metricsql/blob/master/parser.go#L1935
and
https://github.com/VictoriaMetrics/metricsql/blob/master/parser.go#L1980

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions