charmlibs-interfaces-sloth 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- charmlibs_interfaces_sloth-0.1.0/.gitignore +184 -0
- charmlibs_interfaces_sloth-0.1.0/CHANGELOG.md +18 -0
- charmlibs_interfaces_sloth-0.1.0/PKG-INFO +86 -0
- charmlibs_interfaces_sloth-0.1.0/README.md +67 -0
- charmlibs_interfaces_sloth-0.1.0/pyproject.toml +79 -0
- charmlibs_interfaces_sloth-0.1.0/src/charmlibs/interfaces/sloth/__init__.py +147 -0
- charmlibs_interfaces_sloth-0.1.0/src/charmlibs/interfaces/sloth/_sloth.py +297 -0
- charmlibs_interfaces_sloth-0.1.0/src/charmlibs/interfaces/sloth/_topology.py +105 -0
- charmlibs_interfaces_sloth-0.1.0/src/charmlibs/interfaces/sloth/_version.py +15 -0
- charmlibs_interfaces_sloth-0.1.0/src/charmlibs/interfaces/sloth/py.typed +0 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-provider/charmcraft.yaml +43 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-provider/library/README.md +1 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-provider/library/pyproject.toml +1 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-provider/pyproject.toml +12 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-provider/src/charm.py +88 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-requirer/charmcraft.yaml +36 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-requirer/library/README.md +1 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-requirer/library/pyproject.toml +1 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-requirer/pyproject.toml +12 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/charms/sloth-requirer/src/charm.py +79 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/conftest.py +71 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/pack.sh +39 -0
- charmlibs_interfaces_sloth-0.1.0/tests/integration/test_slo_integration.py +213 -0
- charmlibs_interfaces_sloth-0.1.0/tests/unit/test_slo.py +902 -0
- charmlibs_interfaces_sloth-0.1.0/uv.lock +528 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.coverage-*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
.report/
|
|
55
|
+
|
|
56
|
+
# Translations
|
|
57
|
+
*.mo
|
|
58
|
+
*.pot
|
|
59
|
+
|
|
60
|
+
# Django stuff:
|
|
61
|
+
*.log
|
|
62
|
+
local_settings.py
|
|
63
|
+
db.sqlite3
|
|
64
|
+
db.sqlite3-journal
|
|
65
|
+
|
|
66
|
+
# Flask stuff:
|
|
67
|
+
instance/
|
|
68
|
+
.webassets-cache
|
|
69
|
+
|
|
70
|
+
# Scrapy stuff:
|
|
71
|
+
.scrapy
|
|
72
|
+
|
|
73
|
+
# Sphinx documentation
|
|
74
|
+
docs/_build/
|
|
75
|
+
|
|
76
|
+
# PyBuilder
|
|
77
|
+
.pybuilder/
|
|
78
|
+
target/
|
|
79
|
+
|
|
80
|
+
# Jupyter Notebook
|
|
81
|
+
.ipynb_checkpoints
|
|
82
|
+
|
|
83
|
+
# IPython
|
|
84
|
+
profile_default/
|
|
85
|
+
ipython_config.py
|
|
86
|
+
|
|
87
|
+
# pyenv
|
|
88
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
89
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
90
|
+
# .python-version
|
|
91
|
+
|
|
92
|
+
# pipenv
|
|
93
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
94
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
95
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
96
|
+
# install all needed dependencies.
|
|
97
|
+
#Pipfile.lock
|
|
98
|
+
|
|
99
|
+
# UV
|
|
100
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
101
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
102
|
+
# commonly ignored for libraries.
|
|
103
|
+
#uv.lock
|
|
104
|
+
|
|
105
|
+
# poetry
|
|
106
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
107
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
108
|
+
# commonly ignored for libraries.
|
|
109
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
110
|
+
#poetry.lock
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
#pdm.lock
|
|
115
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
116
|
+
# in version control.
|
|
117
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
118
|
+
.pdm.toml
|
|
119
|
+
.pdm-python
|
|
120
|
+
.pdm-build/
|
|
121
|
+
|
|
122
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
123
|
+
__pypackages__/
|
|
124
|
+
|
|
125
|
+
# Celery stuff
|
|
126
|
+
celerybeat-schedule
|
|
127
|
+
celerybeat.pid
|
|
128
|
+
|
|
129
|
+
# SageMath parsed files
|
|
130
|
+
*.sage.py
|
|
131
|
+
|
|
132
|
+
# Environments
|
|
133
|
+
.env
|
|
134
|
+
.venv
|
|
135
|
+
env/
|
|
136
|
+
venv/
|
|
137
|
+
ENV/
|
|
138
|
+
env.bak/
|
|
139
|
+
venv.bak/
|
|
140
|
+
|
|
141
|
+
# Spyder project settings
|
|
142
|
+
.spyderproject
|
|
143
|
+
.spyproject
|
|
144
|
+
|
|
145
|
+
# Rope project settings
|
|
146
|
+
.ropeproject
|
|
147
|
+
|
|
148
|
+
# mkdocs documentation
|
|
149
|
+
/site
|
|
150
|
+
|
|
151
|
+
# mypy
|
|
152
|
+
.mypy_cache/
|
|
153
|
+
.dmypy.json
|
|
154
|
+
dmypy.json
|
|
155
|
+
|
|
156
|
+
# Pyre type checker
|
|
157
|
+
.pyre/
|
|
158
|
+
|
|
159
|
+
# pytype static type analyzer
|
|
160
|
+
.pytype/
|
|
161
|
+
|
|
162
|
+
# Cython debug symbols
|
|
163
|
+
cython_debug/
|
|
164
|
+
|
|
165
|
+
# PyCharm
|
|
166
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
167
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
168
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
169
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
170
|
+
.idea/
|
|
171
|
+
|
|
172
|
+
# PyPI configuration file
|
|
173
|
+
.pypirc
|
|
174
|
+
|
|
175
|
+
# packed charms
|
|
176
|
+
.packed
|
|
177
|
+
|
|
178
|
+
# temporary directory for packing charms
|
|
179
|
+
.tmp
|
|
180
|
+
|
|
181
|
+
# uv.lock from example libraries as we don't commit these
|
|
182
|
+
.example/**/uv.lock
|
|
183
|
+
.tutorial/**/uv.lock
|
|
184
|
+
interfaces/.example/**/uv.lock
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the charmlibs.interfaces.sloth library will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of charmlibs.interfaces.sloth
|
|
12
|
+
- SlothProvider class for providing SLO specifications
|
|
13
|
+
- SlothRequirer class for consuming SLO specifications
|
|
14
|
+
- Automatic Juju topology label injection into Prometheus queries
|
|
15
|
+
- Support for multi-document YAML specifications
|
|
16
|
+
- Pydantic-based validation of SLO specifications
|
|
17
|
+
- Python 3.8+ compatibility
|
|
18
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: charmlibs-interfaces-sloth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sloth integration for Juju charms - SLO (Service Level Objective) management with the Sloth operator.
|
|
5
|
+
Project-URL: Repository, https://github.com/canonical/charmlibs
|
|
6
|
+
Project-URL: Issues, https://github.com/canonical/charmlibs/issues
|
|
7
|
+
Author: The Observability team at Canonical Ltd.
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: cosl>=0.0.10
|
|
15
|
+
Requires-Dist: ops
|
|
16
|
+
Requires-Dist: pydantic>=2.0
|
|
17
|
+
Requires-Dist: pyyaml
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# charmlibs.interfaces.sloth
|
|
21
|
+
|
|
22
|
+
Sloth integration library for Juju charms, providing SLO (Service Level Objective) management with the Sloth operator for generating Prometheus recording and alerting rules.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Provider/Requirer pattern**: Enables charms to share SLO specifications with Sloth
|
|
27
|
+
- **Raw YAML interface**: Provider passes raw YAML strings; validation happens on requirer side
|
|
28
|
+
- **Automatic topology injection**: Optionally inject Juju topology labels into Prometheus queries
|
|
29
|
+
- **Multi-service support**: Provide SLO specs for multiple services in a single YAML document
|
|
30
|
+
|
|
31
|
+
## Getting started
|
|
32
|
+
|
|
33
|
+
To install, add `charmlibs-interfaces-sloth` to your Python dependencies. Then in your Python code, import as:
|
|
34
|
+
|
|
35
|
+
```py
|
|
36
|
+
from charmlibs.interfaces.sloth import SlothProvider, SlothRequirer
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Provider Side
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from charmlibs.interfaces.sloth import SlothProvider
|
|
43
|
+
|
|
44
|
+
class MyCharm(ops.CharmBase):
|
|
45
|
+
def __init__(self, *args):
|
|
46
|
+
super().__init__(*args)
|
|
47
|
+
self.sloth_provider = SlothProvider(self)
|
|
48
|
+
|
|
49
|
+
def _provide_slos(self):
|
|
50
|
+
slo_config = '''
|
|
51
|
+
version: prometheus/v1
|
|
52
|
+
service: my-service
|
|
53
|
+
slos:
|
|
54
|
+
- name: requests-availability
|
|
55
|
+
objective: 99.9
|
|
56
|
+
sli:
|
|
57
|
+
events:
|
|
58
|
+
error_query: 'sum(rate(http_requests_total{status=~"5.."}[{{.window}}]))'
|
|
59
|
+
total_query: 'sum(rate(http_requests_total[{{.window}}]))'
|
|
60
|
+
'''
|
|
61
|
+
self.sloth_provider.provide_slos(slo_config)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Requirer Side
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from charmlibs.interfaces.sloth import SlothRequirer
|
|
68
|
+
|
|
69
|
+
class SlothCharm(ops.CharmBase):
|
|
70
|
+
def __init__(self, *args):
|
|
71
|
+
super().__init__(*args)
|
|
72
|
+
self.sloth_requirer = SlothRequirer(self)
|
|
73
|
+
|
|
74
|
+
def _on_config_changed(self, event):
|
|
75
|
+
# Get validated SLO specs from all related charms
|
|
76
|
+
slos = self.sloth_requirer.get_slos()
|
|
77
|
+
# Process SLOs and generate rules
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Documentation
|
|
81
|
+
|
|
82
|
+
For complete documentation, see the [charmlibs documentation](https://documentation.ubuntu.com/charmlibs/reference/charmlibs/interfaces/sloth).
|
|
83
|
+
|
|
84
|
+
## Contributing
|
|
85
|
+
|
|
86
|
+
See [CONTRIBUTING.md](https://github.com/canonical/charmlibs/blob/main/CONTRIBUTING.md) in the repository root.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# charmlibs.interfaces.sloth
|
|
2
|
+
|
|
3
|
+
Sloth integration library for Juju charms, providing SLO (Service Level Objective) management with the Sloth operator for generating Prometheus recording and alerting rules.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Provider/Requirer pattern**: Enables charms to share SLO specifications with Sloth
|
|
8
|
+
- **Raw YAML interface**: Provider passes raw YAML strings; validation happens on requirer side
|
|
9
|
+
- **Automatic topology injection**: Optionally inject Juju topology labels into Prometheus queries
|
|
10
|
+
- **Multi-service support**: Provide SLO specs for multiple services in a single YAML document
|
|
11
|
+
|
|
12
|
+
## Getting started
|
|
13
|
+
|
|
14
|
+
To install, add `charmlibs-interfaces-sloth` to your Python dependencies. Then in your Python code, import as:
|
|
15
|
+
|
|
16
|
+
```py
|
|
17
|
+
from charmlibs.interfaces.sloth import SlothProvider, SlothRequirer
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Provider Side
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from charmlibs.interfaces.sloth import SlothProvider
|
|
24
|
+
|
|
25
|
+
class MyCharm(ops.CharmBase):
|
|
26
|
+
def __init__(self, *args):
|
|
27
|
+
super().__init__(*args)
|
|
28
|
+
self.sloth_provider = SlothProvider(self)
|
|
29
|
+
|
|
30
|
+
def _provide_slos(self):
|
|
31
|
+
slo_config = '''
|
|
32
|
+
version: prometheus/v1
|
|
33
|
+
service: my-service
|
|
34
|
+
slos:
|
|
35
|
+
- name: requests-availability
|
|
36
|
+
objective: 99.9
|
|
37
|
+
sli:
|
|
38
|
+
events:
|
|
39
|
+
error_query: 'sum(rate(http_requests_total{status=~"5.."}[{{.window}}]))'
|
|
40
|
+
total_query: 'sum(rate(http_requests_total[{{.window}}]))'
|
|
41
|
+
'''
|
|
42
|
+
self.sloth_provider.provide_slos(slo_config)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Requirer Side
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from charmlibs.interfaces.sloth import SlothRequirer
|
|
49
|
+
|
|
50
|
+
class SlothCharm(ops.CharmBase):
|
|
51
|
+
def __init__(self, *args):
|
|
52
|
+
super().__init__(*args)
|
|
53
|
+
self.sloth_requirer = SlothRequirer(self)
|
|
54
|
+
|
|
55
|
+
def _on_config_changed(self, event):
|
|
56
|
+
# Get validated SLO specs from all related charms
|
|
57
|
+
slos = self.sloth_requirer.get_slos()
|
|
58
|
+
# Process SLOs and generate rules
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
For complete documentation, see the [charmlibs documentation](https://documentation.ubuntu.com/charmlibs/reference/charmlibs/interfaces/sloth).
|
|
64
|
+
|
|
65
|
+
## Contributing
|
|
66
|
+
|
|
67
|
+
See [CONTRIBUTING.md](https://github.com/canonical/charmlibs/blob/main/CONTRIBUTING.md) in the repository root.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "charmlibs-interfaces-sloth"
|
|
3
|
+
description = "Sloth integration for Juju charms - SLO (Service Level Objective) management with the Sloth operator."
|
|
4
|
+
readme = "README.md"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
authors = [
|
|
7
|
+
{name="The Observability team at Canonical Ltd."},
|
|
8
|
+
]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Programming Language :: Python :: 3",
|
|
11
|
+
"License :: OSI Approved :: Apache Software License",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Operating System :: POSIX :: Linux",
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
]
|
|
16
|
+
dynamic = ["version"]
|
|
17
|
+
dependencies = [
|
|
18
|
+
"ops",
|
|
19
|
+
"pydantic>=2.0",
|
|
20
|
+
"pyyaml",
|
|
21
|
+
"cosl>=0.0.10",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[dependency-groups]
|
|
25
|
+
lint = [ # installed for `just lint interfaces/sloth` (unit, functional, and integration are also installed)
|
|
26
|
+
"typing_extensions",
|
|
27
|
+
]
|
|
28
|
+
unit = [ # installed for `just unit interfaces/sloth`
|
|
29
|
+
"ops[testing]",
|
|
30
|
+
"pytest",
|
|
31
|
+
]
|
|
32
|
+
functional = [ # installed for `just functional interfaces/sloth`
|
|
33
|
+
]
|
|
34
|
+
integration = [ # installed for `just integration interfaces/sloth`
|
|
35
|
+
"jubilant",
|
|
36
|
+
"pytest-jubilant",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
"Repository" = "https://github.com/canonical/charmlibs"
|
|
41
|
+
"Issues" = "https://github.com/canonical/charmlibs/issues"
|
|
42
|
+
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["hatchling"]
|
|
45
|
+
build-backend = "hatchling.build"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/charmlibs"]
|
|
49
|
+
|
|
50
|
+
[tool.hatch.version]
|
|
51
|
+
path = "src/charmlibs/interfaces/sloth/_version.py"
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
extend = "../../pyproject.toml"
|
|
55
|
+
src = ["src", "tests/unit", "tests/functional", "tests/integration"] # correctly sort local imports in tests
|
|
56
|
+
exclude = [
|
|
57
|
+
"tests/integration/charms/*/library",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint.extend-per-file-ignores]
|
|
61
|
+
# add additional per-file-ignores here to avoid overriding repo-level config
|
|
62
|
+
"tests/**/*" = [
|
|
63
|
+
# "E501", # line too long
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.pyright]
|
|
67
|
+
extends = "../../pyproject.toml"
|
|
68
|
+
include = ["src", "tests"]
|
|
69
|
+
pythonVersion = "3.10" # check no python > 3.10 features are used
|
|
70
|
+
|
|
71
|
+
[tool.charmlibs.functional]
|
|
72
|
+
ubuntu = [] # ubuntu versions to run functional tests with, e.g. "24.04" (defaults to just "latest")
|
|
73
|
+
pebble = [] # pebble versions to run functional tests with, e.g. "v1.0.0", "master" (defaults to no pebble versions)
|
|
74
|
+
sudo = false # whether to run functional tests with sudo (defaults to false)
|
|
75
|
+
|
|
76
|
+
[tool.charmlibs.integration]
|
|
77
|
+
# tags to run integration tests with (defaults to running once with no tag, i.e. tags = [''])
|
|
78
|
+
# Available in CI in tests/integration/pack.sh and integration tests as CHARMLIBS_TAG
|
|
79
|
+
tags = [] # Not used by the pack.sh and integration tests generated by the template
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright 2026 Canonical Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
r"""Sloth Provider and Requirer Library.
|
|
16
|
+
|
|
17
|
+
This library provides a way for charms to share SLO (Service Level Objective)
|
|
18
|
+
specifications with the Sloth charm, which will convert them into Prometheus
|
|
19
|
+
recording and alerting rules.
|
|
20
|
+
|
|
21
|
+
Getting Started
|
|
22
|
+
===============
|
|
23
|
+
|
|
24
|
+
Provider Side (Charms providing SLO specs)
|
|
25
|
+
-------------------------------------------
|
|
26
|
+
|
|
27
|
+
To provide SLO specifications to Sloth, use the ``SlothProvider`` class.
|
|
28
|
+
The recommended approach is to allow users to configure SLOs via ``juju config``::
|
|
29
|
+
|
|
30
|
+
from charmlibs.interfaces.sloth import SlothProvider
|
|
31
|
+
|
|
32
|
+
class MyCharm(ops.CharmBase):
|
|
33
|
+
def __init__(self, *args):
|
|
34
|
+
super().__init__(*args)
|
|
35
|
+
self.sloth_provider = SlothProvider(self)
|
|
36
|
+
self.framework.observe(self.on.config_changed, self._on_config_changed)
|
|
37
|
+
|
|
38
|
+
def _on_config_changed(self, event):
|
|
39
|
+
# Read SLO configuration from juju config
|
|
40
|
+
slo_config = self.config.get('slo_config', '')
|
|
41
|
+
if slo_config:
|
|
42
|
+
self.sloth_provider.provide_slos(slo_config)
|
|
43
|
+
|
|
44
|
+
Users can then configure SLOs using ``juju config``::
|
|
45
|
+
|
|
46
|
+
juju config my-app slo_config='
|
|
47
|
+
version: prometheus/v1
|
|
48
|
+
service: my-service
|
|
49
|
+
labels:
|
|
50
|
+
team: my-team
|
|
51
|
+
slos:
|
|
52
|
+
- name: requests-availability
|
|
53
|
+
objective: 99.9
|
|
54
|
+
description: "99.9% of requests should succeed"
|
|
55
|
+
sli:
|
|
56
|
+
events:
|
|
57
|
+
error_query: '\''sum(rate(http_requests_total{status=~"5.."}[{{.window}}]))'\''
|
|
58
|
+
total_query: '\''sum(rate(http_requests_total[{{.window}}]))'\''
|
|
59
|
+
alerting:
|
|
60
|
+
name: MyServiceHighErrorRate
|
|
61
|
+
labels:
|
|
62
|
+
severity: critical
|
|
63
|
+
'
|
|
64
|
+
|
|
65
|
+
To specify multiple SLOs for different services, separate them with YAML document
|
|
66
|
+
separators (``---``).
|
|
67
|
+
|
|
68
|
+
Requirer Side (Sloth charm)
|
|
69
|
+
----------------------------
|
|
70
|
+
|
|
71
|
+
The Sloth charm uses ``SlothRequirer`` to collect SLO specifications.
|
|
72
|
+
Validation is performed on the requirer side::
|
|
73
|
+
|
|
74
|
+
from charmlibs.interfaces.sloth import SlothRequirer
|
|
75
|
+
|
|
76
|
+
class SlothCharm(ops.CharmBase):
|
|
77
|
+
def __init__(self, *args):
|
|
78
|
+
super().__init__(*args)
|
|
79
|
+
self.sloth_requirer = SlothRequirer(self)
|
|
80
|
+
|
|
81
|
+
def _on_config_changed(self, event):
|
|
82
|
+
# Get validated SLO specs from all related charms
|
|
83
|
+
slos = self.sloth_requirer.get_slos()
|
|
84
|
+
# Process SLOs and generate rules
|
|
85
|
+
|
|
86
|
+
Relation Data Format
|
|
87
|
+
====================
|
|
88
|
+
|
|
89
|
+
SLO specifications are stored in the relation databag as YAML strings under the
|
|
90
|
+
``slo_spec`` key. Each provider unit can provide one or more SLO specifications.
|
|
91
|
+
|
|
92
|
+
For a single service::
|
|
93
|
+
|
|
94
|
+
slo_spec: |
|
|
95
|
+
version: prometheus/v1
|
|
96
|
+
service: my-service
|
|
97
|
+
labels:
|
|
98
|
+
team: my-team
|
|
99
|
+
slos:
|
|
100
|
+
- name: requests-availability
|
|
101
|
+
objective: 99.9
|
|
102
|
+
description: "99.9% of requests should succeed"
|
|
103
|
+
sli:
|
|
104
|
+
events:
|
|
105
|
+
error_query: 'sum(rate(http_requests_total{status=~"5.."}[{{.window}}]))'
|
|
106
|
+
total_query: 'sum(rate(http_requests_total[{{.window}}]))'
|
|
107
|
+
alerting:
|
|
108
|
+
name: MyServiceHighErrorRate
|
|
109
|
+
labels:
|
|
110
|
+
severity: critical
|
|
111
|
+
|
|
112
|
+
For multiple services (separated by YAML document separators)::
|
|
113
|
+
|
|
114
|
+
slo_spec: |
|
|
115
|
+
version: prometheus/v1
|
|
116
|
+
service: my-service
|
|
117
|
+
slos:
|
|
118
|
+
- name: requests-availability
|
|
119
|
+
objective: 99.9
|
|
120
|
+
---
|
|
121
|
+
version: prometheus/v1
|
|
122
|
+
service: my-other-service
|
|
123
|
+
slos:
|
|
124
|
+
- name: requests-latency
|
|
125
|
+
objective: 99.5
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
from ._sloth import (
|
|
129
|
+
SLOError,
|
|
130
|
+
SLORelationData,
|
|
131
|
+
SLOSpec,
|
|
132
|
+
SlothProvider,
|
|
133
|
+
SlothRequirer,
|
|
134
|
+
SLOValidationError,
|
|
135
|
+
)
|
|
136
|
+
from ._topology import inject_topology_labels
|
|
137
|
+
from ._version import __version__ as __version__
|
|
138
|
+
|
|
139
|
+
__all__ = [
|
|
140
|
+
'SLOError',
|
|
141
|
+
'SLORelationData',
|
|
142
|
+
'SLOSpec',
|
|
143
|
+
'SLOValidationError',
|
|
144
|
+
'SlothProvider',
|
|
145
|
+
'SlothRequirer',
|
|
146
|
+
'inject_topology_labels',
|
|
147
|
+
]
|