Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

fix: remove stale opentelemetry_sdk packages at lib module import time #158

Merged
merged 4 commits into from
Aug 8, 2024

Conversation

ca-scribner
Copy link
Contributor

@ca-scribner ca-scribner commented Aug 2, 2024

Issue

#157

Solution

This PR takes the solution from #151 and:

  • runs it before importing any opentelemetry packages
  • widens it to apply to all opentelemetry packages

While fixing this PR, I noticed the ruff.lint settings in pyproject.toml were under an incorrect array ([lint] instead of [tool.ruff]/[tool.ruff.lint]). I've fixed that plus any linting errors that came up as a result as a drive-by.

Context

#151

Testing Instructions

(in a machine model)

to repro the original issue

charmcraft pack
juju deploy grafana-agent --revision=134 --channel=latest/stable
juju deploy ubuntu
juju relate grafana-agent ubuntu
# wait for deploy to finish and charm to go to blocked (because it has no target for its metrics)

# rebuild grafana-agent latest/edge with v12 (old) version of the library
juju refresh grafana-agent --path ./grafana-agent_ubuntu-22.04-amd64.charm

juju refresh grafana-agent --channel latest/edge
# charm should refresh and go to error

to demo the fix:

juju deploy grafana-agent --revision=134 --channel=latest/stable
juju deploy ubuntu
juju relate grafana-agent ubuntu
# wait for deploy to finish and charm to go to blocked (because it has no target for its metrics)

# rebuild grafana-agent latest/edge with v13 (this PR's) version of the library
# or, use [this pr's charm](https://github.com/canonical/grafana-agent-operator/pull/157)
juju refresh grafana-agent --path ./grafana-agent_ubuntu-22.04-amd64.charm
# charm should refresh and go back to blocked.  It should not go to error

Release Notes

Adds a workaround for juju bug 2058335, which results in parts of old python packages being left in the virtual environment after upgrades during charm refresh. This patch detects and removes any duplicate opentelemetry-exporter-otlp-proto-http package found during upgrade.

lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
lib/charms/tempo_k8s/v1/charm_tracing.py Outdated Show resolved Hide resolved
@ca-scribner ca-scribner force-pushed the openg-2554-patch2 branch 2 times, most recently from 80020fa to b3057ef Compare August 6, 2024 19:38
fixes #157 by moving the stale package culling of charm_tracing.py ahead of all package imports and widening its scope to any opentelemetry package directories.
@ca-scribner
Copy link
Contributor Author

@PietroPasotti everything is as you suggested, with the one addition of the "# Not None or empty list" comment on that if not distribution.files

Copy link
Contributor

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

LGTM

# Conflicts:
#	src/charm.py
#	tests/scenario/test_charm.py
@ca-scribner ca-scribner merged commit e128a57 into main Aug 8, 2024
13 checks passed
@ca-scribner ca-scribner deleted the openg-2554-patch2 branch August 8, 2024 15:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants