Skip to content

test: migrate to observability pytest-bdd feature files pattern - #452

Merged
lucabello merged 5 commits into
mainfrom
feat/bdd-coverage
Nov 9, 2026
Merged

lucabello merged 5 commits into
mainfrom
feat/bdd-coverage

Conversation

@1amyae

@1amyae 1amyae commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Pyroscope's integration tests are plain pytest functions run in file order, with no specification of what the charms do. The other observability charms specify it as Gherkin feature files run with pytest-bdd (see canonical/alertmanager-k8s-operator#495).

Solution

  • One feature file per capability in tests/features: configuration, deployment-distributed, deployment-monolithic, ingress, juju-doctor, profiling and self-monitoring.
  • Each tests/integration/test_<feature>.py only loads its feature with scenarios(), so every scenario runs through its feature file, in a Juju model of its own. The steps live in tests/integration/steps, one module per topic.
  • self-monitoring relates Pyroscope to an OpenTelemetry Collector instead of deploying the COS stack. The collector counts the telemetry of each Pyroscope application, so the steps check that every application sends metrics, logs and traces.
  • The scenarios of profiling through an OpenTelemetry Collector are skipped until Collector cannot forward profiles: otelcol 0.130 rejects the OTLP profiles schema Pyroscope v2 needs #439 is fixed.
  • The teardown markers are removed: pytest-jubilant destroys each module's model.
  • observability-clients is a test dependency of the coordinator and the worker, and CONTRIBUTING.md describes the layout.

Context

The scenarios of a feature share its model and Background runs for each of them, so Given steps deploy or integrate only what is missing. The first scenario of deployment-monolithic and of deployment-distributed assumes nothing is integrated yet, so it must run first.

Testing Instructions

tox -e integration

pytest tests/integration --collect-only -q lists 22 tests, 2 of them skipped.

Run on a local k8s controller with charms packed from this branch: test_deployment_monolithic, test_deployment_distributed, test_juju_doctor, test_profiling (HTTP and HTTPS), test_configuration and test_self_monitoring passed. test_self_monitoring passed before its metrics and logs scenarios were grouped, and was not re-run since. test_ingress was not run.

Upgrade Notes

None.

@1amyae
1amyae requested a review from lucabello November 4, 2026 16:29
@1amyae
1amyae marked this pull request as ready for review November 5, 2026 00:11
@lucabello
lucabello added this pull request to stack #457 November 9, 2026 19:19
@lucabello
lucabello removed this pull request from stack #457 November 9, 2026 20:03
* chore: revert incidental changes to worker source and file mode

The BDD coverage branch drops the trailing newline of
worker/src/pyroscope.py, which is the only change to the worker charm,
and makes tests/integration/test_ingress.py executable. Neither belongs
to the change. Restore both so that the worker charm is not touched.

* docs: describe the feature files and how the integration tests load them

CONTRIBUTING.md only lists the tox environments, so nothing says where
the feature files live, which module runs them, or that their scenarios
share a model. Document the layout, the idempotent Given steps and the
@Skip tag.

* test: run the feature files with pytest-bdd

The integration test modules never load their feature files: there is
no scenarios() call, so bdd_features_base_dir has no effect and the
@given/@when/@then decorators sit on test_* functions that pytest runs
as plain tests in file order. The feature files describe tests that are
not the ones that run, and some step texts no longer match the code
(the retention quotes, "Traefik").

Load each feature with scenarios() and turn the test_* functions into
steps, so that every scenario runs through its feature file:

- Given steps deploy or integrate only what is missing and wait for it
  to settle, so a scenario does not depend on the one before it.
- Steps that behave differently get different texts: the ingress
  scenarios say "through the ingress" where they hit Traefik.
- The juju-doctor scenarios, which were stages of one story, become one
  scenario.
- @Retry goes below @then, as pytest-bdd registers the function the
  decorator is applied to.
- The collector scenarios are tagged @Skip, with the reason in the
  feature description, so they no longer deploy a model to skip a step.
- The teardown fixtures and the setup/teardown markers go:
  pytest-jubilant destroys the model of each module, and markers do
  nothing on steps.

* test: use And instead of * in the feature files

Both keywords continue the previous step type, but the feature files mix
the generic * from the proof of concept with the And that reads as a
sentence. Use And throughout.

* test: tell the ingress apart from nginx in the ingress feature

Nginx is the coordinator's workload and serves the HTTP and gRPC
endpoints in every scenario; the ingress is whatever sits in front of it
over the ingress relation, here Traefik. The scenarios and steps say
"through nginx" for the case without an ingress, which names the
workload where the point is the entry path.

Name the entry path instead: the endpoints are hit directly on the
coordinator, or through the ingress.

* test: phrase the features and organise the steps like alertmanager

The feature files each phrase the same things their own way: "a Pyroscope
cluster is deployed", "the coordinator and worker are active", relations
described as "integrate ... over ingress", scenarios named "Pyroscope is
able to ...". The step functions sit in the test modules, so shared steps
are copied or hidden in conftest.py.

Follow the language and layout of alertmanager-k8s-operator's features:

- A feature is described under its title, and a scenario is named after
  what a charm receives or does ("Loki receives Pyroscope's logs").
- A relation is "Pyroscope is related to Loki over "logging"", with the
  endpoint quoted, and a COUNTERPARTS table says how to deploy each charm
  on demand. "Pyroscope is healthy" replaces the active/idle checks.
- Self-monitoring relates one COS charm per scenario instead of deploying
  and relating them all in the background.
- Steps live in tests/integration/steps, one module per topic, registered
  as plugins; the test modules only load their scenarios.
- Where Pyroscope answers is named by the entry path, on the coordinator
  or through the ingress, not by the workload that serves it.

* test: query Pyroscope and COS with observability-clients

"Pyroscope is healthy" only checked the Juju statuses, so a unit that
was active but did not answer passed. It now also checks that nginx
serves the UI on every coordinator unit (8080, over TLS when Pyroscope
has a CA) and that every worker unit answers /ready on 4040.

The steps carried their own requests and curl calls to Prometheus,
Loki, Tempo, Grafana and Pyroscope. They use observability-clients
instead, and assertions.py is gone. The ports are named in helpers.py
instead of being repeated in the steps.

Three queries could not be moved as they were:
- Loki's rules API answers in YAML, which Loki.has_alert_rules cannot
  parse, so that step still reads the response text.
- Tempo.has_tag_value expects objects, and Tempo returns plain strings
  for the tag values, so the step reads them with get_tag_values.
- The workload traces query used the legacy tags search, which matches
  a substring; it is now a TraceQL regex for the same names.

The charm traces step retries for 10 minutes, so that it outlasts the 5
minutes between update-status events: Pyroscope is related to Tempo once
the model has settled, so an application only sends a trace on its next
event.

* test: split the features and use an OTel Collector for self-monitoring

Some features tested two things at once, or the same thing in several
files, and self-monitoring deployed a whole COS stack to check what
Pyroscope sends to it.

- juju-doctor.feature is only the probes, on a cluster that is deployed
  with a worker for every role. The gradual deployment (workers blocked
  until the coordinator and an s3 backend are related) moves to
  deployment-distributed.feature, and its steps are idempotent.
- profiling.feature replaces profiling-tls and the two collector
  features: a scenario outline runs the ingestion over HTTP and HTTPS,
  as alertmanager's tracing feature does, with "Pyroscope serves over
  <scheme>" bringing the model to either.
- retention.feature becomes configuration.feature, named after what it
  configures.
- self-monitoring.feature relates Pyroscope to an OTel Collector for the
  metrics, logs, traces and alert rules, instead of Prometheus, Loki and
  Tempo with its workers and object storage. The collector is blocked
  without a backend, but its receivers work: the steps read what they
  accepted from its own metrics, and the alert rules and scrape jobs
  from the relation data. The workload traces are checked on the
  workers' environment, since the collector cannot tell them from charm
  traces. Grafana and Catalogue stay, for the datasource, dashboards
  and item.

The collector is left out of the waits for active, and the constants of
the COS stack that no step uses any more are removed.

* test: add observability-clients to the charms' dev dependencies

CI runs the integration tests from coordinator/ with `uv run --frozen`,
which installs coordinator/pyproject.toml and coordinator/uv.lock, not
the root ones, so the steps could not import observability_clients. Add
it to the integration test dependencies of the coordinator and of the
worker, next to the other ones.

* test: name the OpenTelemetry Collector and merge scaling into deployment

The features and steps called the collector "OTel Collector"; they use
its full name, like the charm.

scaling-monolithic.feature becomes deployment-monolithic.feature, named
like deployment-distributed.feature. Its two scenarios about a coordinator
that is blocked alone are one outline over 1 and 2 units, so the step that
scaled the coordinator is gone: the step that gives it a number of units
already scales it either way.

* test: count the telemetry of each Pyroscope app in self-monitoring

The steps only checked that the collector's receivers had accepted
something, so one application sending telemetry was enough for the
metrics, logs and traces of all of them.

The collector is configured with a filter processor per application and
signal, which matches the application's juju_application, and the steps
read what each processor matched from the collector's own metrics. A
charm's traces are told from a workload's by the charm_type of their
resource. The collector keeps 1% of the workloads' traces by default, so
their sampling rate is set to 100.

The workload traces step now checks that the spans of every worker
arrive, instead of the worker's trace endpoint.

* test: group self-monitoring scenarios by what Pyroscope sends

The three scenarios about the metrics-endpoint relation and the two about
the logging one each ran the same When. They are one scenario per
relation, with a Then per thing checked, and the traces scenarios are
named the same way.

* test: use And in the self-monitoring scenarios
@lucabello lucabello changed the title feat: Implement BDD feature file coverage for pyroscope-operators test: migrate to observability pytest-bdd feature files pattern Nov 9, 2026
@lucabello
lucabello merged commit 562192c into main Nov 9, 2026
35 checks passed
@lucabello
lucabello deleted the feat/bdd-coverage branch November 9, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants