Skip to content

Commit 2f8dbc8

Browse files
committed
refactor: simplified the framework
Signed-off-by: bwplotka <bwplotka@gmail.com>
1 parent 6009993 commit 2f8dbc8

33 files changed

Lines changed: 2836 additions & 4460 deletions
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
name: Compliance Tests
2-
1+
---
2+
name: Compliance
33
on:
44
pull_request:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
510

611
jobs:
7-
remotewrite-compliance:
12+
remotewrite-sender:
13+
name: Remote Write Sender Compliance Tests
814
runs-on: ubuntu-latest
9-
15+
container:
16+
image: quay.io/prometheus/golang-builder:1.25-base
1017
steps:
11-
- uses: actions/checkout@v4
12-
13-
- name: Set up Go
14-
uses: actions/setup-go@v4
15-
with:
16-
go-version: '1.22'
17-
18-
- name: Run Remote Write Prometheus Compliance Tests
19-
run: |
20-
cd remotewrite/sender
21-
go test --tags=compliance -run "TestRemoteWrite/prometheus/.+" -v ./
18+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
19+
with:
20+
persist-credentials: false
21+
- run: cd remotewrite && make sender

remotewrite/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
results.json
2+
config.yml
3+
index.preloaded.html
4+
bin/

remotewrite/Makefile

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Set the default target to 'help' so it runs when you just type 'make'
22
.DEFAULT_GOAL := help
33

4-
DEBUG=? ""
4+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
5+
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
6+
ROOT_DIR := $(dir $(mkfile_path))
7+
8+
PROMETHEUS_RW_COMPLIANCE_TEST_RE=""
9+
PROMETHEUS_RW_COMPLIANCE_SKIP_TEST_RE=""
10+
TIMEOUT="10m"
11+
SED=$(shell which gsed 2>/dev/null || which sed)
12+
RESULT_FILE="$(ROOT_DIR)/results.json"
13+
14+
## Common vars.
15+
DEBUG=""
16+
## Sender vars.
17+
PROMETHEUS_COMPLIANCE_RW_SENDERS="prometheus"
518

619
.PHONY: help
720
help: ## Show this help message
@@ -10,14 +23,30 @@ help: ## Show this help message
1023
@echo "Available commands:"
1124
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
1225

13-
PROMETHEUS_RW2_COMPLIANCE_SENDERS =? "prometheus"
1426

1527
.PHONY: sender
16-
sender: ## Run sender compliance tests for a given PROMETHEUS_RW2_COMPLIANCE_SENDERS with a HTML results view.
17-
cd ./sender && DEBUG=$(DEBUG) PROMETHEUS_RW2_COMPLIANCE_SENDERS="$(PROMETHEUS_RW2_COMPLIANCE_SENDERS)" go test -json | tee results.json
18-
@echo "Opening HTML result view; load the `results.json` file"
19-
@open ./index.html
20-
21-
.PHONY: sender-check
22-
sender-ci: ## Run sender compliance tests for a given PROMETHEUS_RW2_COMPLIANCE_SENDERS suitable for CI.
23-
cd ./sender && DEBUG=$(DEBUG) PROMETHEUS_RW2_COMPLIANCE_SENDERS="$(PROMETHEUS_RW2_COMPLIANCE_SENDERS)" go test -v
28+
sender: ## Run sender compliance tests for a given senders suitable for humans and CI.
29+
cd ./sender && DEBUG=$(DEBUG) PROMETHEUS_COMPLIANCE_RW_SENDERS=$(PROMETHEUS_COMPLIANCE_RW_SENDERS) go test -run $(PROMETHEUS_RW_COMPLIANCE_TEST_RE) -skip $(PROMETHEUS_RW_COMPLIANCE_SKIP_TEST_RE) -v -timeout=$(TIMEOUT)
30+
31+
.PHONY: sender-html
32+
sender-html: ## Run sender compliance tests for a given senders with a HTML results view.
33+
@cd ./sender && DEBUG=$(DEBUG) PROMETHEUS_COMPLIANCE_RW_SENDERS=$(PROMETHEUS_COMPLIANCE_RW_SENDERS) go test -run $(PROMETHEUS_RW_COMPLIANCE_TEST_RE) -skip $(PROMETHEUS_RW_COMPLIANCE_SKIP_TEST_RE) -json | tee $(RESULT_FILE)
34+
@$(MAKE) open-preloaded-results
35+
36+
PROMETHEUS_RW2_COMPLIANCE_RECEIVERS="local-prometheus"
37+
38+
.PHONY: receiver
39+
receiver: ## Run receiver compliance tests for a given receivers suitable for humans and CI.
40+
cd ./receiver && DEBUG=$(DEBUG) PROMETHEUS_RW2_COMPLIANCE_RECEIVERS=$(PROMETHEUS_RW2_COMPLIANCE_RECEIVERS) go test -run $(PROMETHEUS_RW_COMPLIANCE_TEST_RE) -skip $(PROMETHEUS_RW_COMPLIANCE_SKIP_TEST_RE) -v -timeout=$(TIMEOUT)
41+
42+
.PHONY: receiver-html
43+
receiver-html: ## Run receiver compliance tests for a given receivers with a HTML results view.
44+
@cd ./receiver && DEBUG=$(DEBUG) PROMETHEUS_RW2_COMPLIANCE_RECEIVERS=$(PROMETHEUS_RW2_COMPLIANCE_RECEIVERS) go test -run $(PROMETHEUS_RW_COMPLIANCE_TEST_RE) -skip $(PROMETHEUS_RW_COMPLIANCE_SKIP_TEST_RE) -json | tee $(RESULT_FILE)
45+
@$(MAKE) open-preloaded-results
46+
47+
48+
.PHONY: open-preloaded-results
49+
open-preloaded-results: # Open index.html with the preloaded results from results.json file.
50+
@# Preload to avoid CORS issue on secure browsers.
51+
@cat index.html | perl -pe 'BEGIN{local $$/; open(F,"<results.json"); $$c=<F>; close F} s/const PRELOADED_RESULT_DATA = ``;/const PRELOADED_RESULT_DATA = `$$c`;/' > index.preloaded.html
52+
@open index.preloaded.html

remotewrite/README.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@ Both [sender](#sender-compliance-sender) and [receiver](#receiver-compliance-rec
77
To generate and view results, add `-json` flag to `go test` command and `tee` the results to a file called `results.json`.
88

99
Tests are marked with compliance levels according to RFC specifications:
10-
- **MUST**: Required by specification
11-
- **SHOULD**: Recommended by specification
12-
- **MAY**: Could have by specification
13-
- **RECOMMENDED**: Not in specification but recommended for performance
10+
- **MUST**: Required by Remote Write specification
11+
- **SHOULD**: Recommended by Remote Write specification
12+
- **MAY**: Could have by Remote Write specification
13+
- **RECOMMENDED**: Not in Remote Write specification, but recommended for performance or Prometheus compatibility reasons
1414

1515
## Sender Compliance (`/sender`)
1616

17-
Tests that Remote-Write senders properly implement the protocol by forking sender instances (e.g., Prometheus), examining generated requests, and validating them against the specification.
17+
Tests that Remote-Write senders implement the RW2 protocol by running tests cases with:
18+
19+
1. Scraper exposing OpenMetrics 1.0
20+
2. Target sender to test (e.g., Prometheus),
21+
3. Special receiver that tests various elements of the request(s).
1822

1923
Tests cover:
24+
- Series encoding
2025
- Float samples encoding
2126
- Native Histograms encoding
2227
- Exemplars encoding
23-
- Protocol headers and content negotiation
24-
- Error handling and retry logic
25-
- Backoff and batching behavior
26-
- Metadata and symbol table management
28+
- Metadata encoding
29+
- Protocol headers
30+
- Error handling, basic batching and retry logic
2731
- Request formatting and compression
28-
29-
### Limitations
30-
31-
The test suite validates the format and structure of requests sent by the sender but does not verify end-to-end data flow or persistence. Because senders may have different configuration options and capabilities, passing all tests does not guarantee a sender supports every Remote-Write feature (such as Native Histograms). Some senders may not expose certain features or may require specific configuration.
32+
- Various Prometheus / OpenMetrics 1.0 semantics as "RECOMMENDED" (staleness, upness). Because this test depends on scraping behaviour we
33+
are testing some elements of the exposition format support too.
3234

3335
### Prerequisites
3436

3537
- Go 1.23 or later
36-
- The sender binary to test (e.g., Prometheus)
38+
- The sender binary you want to test (e.g., Prometheus)
39+
- Requires OpenMetrics 1.0 scrape capability.
40+
- Required Remote Write sending capability.
3741

38-
The test suite automatically downloads and runs Prometheus as the reference sender implementation. For testing custom senders, place the binary in the `bin/` directory.
42+
The test suite automatically downloads and runs Prometheus as the reference sender implementation.
3943

4044
### Configuration
4145

@@ -47,6 +51,15 @@ The test suite uses environment variables:
4751
PROMETHEUS_RW2_COMPLIANCE_SENDERS="prometheus"
4852
```
4953

54+
Currently supported senders:
55+
- `prometheus` - The reference Prometheus implementation (automatically downloaded).
56+
- `process` - For custom sender that is a local binary.
57+
58+
For testing custom senders:
59+
60+
* Add target running code and register it the `sender/main_test.go`.
61+
* Use custom process target via `PROMETHEUS_COMPLIANCE_RW_SENDERS="process"` and `PROMETHEUS_COMPLIANCE_RW_PROCESS_BINARY=<path>` envvars.
62+
5063
**Debug output:**
5164

5265
Debug variable controls if the tested process suppresses output (empty DEBUG) or not.
@@ -55,28 +68,20 @@ Debug variable controls if the tested process suppresses output (empty DEBUG) or
5568
DEBUG="1"
5669
```
5770

58-
Currently supported senders:
59-
- `prometheus` - The reference Prometheus implementation (automatically downloaded)
60-
6171
### Running Tests
6272

6373
```bash
64-
pushd ./sender
65-
# Run compliance tests e.g. for the default prometheus binary ...
66-
PROMETHEUS_RW2_COMPLIANCE_SENDERS="prometheus" go test -v
67-
popd
74+
make sender
6875
```
6976

70-
To use visualization HTML page, export data to JSON and generate `results.json` e.g.
77+
To use visualization HTML page:
7178

7279
```bash
73-
pushd ./sender
74-
PROMETHEUS_RW2_COMPLIANCE_SENDERS="prometheus" go test -json | tee results.json
75-
popd
76-
77-
# Open ./index.html in your browser and see results.
80+
make sender-html
7881
```
7982

83+
See Makefile for detailed invocation.
84+
8085
## Receiver Compliance (`/receiver`)
8186

8287
Tests that Remote-Write endpoints properly handle incoming requests by sending various Remote-Write v2 requests and validating responses.
@@ -136,21 +141,14 @@ export PROMETHEUS_RW2_COMPLIANCE_RECEIVERS="local-prometheus,mimir"
136141

137142
### Running Tests
138143

139-
Simply run `go test` in the `receiver` directory. For example:
140-
141144
```bash
142-
pushd ./receiver
143-
# Run compliance tests e.g. for the local-prometheus remote write endpoint defined in your PROMETHEUS_RW2_COMPLIANCE_CONFIG_FILE.
144-
PROMETHEUS_RW2_COMPLIANCE_RECEIVERS="local-prometheus" go test -v
145-
popd
145+
make receiver
146146
```
147147

148-
To use visualization HTML page, export data to JSON and generate `results.json` e.g.
148+
To use visualization HTML page:
149149

150150
```bash
151-
pushd ./receiver
152-
PROMETHEUS_RW2_COMPLIANCE_RECEIVERS="local-prometheus" go test -json | tee results.json
153-
popd
154-
155-
# Open ./index.html in your browser and see results.
151+
make receiver-html
156152
```
153+
154+
See Makefile for detailed invocation.

0 commit comments

Comments
 (0)