Excel compatible SLO reporting tool for Prometheus.
Run the tool
# 1. Have prometheus running on localhost:9090
# 2. Adjust './config/settings.yaml' to your needs or set the environment variables, e.g.
$ export PROMETHEUS_URL=http://localhost:9090
$ export ARCHIVE=./slo-reporting.csv
$ export RUST_LOG=info
# 3. Run the tool
$ cargo run
# Example output
Compiling slo_reporting v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 2.04s
Running `target\debug\slo_reporting.exe`
[2022-11-02T19:57:12Z INFO slo_reporting] Started slo_reporting, version dev
[2022-11-02T19:57:12Z INFO slo_reporting] Read './slo-reporting.csv'
[2022-11-02T19:57:13Z INFO slo_reporting] Processed 'serviceA-uptime' (goal=98%, rolling=14days, step=1day)
[2022-11-02T19:57:13Z INFO slo_reporting] Processed 'serviceB-uptime' (goal=98%, rolling=14days, step=1day)
[2022-11-02T19:57:13Z INFO slo_reporting] Wrote './slo-reporting.csv'
Import the CSV into a spreadsheet, e.g. Excel, and create a chart.
Install
sudo apt install build-essential
IDE recommendations:
Next run
rustup update
# Install the required toolchain instrumenting coverage via profiles
rustup install nightly
rustup component add clippy
Building the application is done with cargo build
or cargo build --release
for a release build.
Running the test suite is done with cargo test
.
For the coverage, things are slightly more complicated. We mainly followed How to collect Rust source-based code coverage which is a bit dated, but still works.
First, add RUSTFLAGS="-Cinstrument-coverage"
to the profile.dev
.
Note that this requires a nightly toolchain.
[profile.test]
inherits = "dev"
rustflags = ["-Cinstrument-coverage"]
Then, run the tests with cargo +nightly test --profile=test
which will generate the coverage data.
Alternatively, you can just set RUSTFLAGS="-Cinstrument-coverage"
in the environment.
Next, we want to generate coverage report (e.g. in HTML format). Note that we need to use the nightly toolchain for this as well and llvm-tools-preview.
# Install grcov
cargo install grcov
# Install llvm-tools-preview
rustup component add llvm-tools-preview
# Generate the coverage report (lcov format)
grcov . -b target\debug -s . -t lcov --llvm --branch --ignore-not-existing -o lcov.info
# Generate the HTML report
grcov . -b target\debug -s . -t html --branch --ignore-not-existing -o ./coverage/
Note that most build agents do have the required tools installed, e.g.
ubuntu-22.04
: Rust Tools