Files
zeekay 5e1ea5c41f debrand: hanzo-ds sqlbuilder/sqlparser forks + brand-neutral mock seam
Completes the debrand on top of the driver/dscol work already on main:

- Repoint to canonical native forks: hanzo-ds/sqlbuilder v1.42.2,
  hanzo-ds/sqlparser v0.4.16.
- Datastore sql flavor now renders native ILIKE (v1.42.2); statement-builder
  test expectations updated from the LOWER(x) LIKE LOWER(?) emulation.
- Mock: expose datastore-go-mock behind a brand-neutral datastoremock.Conn
  seam so first-party code names no ClickConnMockCommon symbol.
- Scrub CH/SigNoz from comments; drop dead SigNoz tracker links.

Zero clickhouse/signoz/CH in first-party Go and go.mod.
2026-07-12 22:38:18 -07:00

51 lines
1.6 KiB
Go

package queryparser
import (
"net/http"
"github.com/hanzoai/o11y/pkg/errors"
"github.com/hanzoai/o11y/pkg/factory"
"github.com/hanzoai/o11y/pkg/http/binding"
"github.com/hanzoai/o11y/pkg/http/render"
"github.com/hanzoai/o11y/pkg/types/parsertypes"
)
type API struct {
queryParser QueryParser
settings factory.ProviderSettings
}
func NewAPI(settings factory.ProviderSettings, queryParser QueryParser) *API {
return &API{settings: settings, queryParser: queryParser}
}
// AnalyzeQueryFilter analyzes a query and extracts metric names and grouping columns.
func (a *API) AnalyzeQueryFilter(w http.ResponseWriter, r *http.Request) {
// Limit request body size to 255 KB (Datastore query limit is 256 KB)
r.Body = http.MaxBytesReader(w, r.Body, 255*1024)
var req parsertypes.QueryFilterAnalyzeRequest
if err := binding.JSON.BindBody(r.Body, &req); err != nil {
render.Error(w, err)
return
}
result, err := a.queryParser.AnalyzeQueryFilter(r.Context(), req.QueryType, req.Query)
if err != nil {
a.settings.Logger.ErrorContext(r.Context(), "failed to analyze query filter", errors.Attr(err))
render.Error(w, err)
return
}
// prepare the response
var resp parsertypes.QueryFilterAnalyzeResponse
for _, group := range result.GroupByColumns {
resp.Groups = append(resp.Groups, parsertypes.ColumnInfoResponse{
Name: group.Name,
Alias: group.Alias,
}) // add the group name and alias to the response
}
resp.MetricNames = append(resp.MetricNames, result.MetricNames...) // add the metric names to the response
render.Success(w, http.StatusOK, resp)
}