Repository navigation
conformance: test the parser against the documented query corpus - #2
Conversation
Add conformance/corpus with the example queries from the Splunk SPL and SPL2 search references, gathered once and checked in, and TestCorpus to run them. A query file does not say which release it belongs to, and the parser cannot guess: `from` is the only textual hint and both dialects use it. Each collection therefore records its dialect, documentation versions, retrieval date and counts in metadata.json, and each line lists the versions that contain it. TestCorpus asserts three things. Robustness: every query parses, or is refused with a positioned *diag.Error; a panic or an unpositioned error fails whatever the query says. Stability: the outcome matches the recorded baseline, so a change in what the parser does with documented syntax is a reviewable diff. The baseline is a snapshot, not a correctness claim, and `make corpus-update` re-records it. Coverage: every implemented command starts at least one stage in its collection. That check found 17 real Splunk commands missing from the known-command table (localop, makemv, sitop, anomalousvalue, audit, addcoltotals, meventcollect, concurrency, anomalies, gauge, tojson, geoip, overlap, convert, delta, erex, geom), so they now report unsupported-command instead of unknown-command; the table is alphabetical for checking against the reference. scripts/gather-corpus.py is the only part that touches the network, and neither the tests nor CI run it. The queries are the documentation's own example blocks and remain Splunk's material; the provenance is recorded in conformance/corpus/README.md and THIRD_PARTY_NOTICES.md.
be-thomas
left a comment
There was a problem hiding this comment.
The corpus is a useful addition, and the harness itself is careful: it checks positioned diagnostics, recovers panics, preserves baselines by query text, and the gatherer reproduces the checked-in files byte-for-byte (I re-ran it offline against the page cache; both queries.jsonl and both metadata.json came out identical). gofmt, go vet and make check are clean, and 26 CLI spot checks matched the recorded expect.
I did find one path that can remove corpus content with no signal (a partial fetch failure silently shrinks the corpus), two classification gaps that make the corpus record success for documented commands the parser does not actually implement, and a filter rule that drops every documented query containing a subsearch or array. There are also two smaller workflow/documentation problems around -update-corpus and running the gatherer.
Finding summary:
scripts/gather-corpus.py: a page whose fetch keeps failing is skipped, and the script still rewrites the corpus with fewer queries and exits cleanly (reproduced: 505 -> 500).pkg/parser/commands/commands.go:spl1Knownis missing seven documented commands that the corpus already contains; they parse as free-text search and are recordedaccepted.conformance/corpus/spl2/queries.jsonl:fieldsummaryis a documented SPL2 command but is absent fromspl2Known, so two baselines recordunknown-command.scripts/gather-corpus.py: the placeholder rule rejects[...], which in SPL is a subsearch or array, so no committed query contains a bracket.scripts/gather-corpus.py: the acceptance rule lets syntax templates and REST parameter fragments into the corpus.conformance/corpus_test.go:-update-corpusrewrites the file and then fails the test.scripts/gather-corpus.py: the docstring names the wrong flag (-update).conformance/corpus/README.md: the documented direct invocation fails because the script is not executable.
Verdict: findings to address; the silent-shrink path in item 1 is the one I would block on.
Address the review of the documented corpus: - gather-corpus.py: a failed page fetch is now an error, not a page without queries, so the corpus cannot shrink because the network was flaky; --allow-partial overrides it deliberately. - gather-corpus.py: drop the bracket filter. It removed subsearches and array literals along with the configuration stanzas it was meant for. A block that starts with a bracket and a block containing the commandname metavariable are now refused directly. - corpus_test.go: -update-corpus rewrites the baseline without also failing the run, so `make corpus-update` exits 0 when re-recording. - commands.go: regenerate spl1Known from the search reference and list every documented SPL2 command in spl2Known. Seven SPL1 commands were parsed as free text, which emitted a query instead of a refusal, and fieldsummary was reported as unknown. The corpus grows to 549 SPL1 and 92 SPL2 queries; baselines re-recorded with `make corpus-update`.
The documented corpus has breadth, but a documentation example is short and usually demonstrates one command. Add a second kind of collection: the detection searches of the Splunk security_content repository, which are the queries analysts actually write. Those searches call macros, so the gatherer expands the repository's own macro definitions and cuts the pipeline at the first stage that still calls a macro the repository does not define. What is stored is the detection's own SPL up to that point, with nothing invented and nothing reordered. The collection is recorded as kind "derived" with the transformation and the Apache-2.0 licence, and the licence text ships beside the queries. That adds 2145 unique queries, taking the corpus from 641 to 2786. The recorded baselines show where the parser actually stands: 1019 of the new refusals are tstats, 113 rename, and the largest syntax classes are space-separated stats arguments, IN value lists, and JSON object literals. TestCorpus now validates the kind and what it promises, requires 2000 queries rather than 200, and checks command coverage per dialect rather than per collection: a source that documents a single command should not have to repeat every other command's example.
be-thomas
left a comment
There was a problem hiding this comment.
Reviewed the PR delta dc83fd3..f312cd3, concentrating on the new derived spl1-detections collection and its gatherer. Verified that make check and go test -race ./... pass, that a re-run of scripts/gather-corpus.py is byte-identical (git status stays clean), and that spl1-detections/LICENSE is identical to the upstream security_content Apache-2.0 text at the pinned commit. The documented counts (549 / 2145 / 92, total 2786), the layout, and the available flags are accurate. Six defects are reported below: three in how the gatherer derives the queries (a YAML truncation, the backtick cut rule, and the ordering of whitespace normalization), two gaps in what TestCorpus actually validates, and one archive-extraction weakness.
Fold quoted search scalars that continue on following lines instead of storing the first line, and refuse a search whose quote never closes. Cut a pipeline only where a stage still calls a macro, so the triple backtick code fences inside detection searches are kept rather than read as unexpanded macros. Normalize whitespace after macro expansion, which can itself introduce newlines. Extract the pinned archive only through tarfile's data filter, and remove the temporary tree when the cached body is not a readable archive. Check the declared licence text instead of the file's presence, and reconcile queries_per_version with the versions recorded on each query line. Re-gather: 2,812 queries (549 documented SPL1, 2,171 detections, 92 SPL2).
What this changes
Adds
conformance/corpus/: query collections gathered once and checked in,plus
TestCorpusto run them against both front-ends on everymake check.There are two kinds of collection, and the distinction is recorded in each
metadata.json.spl1spl1-detectionssecurity_contentdetections, macro-expandedspl22,812 queries in total.
scripts/gather-corpus.pyrefreshes all three. It is the only part thattouches the network and is never run by the tests or CI.
conformance/corpus/README.mddocuments the format, the refresh andbaseline workflow, and the provenance;
CONFORMANCE.md,THIRD_PARTY_NOTICES.mdandCHANGELOG.mdare updated.d358ee6,and the six from the second review in
346331a: multi-line quoted searchscalars, code fences mistaken for macros, whitespace introduced by macro
expansion, licence-text checking,
queries_per_versionreconciliation, andcleanup of a failed archive extraction.
The derived collection
Documentation examples are short and usually demonstrate one command. The
detection searches in
splunk/security_contentare the queries analystsactually write. Most call macros, so the gatherer expands the repository's own
definitions (with
$argument$substitution, up to eight rounds) and cuts thepipeline at the first stage that still calls a macro the repository does not
define — those usually come from an app. What is stored is the detection's own
SPL up to that point: nothing invented, nothing reordered, duplicates stored
once with every source detection listed.
The repository is pinned at commit
a3f6523eabf696d66e20fdd80766bfae95575577.It is Apache-2.0, so the collection records
kind,transformandlicensein
metadata.json, ships the licence text beside the queries, andTHIRD_PARTY_NOTICES.mdstates the changes as section 4(b) requires.The version is metadata, never inferred
A query file does not say which release it belongs to and the parser cannot
guess it —
fromis the only textual hint and both dialects use it — so eachcollection records dialect, versions, retrieval date and counts in
metadata.json, and each line lists the source versions that contain it. Thederived collection records the
security_contentcommit instead of a Splunkrelease; SPL2 is published unversioned and records
current.The test
TestCorpusasserts three properties, aggregated per dialect:*diag.Error. A panic, an error that is not a*diag.Error, a diagnosticwithout a code, or a position outside the input fails, whatever the query
says.
acceptedorerror:<code>) matches thebaseline on each line, so any change in what the parser does with gathered
syntax shows up as a reviewable diff.
make corpus-updatere-records it andexits 0; the baseline is a snapshot, not a correctness claim.
collections of its dialect. One documented exception: the SPL2 reference
describes WHERE as a clause of FROM, so no documented query starts a piped
wherestage.It also validates each collection's
kindand what that kind promises: aderived collection must name its transformation, its licence, and carry the
licence text beside the queries; a documented collection must not claim
either. The corpus floor is 2,000 queries.
Recorded outcomes
unsupported-commandsyntaxspl1unsupported-subsearch5,unknown-command1)spl1-detectionsunknown-command4,unsupported-subsearch3)spl2What the corpus says about the parser
The derived collection is where the gaps are visible, and they are the point
of the exercise rather than a regression:
tstatsalone, 112 arerename, 63fillnull, 32bucket, 27spath, 14mstats, 8lookup.unexpected "-"(248),unexpected ","(179, mostlyIN (a, b)value lists),unexpected character "{"(98,JSON object literals), and space-separated
statsarguments(
stats count min(_time) AS firstTime …, about 125 acrossmin/max/values/dc), plus0x…numeric literals (21).unexpected character ""`(38) is the code-fence prose a few detections quote inside their own search.
Fixing any of these changes exactly one baseline line per query.
Tests run
make check— gofmt,go vet,go test ./..., build: pass.go test -race ./...: pass../scripts/gather-corpus.pyre-run twice: byte-identical output, so thechecked-in corpus matches the gatherer and the gatherer is idempotent.
make corpus-updatefollowed by a cleanTestCorpus.LICENSEunderApache-2.0and aqueries_per_versionset to 1 both failTestCorpus; a non-tar cached bodyexits with the archive error and leaves no temporary directory behind.
inline comment is fixed or answered and all threads are resolved.
Open questions
documented SPL2 queries are syntax refusals. The reference writes clauses
without a pipe (
FROM main WHERE status=200 | stats count() BY host), whilethe subset requires
from main | where ... | stats ...;GROUP BY ... SELECT, quoted aliases andstats count AS xare also documented. Shouldthe SPL2 grammar accept unpiped clauses before the corpus is widened
further?
hiding them.
tstatsis the single largest; space-separatedstatsarguments and
IN (…)lists are the cheapest syntax wins. Is there an orderthe maintainer prefers, or should this PR stay corpus-only?
data with page and version provenance, and the detection searches are
Apache-2.0 with the notice and licence text committed. Is checking both in
acceptable, or should either be gathered locally instead of committed?