Repository navigation
test: migrate to observability pytest-bdd feature files pattern - #456
Merged
Merged
Conversation
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.
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.
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.
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.
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.
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.
"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.
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.
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.
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.
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.
lucabello
force-pushed
the
test/bdd-wire-features
branch
from
November 9, 2026 19:08
f75ccba to
ad31bda
Compare
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.
lucabello
marked this pull request as ready for review
November 9, 2026 19:19
lucabello
added a commit
that referenced
this pull request
Nov 9, 2026
* test: add BDD feature coverage for coordinator and worker * test: remove unit feature files and optimize integration feature files * fix: add ingress wait * test: migrate to observability pytest-bdd feature files pattern (#456) * 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 --------- Co-authored-by: Luca Bello <36242061+lucabello@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Stacked on #452. In that PR no test module loads its feature file (no
scenarios()call), sobdd_features_base_dirhas no effect and the@given/@when/@thendecorators sit ontest_*functions that pytest runs as plain tests in file order. The feature files describe tests that are not the ones that run, and they phrase the same things in different ways.Solution
tests/integration/test_<feature>.pyonly loads its feature withscenarios("<feature>.feature"), so every scenario runs through its feature file. The steps live intests/integration/steps, one module per topic, registered inconftest.py.Pyroscope is related to Loki over "logging", with the endpoint quoted, and aCOUNTERPARTStable insteps/relations.pysays how to deploy each charm on demand;Pyroscope is healthyreplaces the active/idle checks: every application in the model is active and idle, nginx serves the UI on every coordinator unit, and every worker unit answers/ready;Andis used instead of*.Givensteps deploy or integrate only what is missing and wait for it to settle, so a scenario does not depend on the one before it.observability-clientsinstead ofrequestsandcurl;assertions.pyis gone.self-monitoring.featurerelates Pyroscope to an OpenTelemetry Collector, which stands for Prometheus, Loki and Tempo, instead of deploying that stack. The collector is blocked without a backend, but it receives, and afilterprocessor per application and signal, set with itsprocessorsconfig, counts what each application sends: the steps read those counts from its own metrics, and the alert rules and scrape jobs from the relation data. Grafana and Catalogue stay, for the datasource, dashboards and item.ingressrelation).juju-doctor.featureis only the probes. The gradual deployment, with the workers blocked until the coordinator and an s3 backend are related, isdeployment-distributed.feature.profiling.featurereplacesprofiling-tlsand the two collector features: a scenario outline runs the ingestion over HTTP and HTTPS, as alertmanager's tracing feature does, andPyroscope serves over <scheme>brings the model to either.retention.featureisconfiguration.feature, named after what it configures.@retrygoes below@then: pytest-bdd registers the function the decorator is applied to, so with the order of test: migrate to observability pytest-bdd feature files pattern #452 the retries would be dropped.profiling.featureare tagged@skip, with the reason (Collector cannot forward profiles: otelcol 0.130 rejects the OTLP profiles schema Pyroscope v2 needs #439) in the feature description, so they no longer deploy a model to skip a step.setup/teardownmarkers are removed:pytest-jubilantdestroys each module's model, and markers do nothing on steps.worker/src/pyroscope.pynewline,test_ingress.pyfile mode), andCONTRIBUTING.mddescribes the layout.Context
With
scenarios(), pytest-bdd creates one test per scenario in the module's order, and re-runs theBackgroundfor each, hence the idempotentGivensteps. The scenarios of a feature share the module's Juju model.Pyroscope relates to the OpenTelemetry Collector over every telemetry endpoint without naming the collector's side, since each of Pyroscope's endpoints matches one of the collector's. The metrics, logs and traces steps check every application, not that some arrived: a
filterprocessor matches an application'sjuju_applicationand the collector counts what it drops, so the counts are per application, and the collector's own telemetry, which goes to receivers of its own, is not among them. Charm and workload traces both arrive over OTLP, and are told apart by thecharm_typeof the charm's resource. The collector keeps 1% of the workloads' traces by default, so the feature setstracing_sampling_rate_workloadto 100. Alert rules are read from the relation data, so Prometheus and Loki no longer validate them. The charm traces step retries for 10 minutes: a charm only sends a trace on its next event, at the latest the nextupdate-status.Not done here:
deployment-monolithicassumes nothing is integrated yet, so it must run before the ones that integrate the coordinator; the same goes for the first one ofdeployment-distributed.@pytest.mark.teardowntests are gone; they were not scenarios.Testing Instructions
Scenarios are collected with
pytest tests/integration --collect-only -q: 22 tests, 2 of them skipped.Verified on a local k8s controller, with charms packed from this branch:
test_deployment_monolithic(4 passed),test_deployment_distributedandtest_juju_doctor(3 passed),test_profiling(HTTP and HTTPS passed, the 2 collector scenarios skipped),test_configuration(passed) andtest_self_monitoring(10 scenarios passed, with the per-application counts, before its metrics and logs scenarios were grouped into 2, which was not re-run).test_ingresswas not run.Upgrade Notes
None.