Skip to content

Commit 2a764fa

Browse files
chore: update charm libraries (#191)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e68f1ff commit 2a764fa

3 files changed

Lines changed: 42 additions & 11 deletions

File tree

lib/charms/grafana_agent/v0/cos_agent.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class _MetricsEndpointDict(TypedDict):
254254

255255
LIBID = "dc15fa84cef84ce58155fb84f6c6213a"
256256
LIBAPI = 0
257-
LIBPATCH = 23
257+
LIBPATCH = 24
258258

259259
PYDEPS = ["cosl >= 0.0.50", "pydantic"]
260260

@@ -711,11 +711,16 @@ def _scrape_jobs(self) -> List[Dict]:
711711
scrape_configs = self._scrape_configs.copy()
712712

713713
# Convert "metrics_endpoints" to standard scrape_configs, and add them in
714+
unit_name = self._charm.unit.name.replace("/", "_")
714715
for endpoint in self._metrics_endpoints:
716+
port = endpoint["port"]
717+
path = endpoint["path"]
718+
sanitized_path = path.strip("/").replace("/", "_")
715719
scrape_configs.append(
716720
{
717-
"metrics_path": endpoint["path"],
718-
"static_configs": [{"targets": [f"localhost:{endpoint['port']}"]}],
721+
"job_name": f"{unit_name}_localhost_{port}_{sanitized_path}",
722+
"metrics_path": path,
723+
"static_configs": [{"targets": [f"localhost:{port}"]}],
719724
}
720725
)
721726

lib/charms/operator_libs_linux/v0/passwd.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Simple library for managing Linux users and groups.
15+
"""Legacy Charmhub-hosted passwd library, deprecated in favour of ``charmlibs.passwd``.
16+
17+
WARNING: This library is deprecated and will no longer receive feature updates or bugfixes.
18+
``charmlibs.passwd`` version 1.0 is a bug-for-bug compatible migration of this library.
19+
Add 'charmlibs-passwd~=1.0' to your charm's dependencies, and remove this Charmhub-hosted library.
20+
Then replace `from charms.operator_libs_linux.v0 import passwd` with
21+
`from charmlibs import passwd`.
22+
Read more:
23+
- https://documentation.ubuntu.com/charmlibs
24+
- https://pypi.org/project/charmlibs-passwd
25+
26+
---
27+
28+
Simple library for managing Linux users and groups.
1629
1730
The `passwd` module provides convenience methods and abstractions around users and groups on a
1831
Linux system, in order to make adding and managing users and groups easy.
@@ -45,7 +58,7 @@
4558

4659
# Increment this PATCH version before using `charmcraft publish-lib` or reset
4760
# to 0 if you are raising the major API version
48-
LIBPATCH = 4
61+
LIBPATCH = 5
4962

5063

5164
def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:
@@ -58,9 +71,9 @@ def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:
5871
TypeError: where neither a string or int is passed as the first argument
5972
"""
6073
try:
61-
if type(user) is int:
74+
if isinstance(user, int) and not isinstance(user, bool):
6275
return pwd.getpwuid(user)
63-
elif type(user) is str:
76+
elif isinstance(user, str):
6477
return pwd.getpwnam(user)
6578
else:
6679
raise TypeError("specified argument '%r' should be a string or int", user)
@@ -79,9 +92,9 @@ def group_exists(group: Union[str, int]) -> Optional[grp.struct_group]:
7992
TypeError: where neither a string or int is passed as the first argument
8093
"""
8194
try:
82-
if type(group) is int:
95+
if isinstance(group, int) and not isinstance(group, bool):
8396
return grp.getgrgid(group)
84-
elif type(group) is str:
97+
elif isinstance(group, str):
8598
return grp.getgrnam(group)
8699
else:
87100
raise TypeError("specified argument '%r' should be a string or int", group)

lib/charms/operator_libs_linux/v1/systemd.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,20 @@
1313
# limitations under the License.
1414

1515

16-
"""Abstractions for stopping, starting and managing system services via systemd.
16+
"""Legacy Charmhub-hosted systemd library, deprecated in favour of ``charmlibs.systemd``.
17+
18+
WARNING: This library is deprecated and will no longer receive feature updates or bugfixes.
19+
``charmlibs.systemd`` version 1.0 is a bug-for-bug compatible migration of this library.
20+
Add 'charmlibs-systemd~=1.0' to your charm's dependencies, and remove this Charmhub-hosted library.
21+
Then replace `from charms.operator_libs_linux.v0 import systemd` with
22+
`from charmlibs import systemd`.
23+
Read more:
24+
- https://documentation.ubuntu.com/charmlibs
25+
- https://pypi.org/project/charmlibs-systemd
26+
27+
---
28+
29+
Abstractions for stopping, starting and managing system services via systemd.
1730
1831
This library assumes that your charm is running on a platform that uses systemd. E.g.,
1932
Centos 7 or later, Ubuntu Xenial (16.04) or later.
@@ -64,7 +77,7 @@
6477

6578
# Increment this PATCH version before using `charmcraft publish-lib` or reset
6679
# to 0 if you are raising the major API version
67-
LIBPATCH = 4
80+
LIBPATCH = 5
6881

6982

7083
class SystemdError(Exception):

0 commit comments

Comments
 (0)