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
168 changes: 168 additions & 0 deletions .github/workflows/correctness.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Correctness Tests

# Verifies cross-language parity between Python and Rust implementations of
# PromQL pattern matching and sketch serialisation. Ephemeral GitHub Actions
# VMs are well-suited for these deterministic correctness checks.

on:
push:
branches: [ main ]
paths:
- 'asap-common/tests/**'
- 'asap-common/dependencies/**'
- 'asap-common/sketch-core/**'
- '.github/workflows/correctness.yml'
pull_request:
branches: [ main ]
paths:
- 'asap-common/tests/**'
- 'asap-common/dependencies/**'
- 'asap-common/sketch-core/**'
- '.github/workflows/correctness.yml'
workflow_dispatch:

jobs:
# ── 1. Cross-language token matching (Python vs Rust) ──────────────────────
cross-language-token-matching:
name: Cross-language PromQL token matching
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
if [ -f asap-common/dependencies/py/requirements.txt ]; then
pip install -r asap-common/dependencies/py/requirements.txt
fi
pip install -e asap-common/dependencies/py/promql_utilities/

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Install protoc
run: |
sudo apt-get update -qq
sudo apt-get install -y protobuf-compiler

- name: Run sccache
uses: mozilla-actions/sccache-action@v0.0.4

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-correctness-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}

- name: Run master test runner (Python + Rust + comparison)
working-directory: asap-common/tests/compare_matched_tokens
run: python utilities/master_test_runner.py
env:
RUSTC_WRAPPER: sccache

- name: Upload test artefacts
if: always()
uses: actions/upload-artifact@v4
with:
name: cross-language-token-results
path: |
asap-common/tests/compare_matched_tokens/python_tests/python_test_results.json
asap-common/tests/compare_matched_tokens/rust_tests/rust_test_results.json
asap-common/tests/compare_matched_tokens/comparison_tests/comparison_report.json
asap-common/tests/compare_matched_tokens/test_summary.json
if-no-files-found: warn

# ── 2. Cross-language serialised pattern comparison ────────────────────────
cross-language-pattern-serialisation:
name: Cross-language pattern serialisation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
if [ -f asap-common/dependencies/py/requirements.txt ]; then
pip install -r asap-common/dependencies/py/requirements.txt
fi
pip install -e asap-common/dependencies/py/promql_utilities/

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Install protoc
run: |
sudo apt-get update -qq
sudo apt-get install -y protobuf-compiler

- name: Run sccache
uses: mozilla-actions/sccache-action@v0.0.4

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-correctness-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}

- name: Generate Python patterns
working-directory: asap-common/tests/compare_patterns
run: python python_generate_patterns.py

- name: Build and run Rust pattern generator
working-directory: asap-common/tests/compare_patterns
run: cargo run --release
env:
RUSTC_WRAPPER: sccache

- name: Compare serialised patterns
working-directory: asap-common/tests/compare_patterns
run: python compare_serialized_patterns.py

# ── 3. Rust pattern-matching unit tests ────────────────────────────────────
rust-pattern-matching:
name: Rust pattern matching unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Install protoc
run: |
sudo apt-get update -qq
sudo apt-get install -y protobuf-compiler

- name: Run sccache
uses: mozilla-actions/sccache-action@v0.0.4

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-correctness-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}

- name: Run Rust pattern matching tests
working-directory: asap-common/tests/rust_pattern_matching
run: cargo test --release
env:
RUSTC_WRAPPER: sccache
1 change: 1 addition & 0 deletions asap-common/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies/py/promql_utilities/promql_utilities.egg-info/
dependencies/rs/**/target/

tests/**/*.json
!tests/**/test_data/*.json
tests/**/target/
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[workspace]

[package]
name = "promql_cross_lang_tests"
version = "0.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ impl PatternTester {
// Rate pattern
PromQLPattern::new(
Self::build_rate_pattern(),
vec![
"metric".to_string(),
"function".to_string(),
"range_vector".to_string(),
],
// Some("ONLY_TEMPORAL".to_string()),
),
// Quantile over time pattern
PromQLPattern::new(
Self::build_quantile_over_time_pattern(),
vec![
"metric".to_string(),
"function".to_string(),
"range_vector".to_string(),
"function_args".to_string(),
],
// Some("ONLY_TEMPORAL".to_string()),
),
];
Expand All @@ -44,34 +33,31 @@ impl PatternTester {
// Sum aggregation pattern
PromQLPattern::new(
Self::build_sum_pattern(),
vec!["metric".to_string(), "aggregation".to_string()],
// Some("ONLY_SPATIAL".to_string()),
),
// Simple metric pattern
PromQLPattern::new(
Self::build_metric_pattern(),
vec!["metric".to_string()],
// Some("ONLY_SPATIAL".to_string()),
),
];

// ONE_TEMPORAL_ONE_SPATIAL patterns
let combined_patterns = vec![
// Sum of rate pattern
// Aggregation of single-arg temporal functions
PromQLPattern::new(
Self::build_one_temporal_one_spatial_pattern(),
vec![
"metric".to_string(),
"function".to_string(),
"aggregation".to_string(),
"range_vector".to_string(),
],
// Some("ONE_TEMPORAL_ONE_SPATIAL".to_string()),
),
// Aggregation of quantile_over_time (2-arg)
PromQLPattern::new(
Self::build_combined_quantile_pattern(),
// Some("ONE_TEMPORAL_ONE_SPATIAL".to_string()),
),
];

// Insert in order from simple to complex to avoid panics
patterns.insert("ONLY_VECTOR".to_string(), spatial_patterns.clone());
// ONLY_VECTOR is derived via disambiguation in test_query, not a separate entry
patterns.insert("ONLY_SPATIAL".to_string(), spatial_patterns);
patterns.insert("ONLY_TEMPORAL".to_string(), temporal_patterns);
patterns.insert("ONE_TEMPORAL_ONE_SPATIAL".to_string(), combined_patterns);
Expand Down Expand Up @@ -280,7 +266,20 @@ impl PatternTester {

let args: Vec<Option<HashMap<String, Value>>> = vec![ms];

PromQLPatternBuilder::function(vec!["rate", "increase"], args, Some("function"), None)
PromQLPatternBuilder::function(
vec![
"rate",
"increase",
"avg_over_time",
"sum_over_time",
"count_over_time",
"min_over_time",
"max_over_time",
],
args,
Some("function"),
None,
)
}

fn build_quantile_over_time_pattern() -> Option<HashMap<String, Value>> {
Expand Down Expand Up @@ -327,7 +326,6 @@ impl PatternTester {

let func = PromQLPatternBuilder::function(
vec![
"quantile_over_time",
"sum_over_time",
"count_over_time",
"avg_over_time",
Expand All @@ -351,6 +349,30 @@ impl PatternTester {
)
}

fn build_combined_quantile_pattern() -> Option<HashMap<String, Value>> {
let num = PromQLPatternBuilder::number(None, None);
let ms = PromQLPatternBuilder::matrix_selector(
PromQLPatternBuilder::metric(None, None, None, Some("metric")),
None,
Some("range_vector"),
);
let func_args: Vec<Option<HashMap<String, Value>>> = vec![num, ms];
let func = PromQLPatternBuilder::function(
vec!["quantile_over_time"],
func_args,
Some("function"),
None,
);
PromQLPatternBuilder::aggregation(
vec!["sum", "count", "avg", "quantile", "min", "max"],
func,
None,
None,
None,
Some("aggregation"),
)
}

fn build_sum_rate_pattern() -> Option<HashMap<String, Value>> {
let ms = PromQLPatternBuilder::matrix_selector(
PromQLPatternBuilder::metric(None, None, None, Some("metric")),
Expand Down
Loading
Loading