Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
pull_request:
branches: [ "master" ]

permissions:
contents: read
# Allows the lint job's only-new-issues option to read the PR diff.
pull-requests: read

jobs:

build:
Expand All @@ -25,5 +30,44 @@ jobs:
CGO_ENABLED=0 go build -ldflags="-extldflags=-static" -o gigapipe cmd/gigapipe/main.go

- name: Unit tests
run: go test ./...
run: go test -race ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
# Must be built with a Go toolchain >= go.mod's `go` directive, or
# golangci-lint refuses to run at all.
version: v2.13.1
# Grandfather in pre-existing findings; gate only newly introduced
# ones so adoption doesn't require cleaning up the whole repo first.
only-new-issues: true

arch-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'

- name: Install go-arch-lint
run: go install github.com/fe3dback/go-arch-lint@v1.15.0

# Report-only: baselines current package coupling against
# .go-arch-lint.yml without gating the merge. continue-on-error keeps
# this from blocking a PR while still surfacing the report.
- name: go-arch-lint check (report-only)
continue-on-error: true
run: go-arch-lint check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.idx
/docker
/deps
/.claude/
52 changes: 52 additions & 0 deletions .go-arch-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# go-arch-lint configuration, report-only baseline (schema v3).
#
# This describes the current *rough* top-level layering of the repo
# (reader/, writer/, ruler/, shared/, ctrl/, cmd/, view/) so that
# `go-arch-lint check` runs cleanly today and can be tightened later.
# Dependency rules are deliberately permissive (anyProjectDeps/anyVendorDeps)
# — the point of this pass is to baseline current package coupling, not to
# enforce boundaries that don't exist yet. Run "go-arch-lint check" locally
# to see the current dependency graph; this is not wired as a CI gate.
version: 3

allow:
depOnAnyVendor: true

components:
cmd:
in: cmd/**
ctrl:
in: ctrl/**
reader:
in: reader/**
writer:
in: writer/**
ruler:
in: ruler/**
shared:
in: shared/**
view:
in: view/**
test:
in: test/**

deps:
cmd:
anyProjectDeps: true
ctrl:
anyProjectDeps: true
reader:
anyProjectDeps: true
writer:
anyProjectDeps: true
ruler:
anyProjectDeps: true
shared:
# shared already imports from reader/ and writer/ today (e.g.
# shared/commonroutes/controller.go); left permissive rather than
# inventing a boundary that doesn't exist yet.
anyProjectDeps: true
view:
anyProjectDeps: true
test:
anyProjectDeps: true
62 changes: 62 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# golangci-lint configuration (schema v2).
#
# Goal for this pass: a reasonable, not-overly-strict baseline appropriate for
# a mid-size *existing* codebase, not a from-scratch project. Linter choice
# and tuning below were derived by actually running golangci-lint against
# this repo and looking at what fired:
#
# - errcheck is intentionally NOT enabled. This codebase idiomatically
# ignores errors from things like http.ResponseWriter.Write and
# rows/conn.Close() in defers; enabling it flags ~170 pre-existing call
# sites that are not bugs, just this codebase's style.
# - govet's "structtag" and "composites" checks are disabled. Both parsers
# built on github.com/alecthomas/participle encode grammar rules as
# struct tags (e.g. `@@`, `"(" @@ ")"`) that are not real reflect
# struct tags, and lexer rule tables use unkeyed composite literals by
# participle's own convention. These would fire on every new grammar
# rule added to the PromQL/LogQL/TraceQL parsers, which is exactly the
# code this milestone's corpus work touches most.
# - staticcheck is restricted to the SA* (actual bug/deprecation) checks.
# The ST*/S*/QF* style and quickfix checks bundled into staticcheck by
# default add ~90 pre-existing stylistic findings (e.g. "could use
# strings.ReplaceAll", implicit type on declaration) that are not worth
# a hard gate right now.
#
# ineffassign, unused, misspell, unconvert, gofmt and goimports are enabled
# as-is; the CI job runs golangci-lint-action with only-new-issues so this
# initial adoption gates new/changed code without requiring a full
# pre-existing-debt cleanup as a prerequisite.
version: "2"

linters:
default: none
enable:
- govet
- ineffassign
- unused
- staticcheck
- misspell
- unconvert
settings:
govet:
disable:
- structtag
- composites
staticcheck:
checks:
- "SA*"
exclusions:
paths:
# Ported/vendored-style algorithm implementations (two independent
# copies pre-date this config); not code we want a style gate on.
- reader/utils/cityhash102
- writer/utils/helputils/cityhash102

formatters:
enable:
- gofmt
- goimports
exclusions:
paths:
- reader/utils/cityhash102
- writer/utils/helputils/cityhash102
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,47 @@ docker-compose ?= docker-compose
# server (via compose interpolation) and the test runner see the same value.
export QRYN_RULER_ENABLED ?= true

# Query heads with a parser fuzz target.
heads := promql logql traceql

# HEAD/DURATION are set on the command line, e.g. `make fuzz HEAD=promql`.
HEAD ?=
DURATION ?= 60s

.PHONY: docker e2e-deps e2e-build e2e-test e2e-cleanup e2e-full e2e-ci \
build test-unit lint arch-lint fuzz

docker:
docker build -f scripts/deploy/docker/Dockerfile -t gigapipe .

# Build the gigapipe binary the same way CI does.
build:
go mod tidy
CGO_ENABLED=0 go build -ldflags="-extldflags=-static" -o gigapipe cmd/gigapipe/main.go

# Run the full unit-test suite with the race detector, matching CI.
test-unit:
go test -race ./...

# Run golangci-lint with the repo's committed config, gating only issues
# introduced since origin/master (mirrors CI's only-new-issues option) so
# this doesn't fail locally on pre-existing repo-wide debt.
lint:
golangci-lint run --new-from-rev=origin/master

# Run go-arch-lint in report-only mode against the baseline layering config.
arch-lint:
go-arch-lint check

# Run the native Go parser fuzz target for one query head:
# make fuzz HEAD=promql|logql|traceql [DURATION=60s]
fuzz:
@case " $(heads) " in \
*" $(HEAD) "*) ;; \
*) echo "fuzz: unknown or missing HEAD '$(HEAD)' (expected one of: $(heads)); usage: make fuzz HEAD=promql [DURATION=60s]" >&2; exit 1 ;; \
esac
go test "./reader/$(HEAD)/$(HEAD)_parser" -run '^$$' -fuzz "FuzzParse" -fuzztime "$(DURATION)"

e2e-deps:
if [ ! -d ./deps/qryn-test ]; then git clone https://github.com/metrico/qryn-test.git ./deps/qryn-test; fi
cd deps/qryn-test && git pull && git checkout main && git pull;
Expand Down
11 changes: 11 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ For end-to-end tests:
make e2e-full
```

The Makefile also wraps the same build/test/lint lanes CI runs, plus
parser-fuzz helpers for the query transpilers:

```bash
make build # build the gigapipe binary the way CI does
make test-unit # go test -race ./..., matching CI
make lint # golangci-lint, gated to issues new since origin/master
make arch-lint # go-arch-lint report against .go-arch-lint.yml
make fuzz HEAD=promql DURATION=60s # run the native Go parser fuzz target for a query head
```

## Submitting a Pull Request

1. Create a branch:
Expand Down
70 changes: 70 additions & 0 deletions reader/internal/parserpin/parserpin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package parserpin

import (
"reflect"
"testing"
)

// ParserPinCase is one table-driven "valid query -> expected AST shape" or
// "invalid query -> expected error class" pin for a single query head's
// parser.
//
// Deep AST-shape assertions are genuinely different per head (PromQL,
// LogQL and TraceQL parsers produce unrelated types with no common
// interface worth inventing), so this helper only guarantees the shallow,
// generic assertion that is easy to make generic: a valid query parses to a
// non-nil root with no error, and an invalid query returns a non-nil error.
// A case that wants a deeper shape pin supplies Check, run only when parsing
// itself succeeds as expected.
type ParserPinCase[T any] struct {
// Name is the subtest name (t.Run).
Name string
// Query is the raw text handed to the parser.
Query string
// WantErr marks this as an invalid-query case: Parse must return a
// non-nil error, and Check (if set) is not run.
WantErr bool
// Check, if set, receives the parsed AST for a valid-query case for a
// head to assert deeper shape beyond "non-nil root".
Check func(t *testing.T, ast T)
}

// RunParserPins runs every case in cases as a subtest, calling parse and
// asserting either a non-nil root with no error (WantErr == false) or a
// non-nil error (WantErr == true).
func RunParserPins[T any](t *testing.T, parse func(query string) (T, error), cases []ParserPinCase[T]) {
t.Helper()
for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
ast, err := parse(c.Query)
if c.WantErr {
if err == nil {
t.Fatalf("Parse(%q): expected an error, got none", c.Query)
}
return
}
if err != nil {
t.Fatalf("Parse(%q): unexpected error: %v", c.Query, err)
}
if isNilAST(ast) {
t.Fatalf("Parse(%q): expected a non-nil AST root", c.Query)
}
if c.Check != nil {
c.Check(t, ast)
}
})
}
}

// isNilAST reports whether a generic AST root (typically a pointer) is nil,
// without requiring T to satisfy any particular interface.
func isNilAST(ast any) bool {
v := reflect.ValueOf(ast)
switch v.Kind() {
case reflect.Pointer, reflect.Interface, reflect.Slice, reflect.Map, reflect.Chan, reflect.Func:
return v.IsNil()
default:
return false
}
}
Loading
Loading