Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ rules.md
coverage.out
coverage.html

# Python bytecode from scripts/
__pycache__/

# Editor and OS noise
.DS_Store
.idea/
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ All notable changes to this project are documented here. The format follows
SPL.
- Fuzz targets `FuzzParseSPL1` and `FuzzParseSPL2`, and a lexer-parity test
that tokenizes one corpus with both generated lexers.
- A query corpus under `conformance/corpus/` with 2,812 queries in three
collections. `spl1` and `spl2` hold the example queries from the SPL and SPL2
search references, gathered across Splunk Enterprise documentation versions
(9.0 through 10.0) and from the current SPL2 reference;
`spl1-detections` holds 2,171 searches from the pinned Splunk
`security_content` detections with the repository's own macros expanded, and
is recorded as a derived collection with its transformation and its
Apache-2.0 licence. Every `metadata.json` records the dialect, the kind, and
the versions each query appeared in, because a query file does not say which
release it belongs to. `TestCorpus` requires every query to parse or be
refused with a positioned diagnostic, records each outcome so behaviour
changes are reviewable, and fails when an implemented command has no corpus
coverage in its dialect. `scripts/gather-corpus.py` refreshes the corpus and
is never run by tests.

### Changed

Expand Down
41 changes: 41 additions & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ conformance/
│ ├── promql/ PromQL-specific output and refusals
│ ├── spl2/ SPL2 subset (`spl_version: 2`)
│ └── errors/ parser and unsupported-construct refusals
├── corpus/ query collections, one directory per source
│ ├── spl1/ documented, with the Splunk versions as metadata
│ ├── spl1-detections/ derived from security_content detections
│ └── spl2/ documented, published unversioned
├── fixtures/
│ ├── mappings/ mapping files referenced by case metadata
│ └── data/ NDJSON seed data for the engines
Expand Down Expand Up @@ -124,6 +128,43 @@ interleaved failure, and `-parallel N` to raise or lower the bound.
go test ./conformance -parallel 1 -v
```

## Query corpus

`corpus/` holds the queries the parser is tested against at breadth. It is not
a second compatibility contract: `cases/` is what OpenSPL promises to emit,
while the corpus is the broad input the parser has to survive. A collection is
one of two kinds:

- **Documented.** The example queries of the Splunk SPL and SPL2 search
references, gathered across documentation versions.
- **Derived.** The searches of the Splunk `security_content` detections, with
the repository's own macro definitions expanded. The source does not publish
them as example queries, so the collection records its transformation and its
licence in `metadata.json` and ships the licence text beside the queries.

`TestCorpus` runs with the offline suite and asserts three things:

- **Robustness.** Every query parses, or is refused with a positioned
diagnostic. A panic, an error that is not a `*diag.Error`, or a position
outside the input fails, whatever the query says.
- **Stability.** The outcome (`accepted`, or `error:<code>`) matches the
recorded baseline in `queries.jsonl`, so a behaviour change on gathered
syntax appears as a reviewable diff. Re-record it with `make corpus-update`
and read the diff before committing.
- **Coverage.** Every implemented command appears at the start of at least one
stage in the collections of its dialect. A command with no corpus query is a
command nothing tests.

The dialect, the kind, and the source versions live in each collection's
`metadata.json`, and each query lists the versions that contain it. Nothing is
inferred from the query text: `from` is the only textual hint, and classic SPL
and SPL2 both use it.

`scripts/gather-corpus.py` refreshes the corpus from the documentation and from
the pinned `security_content` commit. It needs network access, so neither the
tests nor CI run it. See [conformance/corpus/README.md](conformance/corpus/README.md)
for the format, the cache, and the provenance.

## Engine cases

`engines/cases.tsv` lists queries that must be accepted and executed by a real
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LDFLAGS := -s -w \
-X github.com/be-thomas/openspl/pkg/version.Commit=$(COMMIT) \
-X github.com/be-thomas/openspl/pkg/version.Date=$(DATE)

.PHONY: all build test race vet fmt fmt-check check hooks generate generate-check conformance conformance-update e2e clean help
.PHONY: all build test race vet fmt fmt-check check hooks generate generate-check conformance conformance-update corpus-update e2e clean help

all: check

Expand Down Expand Up @@ -65,6 +65,9 @@ conformance:
conformance-update:
go test ./conformance -count=1 -update

corpus-update:
go test ./conformance -count=1 -run TestCorpus -update-corpus

e2e:
./conformance/engines/run.sh

Expand All @@ -86,5 +89,6 @@ help:
'generate-check fail if committed parsers differ from the grammars' \
'conformance run the offline conformance suite' \
'conformance-update regenerate goldens and expectations' \
'corpus-update re-record the query corpus outcomes' \
'e2e run the Docker engine harness' \
'clean remove build output'
27 changes: 27 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ listed here with their versions and licenses.
| Upstream | <https://www.antlr.org/> |
| Role | Build-time only. Generates the Go parser sources committed under `pkg/parser/*/gen`. Never shipped, and not needed to build OpenSPL. |

## Splunk documentation examples

| Field | Value |
|---|---|
| Source | Splunk Enterprise search reference and Splunk Cloud Platform SPL2 search reference |
| Upstream | <https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference>, <https://help.splunk.com/en/splunk-cloud-platform/search/spl2-search-reference> |
| Role | Test data only. `conformance/corpus` reproduces the documentation's short example queries as parser-coverage inputs. No prose is included, nothing is linked into the binary, and the gatherer records each query's page and documentation versions. |
| Terms | The example queries remain Splunk's material and are not covered by OpenSPL's license. |

## Splunk security_content detections

| Field | Value |
|---|---|
| Source | Splunk security_content detection searches |
| Commit | `a3f6523eabf696d66e20fdd80766bfae95575577` |
| License | Apache License 2.0, reproduced at [`conformance/corpus/spl1-detections/LICENSE`](conformance/corpus/spl1-detections/LICENSE) |
| Upstream | <https://github.com/splunk/security_content> |
| Role | Test data only. `conformance/corpus/spl1-detections` holds the `search` value of each detection, transformed for parser coverage. Nothing is linked into the binary. |

Changes to that material, as section 4(b) of the license requires stating: the
`search` value of each detection was extracted; the repository's own macro
definitions were expanded into it; the pipeline was cut at the first stage that
calls a macro the repository does not define; whitespace was normalized; and
texts that occur more than once were stored once, with every source detection
listed. The detection title, description, and all other fields were dropped.
The collection's `metadata.json` records the same transformation.

## Generated code

The Go files under `pkg/parser/spl1/gen` and `pkg/parser/spl2/gen` are produced
Expand Down
152 changes: 152 additions & 0 deletions conformance/corpus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Query corpus

Two kinds of query collections, gathered once and checked in, so the parser is
exercised against far more real syntax than the hand-written conformance cases
can cover.

- **Documented.** The example queries of the Splunk SPL and SPL2 search
references, gathered across documentation versions.
- **Derived.** The searches of the Splunk `security_content` detections, with
the repository's own macro definitions expanded. They are not published as
example queries, so they are labelled derived and their transformation is
recorded in `metadata.json`.

This is a breadth and robustness corpus, not the compatibility contract.
[`../cases/`](../cases/) is what OpenSPL promises to emit; the corpus is what
the parser must survive: every query either parses, or is refused with a
positioned diagnostic, and either way the outcome is recorded so a change shows
up in review.

## Layout

```text
corpus/
├── spl1/ documented, Splunk Enterprise 9.0-10.0
│ ├── metadata.json dialect, versions, counts, provenance
│ └── queries.jsonl one query per line
├── spl1-detections/ derived from security_content detection searches
│ ├── LICENSE Apache-2.0, the source's licence
│ ├── metadata.json
│ └── queries.jsonl
└── spl2/ documented, SPL2 (published unversioned)
├── metadata.json
└── queries.jsonl
```

Every collection has the same two data files; `LICENSE` appears only where the
source carries a licence of its own.

Each `queries.jsonl` line is one query:

```json
{"query":"index=* | stats count(eval(status=\"404\")) AS count_status BY sourcetype","pages":["search-commands/stats"],"versions":["9.0","9.1","9.2","9.3","9.4","10.0"],"expect":"accepted"}
```

| Key | Meaning |
|---|---|
| `query` | The query, whitespace-normalized to one line. |
| `pages` | Source pages the query appears on, relative to `base_url`. |
| `versions` | Versions of the source that contain the query. |
| `expect` | `accepted`, or `error:<code>` for the diagnostic the parser returns. |

A query that appears in several versions is stored once and lists every version
it appears in. A query that only one version documents keeps that narrower
list, which is how version-specific syntax stays visible.

`metadata.json` records `source`, `base_url`, `retrieved`, `versions`, the query
counts, and the gatherer that produced the files, plus these keys:

| Key | Meaning |
|---|---|
| `kind` | `documented` for the source's own examples, `derived` for a transformation. |
| `transform` | For derived collections: exactly what was done to the source text. |
| `license` | For derived collections: the source's licence. |

Required keys are validated by `TestCorpus`, so a truncated or hand-edited file
fails instead of silently shrinking the corpus.

## The version is metadata, never inferred

A query file does not say which Splunk release it belongs to, and the parser
does not try to guess: `from` is the only textual hint, and classic SPL and
SPL2 both use it. The version lives in `metadata.json` (`versions`,
`queries_per_version`) and on each line (`versions`). The documentation for
SPL2 is published unversioned, so its collection records the single entry
`current` plus the retrieval date. The derived collection records the
`security_content` commit it was taken from.

## The derived collection

`detections/**/*.yml` holds one detection per file, and each `search:` is a real
classic-SPL query. Two things stand between that text and a corpus line:

1. **Macros.** Most searches call macros, and the call alone is not a query. The
definitions in the repository's own `macros/` are expanded first, with
`$argument$` substitution, up to eight rounds of nesting.
2. **Undefined macros.** A detection usually ends with a filter macro that
`security_content` does not define, because it is meant to come from an app.
Those cannot be expanded, so the pipeline is cut at the first stage that
still calls one. What remains is the detection's own SPL up to that point,
with nothing invented and nothing reordered.

The queries are deduplicated by text; `pages` lists every detection that shares
a query. Duplicated detection searches are common, and storing the same text
twice would only slow the test down.

## Refreshing

The gatherer needs network access and is never run by the tests or by CI:

```sh
scripts/gather-corpus.py # every collection
scripts/gather-corpus.py --dialect spl2 # one dialect
scripts/gather-corpus.py --versions 9.4,10.0 # a subset of SPL versions
scripts/gather-corpus.py --skip-detections # documentation only
```

It caches every page and archive under `~/.cache/openspl/docs`, so a re-run
after a partial failure does not refetch what it already has. Existing `expect`
values are carried over by query text, so re-gathering alone never rewrites a
baseline. A version that yields no queries aborts the run rather than recording
empty coverage, which is what a documentation version that redirects to the
login page looks like.

## Outcomes

`expect` is a snapshot of what the parser currently does with the query, not a
claim that it is right. A query the parser refuses stays refused until the
parser is fixed; fixing it changes exactly that line.

```sh
make corpus-update # go test ./conformance -run TestCorpus -update-corpus
```

Read the diff before committing it: every changed outcome is a behaviour
change, and the corpus is how an unintended one gets noticed.

`TestCorpus` also fails when an implemented command never appears at the start
of a stage anywhere in the collections of its dialect, because a command with no
corpus query is a command nothing tests. The rule is per dialect rather than per
collection so that a derived collection, which is heavy on searches over raw
events, does not have to reproduce the documentation's command coverage.

## Provenance

Documented collections: `query` values are the documentation's own example
blocks, reproduced as short syntax specimens for parser coverage; the prose
around them is not included. They remain the property of Splunk and are
attributed here with the page and version they came from.

Derived collection: the detection searches come from
[splunk/security_content](https://github.com/splunk/security_content), pinned at
commit `a3f6523eabf696d66e20fdd80766bfae95575577`, under the Apache License 2.0;
the licence text is in [`spl1-detections/LICENSE`](spl1-detections/LICENSE).
Changes to that material, as the licence requires stating: the `search` value of
each detection was extracted, its macros were expanded from the same
repository's `macros/` definitions, the pipeline was cut at the first stage that
calls a macro the repository does not define, whitespace was normalized, and
duplicate texts were stored once. The detection title, description, and every
other field were dropped.

[`../../THIRD_PARTY_NOTICES.md`](../../THIRD_PARTY_NOTICES.md) records both
sources.
Loading
Loading