<#C01HWQ1R0BC|> Can anyone help me with deploying ...
# support
d
#C01HWQ1R0BC Can anyone help me with deploying system metrics in SigNoz using Terraform code? I want to use PromQL queries for this, but I'm not sure about the PromQL query resource configurations. I was able to deploy them earlier using the query builder type.
Copy code
resource "signoz_alert" "new_alert" {
  alert            = "High CPU Usage Monitor"
  alert_type       = "METRIC_BASED_ALERT"
  severity         = "warning"
  broadcast_to_all = false
  rule_type        = "promql_rule"  # Rule type already set here, no need to duplicate

  condition = jsonencode({
    alertOnAbsent = true,
    absentFor     = 10,
    compositeQuery = {
      promQueries = {
        A = {
          name    = "A"
          query   = "avg(k8s_node_cpu_utilization) by (node_name) > 0.8"
          legend  = ""
          disabled = false
        }
      },
      queryType = "promql",
      panelType = "graph"
    },
    op                = "1", # Greater than
    matchType         = "1", # Exact match
    selectedQueryName = "A",
  })

  # Keeping other values outside the condition block
  description = "This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})"
  eval_window = var.eval_window
  frequency   = var.frequency
  labels = {
    "environment" = var.environment
  }
  preferred_channels = [
    "aws-infra-cluster-dev-alerts"
  ]
  version   = "v4"
}
Hi @nitya-signoz
n
Can you share more details about what you did previously that was in a working state vs what you are doing now, then someone might be able to help.
d
@nitya-signoz This code got deployed
Copy code
esource "signoz_alert" "high_cpu_usage" {
  alert      = "High CPU Usage Monitor"
  alert_type = "METRIC_BASED_ALERT"
  severity   = "warning"
  broadcast_to_all   = false
  preferred_channels = []
  rule_type          = "threshold_rule"
  description        = "Alert when CPU usage exceeds threshold"
  eval_window        = var.eval_window
  frequency          = var.frequency
  labels = {
    environment = var.environment
  }

  condition = jsonencode({
    alertOnAbsent = true,
    absentFor     = 10,
    compositeQuery = {
      builderQueries = {
        A = {
          expression         = "A",
          queryName          = "A",
          dataSource         = "metrics",
          aggregateOperator  = "avg",
          reduceTo           = "avg",
          timeAggregation    = "avg",
          spaceAggregation   = "avg",
          aggregateAttribute = {
            key        = "k8s_node_cpu_utilization",
            type       = "Gauge",
            isColumn   = true,
            isJSON     = false,
            dataType   = "float64"
          },
          groupBy = [
            {
              key      = "k8s_node_name",
              type     = "tag",
              isColumn = false,
              isJSON   = false,
              dataType = "string"
            }
          ],
          filters = {
            items = [],
            op    = "AND"
          },
          stepInterval = 60,
          ShiftBy      = 0,
          IsAnomaly    = false,
          disabled     = false,
          QueriesUsedInFormula = null,
          limit        = 0,
          offset       = 0,
          pageSize     = 0
        }
      },
      chQueries   = {},
      promQueries = {},
      panelType   = "graph",
      queryType   = "builder",
      unit        = "%"
    },
    matchType         = "1",
    op                = "1",
    selectedQueryName = "A",
    target            = var.cpu_threshold,
    targetUnit        = "%"
  })
}
But here it is using the type as query builder. so the work was easy.
Copy code
error am getting 
Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Error: failed to read signoz_alert
│ 
│ status: 500, body: {"status":"error","errorType":"internal","error":"sql: no rows in result set"}
n
@Srikanth Chekuri / @Prashant Shahi might have some idea here.
d
Ok, Thanks. @Srikanth Chekuri and @Prashant Shahi, Can anyone guide me here