SigNoz/signoz · error · model.ApiError

error building clickhouse query: %v

Error message

error building clickhouse query: %v

What it means

This 500 is returned from the queue overview endpoint when queues2.BuildOverviewQuery fails to translate the validated QueueListRequest into a ClickHouse query. BuildOverviewQuery constructs SQL from user-supplied filters, group-by, and time-range parameters; invalid combinations (unknown group-by keys, bad filter columns, inverted or zero time ranges, unsupported aggregation) surface here rather than during request parsing.

Source

Thrown at pkg/query-service/app/http_handler.go:4032

	}
	aH.WriteJSON(w, r, field)
}

func (aH *APIHandler) getQueueOverview(w http.ResponseWriter, r *http.Request) {

	queueListRequest, apiErr := ParseQueueBody(r)

	if apiErr != nil {
		aH.logger.ErrorContext(r.Context(), "failed to parse queue body", errors.Attr(apiErr.Err))
		RespondError(w, apiErr, nil)
		return
	}

	chq, err := queues2.BuildOverviewQuery(queueListRequest)

	if err != nil {
		aH.logger.ErrorContext(r.Context(), "failed to build queue overview query", errors.Attr(err))
		RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: fmt.Errorf("error building clickhouse query: %v", err)}, nil)
		return
	}

	results, err := aH.reader.GetListResultV3(r.Context(), chq.Query)
	if err != nil {
		RespondError(w, model.BadRequest(err), nil)
		return
	}

	aH.Respond(w, results)
}

func (aH *APIHandler) getDomainList(w http.ResponseWriter, r *http.Request) {
	// Extract claims from context for organization ID
	claims, err := authtypes.ClaimsFromContext(r.Context())
	if err != nil {
		render.Error(w, err)
		return

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Inspect the server log line 'failed to build queue overview query' — errors.Attr(err) carries the exact builder failure
  2. Check the request payload's groupBy, filters, and time range against the queues2 package's supported fields for your SigNoz version
  3. Repro with a minimal request (valid time range, no filters, default groupBy) and add fields back one at a time to isolate the offending parameter
  4. If schema drift is suspected (old column names), align frontend payload with the query-service version or upgrade both together

Example fix

// before
{"groupBy": ["bogus_field"], "filters": [{"column": "no_such_col", "op": "eq", "value": 1}]}

// after
{"groupBy": ["destination"], "filters": [{"column": "destination", "op": "eq", "value": "orders"}], "start": 1710000000, "end": 1710086400}
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_GROUPBY = new Set(['destination','name','status']);
function validateQueueReq(req) {
  if (!req.start || !req.end || req.end <= req.start) return 'invalid time range';
  for (const g of req.groupBy || []) if (!SUPPORTED_GROUPBY.has(g)) return `unsupported groupBy: ${g}`;
  return null;
}

Type guard

function isQueueListRequest(r: unknown): r is QueueListRequest {
  const q = r as QueueListRequest;
  return typeof q?.start === 'number' && typeof q?.end === 'number' && q.end > q.start &&
    (q.groupBy ?? []).every(g => typeof g === 'string');
}

Try / catch

try {
  const res = await fetch('/api/v1/queues/overview', {method:'POST', body: JSON.stringify(req)});
  if (res.status === 500) console.error('query build failed — check groupBy/filters payload');
} catch (e) { /* network */ }

Prevention

When it happens

Trigger: POST to the queue overview/list API with an invalid groupBy field, a filter referencing a nonexistent ClickHouse column, an unreadable start/end timestamp pair, or a queue-name pattern the query builder cannot escape, causing BuildOverviewRequest (earlier validation passes) but BuildOverviewQuery to error.

Common situations: Frontend sending a newer/older request schema than the query-service expects after a version mismatch; user-crafted filter expressions with reserved SQL characters; empty or malformed time range slipped through earlier validation; column renamed in a ClickHouse migration but request still references the old name.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/e06ea53933178f9d. Report an issue: GitHub.