Skip to content

refactor(observability): self-migrate to register_or_reuse helpers (Phase 1)#228

Merged
pcalnon merged 1 commit intomainfrom
refactor/observability-self-migrate-helpers
May 6, 2026
Merged

refactor(observability): self-migrate to register_or_reuse helpers (Phase 1)#228
pcalnon merged 1 commit intomainfrom
refactor/observability-self-migrate-helpers

Conversation

@pcalnon
Copy link
Copy Markdown
Owner

@pcalnon pcalnon commented May 6, 2026

Summary

Phase 1 of the migration plan in notes/observability/REGISTER_OR_REUSE_HELPER_DESIGN_2026-05-05.md.

juniper-observability's own two inline guards (added in PR #211 for PrometheusMiddleware.__init__ and PR #214 for set_build_info) swap to the canonical helpers introduced in 0.2.0 (PR #216 / tag juniper-observability-v0.2.0).

What changes

File Helper used Net diff
juniper_observability/middleware/prometheus.py register_or_reuse (×3) −25 lines, −1 closure, −1 REGISTRY import
juniper_observability/prometheus.py register_info_or_update −10 lines, −1 try/except, −1 REGISTRY import

Pure internal refactor — production behaviour and the collectors' wire format are unchanged. The helper has its own unit tests (tests/test_prometheus_helpers.py, 26 cases including the adopt-existing path); these two consumers' integration tests (test_prometheus_middleware.py, test_prometheus_utils.py) exercise the swap end-to-end.

Verification

  • juniper-observability own suite: 83 passed (unchanged)
  • juniper-data full default suite under JuniperData env: 950 passed (unchanged)

What's next

Phase 2 — per-consumer migration in dependency order: juniper-data → juniper-canopy → juniper-cascor-client → juniper-cascor. Each consumer's PR will:

  1. Bump the juniper-observability dep pin to >=0.2.0
  2. Replace its inline _get_or_create / _register_or_reuse with an import from juniper_observability
  3. Drop the duplicated implementation

Test plan

  • juniper-observability own tests pass (83 / 83)
  • juniper-data tests pass (950 / 950) — exercises the helper through the integrated middleware + build-info paths
  • CHANGELOG Unreleased entry under Changed documents the refactor
  • No version bump in this PR (no public API change); whoever cuts the next release decides if 0.2.1 is warranted

🤖 Generated with Claude Code

…hase 1)

Phase 1 of the migration plan in
``notes/observability/REGISTER_OR_REUSE_HELPER_DESIGN_2026-05-05.md``:
juniper-observability's own two inline guards (added in PR #211 for
``PrometheusMiddleware.__init__`` and PR #214 for ``set_build_info``)
swap to the canonical helpers introduced in ``0.2.0`` (PR #216).

### What changes

- ``juniper_observability/middleware/prometheus.py``:
  ``PrometheusMiddleware.__init__`` drops its inline ``_get_or_create``
  closure (try/except + ``REGISTRY._names_to_collectors`` lookup) and
  calls ``register_or_reuse`` directly. Net -25 lines.
- ``juniper_observability/prometheus.py``: ``set_build_info`` drops
  its inline try/except + lookup + ``info.info({...})`` sequence and
  calls ``register_info_or_update`` (which composes those three
  steps). Net -10 lines.

Pure internal refactor — production behaviour and the collectors'
wire format are unchanged. The helper has its own unit tests
(``tests/test_prometheus_helpers.py``, 26 cases including the
adopt-existing path); these two consumers' tests
(``test_prometheus_middleware.py``, ``test_prometheus_utils.py``)
exercise the integration end-to-end.

### Verification

- juniper-observability own suite: **83 passed** (unchanged)
- juniper-data full default suite under JuniperData env: **950
  passed** (unchanged from yesterday's main run)

### Next

Phase 2 — per-consumer migration in dependency order:
juniper-data → juniper-canopy → juniper-cascor-client → juniper-cascor.
Each consumer's PR will:
  1. Bump the ``juniper-observability`` dep pin to ``>=0.2.0``
  2. Replace its inline ``_get_or_create`` / ``_register_or_reuse``
     with an import from ``juniper_observability``
  3. Drop the duplicated implementation

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pcalnon pcalnon self-assigned this May 6, 2026
Copy link
Copy Markdown
Owner Author

@pcalnon pcalnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

@pcalnon pcalnon merged commit b2e2afe into main May 6, 2026
22 checks passed
@pcalnon pcalnon deleted the refactor/observability-self-migrate-helpers branch May 6, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant