Full rebrand across cosmetic branding, code identifiers, and infrastructure/data-plane naming, using the supplied Cairn OBS logo package. Cosmetic: favicon/logo swap (also closes a stale license-audit finding -- the old favicon was SvelteKit's unreplaced scaffold logo), new centered welcome landing page, larger/legible sidebar logo, page titles, CLAUDE.md/README/docs prose. Code identifiers: Go module path github.com/sentry/sentry -> github.com/cairnobs/cairnobs across all 13 modules and ~91 files (protoc regenerated); Rust crates sentry-agent/sentry-parser/sentry-search -> cairnobs-*; CLI sentryctl -> cairnobsctl; Terraform provider fully renamed (sentry_dashboard etc. -> cairnobs_dashboard, provider type, env vars); every session/auth cookie name; agent config paths and Windows service identity. Deliberately preserved: the gRPC wire protocol's protobuf packages (sentry.logs.v1, sentry.agent.v1) and their Go import directory (proto/sentry/...) -- renaming the wire-level package would break every currently-deployed agent binary (confirmed two real hosts, including mail.inbuxa.com, are actively streaming through this exact contract) until rebuilt and redeployed in lockstep with an ingest cutover. Only the Go module path wrapping the generated code changes. Infrastructure: every docker-compose container name (root and three component-level compose files); the Helm chart (directory, Chart.yaml, named-template helpers, all templates, values.yaml image repos); Kubernetes Operator (CRD group sentry.io -> cairnobs.io, both CRD YAML files, Go identifiers, RBAC markers); the coupled enterprise/tenantcrd package. Caught and fixed real path-coupling bugs along the way: the Helm chart's search/ingest volume mounts and the dev-only-credential detection constant vs. docker-compose.yml's literal values had to move together or a security warning would have silently stopped firing. Data plane: Postgres database sentry_metadata -> cairnobs_metadata and role sentry -> cairnobs; ClickHouse database sentry -> cairnobs; Kafka topic sentry.logs.raw -> cairnobs.logs.raw and its consumer groups. Source-level defaults, docker-compose.yml, and every migrate.sh/ provision script default updated together; already-applied migration files left untouched per this repo's immutable-migration convention. Verified at every layer: all 13 Go modules build/vet/test clean, both Rust workspaces (agent, search) build/clippy/test clean, npm run check/ build clean, docker compose config validates on all four compose files. Live-verified against a real docker stack multiple times through this work, including a final fresh-volume run confirming the actual renamed Postgres database/role, ClickHouse database, and Kafka topic all work end to end with a real login and query, zero console errors.
89 lines
3.8 KiB
Markdown
89 lines
3.8 KiB
Markdown
# api
|
|
|
|
Cairn OBS's query API: a single `POST /query` endpoint accepting either the
|
|
pipe syntax or raw SQL, compiled and routed across ClickHouse and Tantivy
|
|
by `internal/querylang`. Replaces Phase 0/1's two separate placeholder
|
|
endpoints (raw-SQL-only `/query`, free-text-only `/search`) — see
|
|
`/docs/query-language-design.md` for the grammar, IR, and routing design,
|
|
and `/docs/query-language-reference.md` for the user-facing syntax.
|
|
|
|
## Why plain REST, not gRPC + REST gateway
|
|
|
|
CLAUDE.md pins the control plane to "Go, gRPC + REST gateway." This
|
|
service is plain `net/http` instead — a deliberate simplification, not a
|
|
change to the pinned stack. Wiring up a `.proto` service,
|
|
`google.api.http` annotations, and `protoc-gen-grpc-gateway` codegen for
|
|
one endpoint doesn't buy much at this size. `api` *does* speak gRPC
|
|
internally — to `/search` — this simplification is about the
|
|
public-facing surface only.
|
|
|
|
## Endpoint
|
|
|
|
`POST /query` — body `{"query": "...", "language": ""}`, response
|
|
`{"columns": [...], "rows": [[...], ...]}` or `{"error": "..."}`.
|
|
|
|
- `query` is either pipe syntax (`service=api | where status>=500 |
|
|
stats count by host`) or raw SQL (`SELECT ...`). Auto-detected by
|
|
whether the query starts with `SELECT` (case-insensitive).
|
|
- `language` optionally overrides detection: `"sql"` or `"spl"`. Exists
|
|
for the rare case a pipe query legitimately starts with the literal
|
|
word "select" as a bare search term.
|
|
- Both syntaxes compile to the same `querylang/ir.Plan` and execute
|
|
through the same code path — see `internal/querylang/executor` for the
|
|
four routing cases (pure ClickHouse; Tantivy prefilter + ClickHouse
|
|
rows; Tantivy prefilter + ClickHouse aggregation; raw SQL passthrough).
|
|
|
|
`GET /healthz` — for docker-compose/k8s liveness checks.
|
|
|
|
No auth. Not scoped yet — don't expose this beyond a trusted dev/homelab
|
|
network.
|
|
|
|
## Configuration
|
|
|
|
Environment variables (see `internal/config/config.go`):
|
|
|
|
| Var | Default | Purpose |
|
|
|---|---|---|
|
|
| `HTTP_LISTEN_ADDR` | `:8080` | |
|
|
| `CLICKHOUSE_ADDR` | `localhost:9000` | Native protocol port |
|
|
| `CLICKHOUSE_DATABASE` / `_USERNAME` / `_PASSWORD` | `sentry` / `default` / `` | |
|
|
| `SEARCH_GRPC_ADDR` | `localhost:50052` | Must match `/search`'s `GRPC_LISTEN_ADDR` |
|
|
| `QUERY_TIMEOUT_SECONDS` | `30` | Per-request timeout |
|
|
| `CORS_ALLOWED_ORIGIN` | `*` | Wide open by default since there's no auth yet; tighten together |
|
|
|
|
`searchclient.Dial` connects to `/search` over plain TCP, no TLS — same
|
|
trust boundary as `api`'s existing plain-TCP connection to ClickHouse.
|
|
mTLS in this project is specifically the agent↔ingest edge boundary, not
|
|
every internal hop.
|
|
|
|
## Building & testing
|
|
|
|
```sh
|
|
go build ./...
|
|
go vet ./...
|
|
go test ./...
|
|
```
|
|
|
|
```sh
|
|
# from the repo root, not api/
|
|
docker build -f api/Dockerfile -t sentry-api .
|
|
```
|
|
|
|
## Testing notes
|
|
|
|
`internal/queryapi`'s HTTP handler depends on ClickHouse and `/search`
|
|
only through the narrow interfaces `querylang/executor` defines
|
|
(`SQLRunner`, `SearchClient`), so routing, compilation, JSON encoding,
|
|
and error-status mapping are all unit-tested against fakes — no live
|
|
ClickHouse or `/search` instance needed, and the real lexer/parser/
|
|
planner run unmocked in these tests, only the backends are faked. See
|
|
`internal/querylang`'s own package docs for how compilation and
|
|
execution are tested independently of each other. `executor.ChRunner`
|
|
(the reflection-based row scanning against ClickHouse's `driver.Rows`)
|
|
and `internal/searchclient`'s actual gRPC dial are not unit-tested — the
|
|
former because faking `driver.Rows` fully would be significant
|
|
test-only scaffolding the driver's own docs say isn't meant to be
|
|
implemented by adopters; the latter because it's a thin wrapper with
|
|
nothing but wiring to test. Both are exercised end-to-end via the
|
|
docker-compose flow in `/docs/phase-2-runbook.md`.
|