This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
rpki-client-web is a Python web service that wraps rpki-client and exposes its results via HTTP API and Prometheus metrics. It runs rpki-client periodically to validate RPKI objects and tracks various statistics about repository fetching, warnings, and errors.
# Run all tests
uv run pytest tests/ -v
# Run specific test file
uv run pytest tests/test_outputparser.py -v
# Run single test
uv run pytest tests/test_outputparser.py::test_parse_failed_fetch -v# Lint and fix code
uv run ruff check --fix rpkiclientweb/
# Format code
uv run ruff format rpkiclientweb/# Run with config file
python -m rpkiclientweb -v -c config.yml
# Docker development
docker run -p 8888:8888 --detach --name rpki-client-web -v ./config:/config ghcr.io/ties/rpki-client-web:dev- RpkiClient (
rpki_client.py) - Main orchestrator that runs rpki-client and processes output - OutputParser (
outputparser.py) - Parses rpki-client stderr output for warnings and fetch status - Models (
models.py) - Data classes for warnings, fetch status, and other structured data - Parsing (
parsing.py) - Low-level regex-based parsing of rpki-client log lines - Metrics (
metrics.py) - Prometheus metrics definitions - Web (
web.py) - HTTP API endpoints for results, config, and metrics
- Execution:
RpkiClientruns rpki-client subprocess periodically - Parsing:
OutputParserprocesses stderr using regex patterns inparsing.py - Metrics: Parsed data updates Prometheus metrics with normalized URIs
- API: Web endpoints serve results, metrics, and validated objects
- URI Normalization: Raw URIs are preserved in data structures. Normalization happens only when creating Prometheus metric labels using
parse_proto_host_from_url()to reduce cardinality - Dataclass Equality: Models use
@dataclass(frozen=True)for immutable, hashable objects that work correctly withinoperations on sets/lists - Generator-based Parsing: Parsing functions yield results rather than returning lists for memory efficiency
- Metric Lifecycle: Tracks repositories over time, removing metrics for unreferenced repos after 24h
- Input-driven Tests: Most tests use real rpki-client output files from
tests/inputs/ - Parsing Validation: Tests verify specific warnings/errors are correctly extracted
- Metric Behavior: Tests validate metric creation, updates, and cleanup
- Raw URI Preservation: Tests expect raw URIs in parsed objects, normalization happens at metric level
rpkiclientweb/parsing.py- Contains regex patterns matching rpki-client log formatsrpkiclientweb/models.py- Data structures with careful attention to__eq__and__hash__behaviorrpkiclientweb/rpki_client.py- Metric label creation with URI normalizationtests/inputs/- Real-world rpki-client output for comprehensive testing
Before committing changes, always run these validation commands to ensure code quality:
# Lint and fix code
uv run ruff check --fix rpkiclientweb/
# Format code
uv run ruff format rpkiclientweb/
# Run tests
uv run pytest tests/ -vThese steps ensure that all code follows the project's formatting standards, passes linting checks, and doesn't break existing functionality.
- When modifying URI handling, remember normalization happens at metric creation time, not parse time
- The
normalize_object_uri()function handles.rsync/prefixes and#hashfragments for ManifestObjectWarning - Tests may break if dataclass equality behavior changes - prefer factory functions over computed properties
- The project uses uv for dependency management and hatchling for builds