Skip to content

Commit a1badc9

Browse files
authored
Merge pull request #16 from imrehg/updates
Various updates
2 parents 1e370a2 + ff3f04c commit a1badc9

File tree

7 files changed

+243
-70
lines changed

7 files changed

+243
-70
lines changed

.github/workflows/python.yaml

+6-11
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,24 @@ jobs:
2727
run: git checkout ${{ env.BRANCH }}
2828

2929
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v1
30+
uses: actions/setup-python@v3
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333

3434
- name: Install dependencies
3535
run: |
3636
python -m pip install --upgrade pip
37-
python -m pip install 'poetry>=1.2.0b1'
37+
python -m pip install 'poetry>=1.2.0b1' 'nox'
3838
poetry plugin add poetry-dynamic-versioning-plugin
39-
poetry install
39+
nox -l
4040
4141
- name: Run linting
4242
run: |
43-
poetry run isort --check src/ tests/
44-
poetry run black --check src/ tests/
45-
poetry run flake8 src/ tests/
46-
poetry run mypy src
47-
poetry run bandit src
43+
nox -s lint
4844
4945
- name: Run unit tests
5046
run: |
51-
poetry run coverage run -m pytest
52-
poetry run coverage report -m
47+
nox -s test-${{ matrix.python-version }}
5348
5449
publish:
5550
name: "Publish to PyPI"
@@ -63,7 +58,7 @@ jobs:
6358
fetch-depth: 0
6459

6560
- name: Set up Python 3.10
66-
uses: actions/setup-python@v1
61+
uses: actions/setup-python@v3
6762
with:
6863
# Needs to be string for 3.10, otherwise it's wrongly parsed as 3.1
6964
python-version: '3.10'

noxfile.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import nox
2+
3+
source_folders = ["src/"]
4+
project_folders = source_folders + ["tests/"]
5+
6+
# Default sessions
7+
nox.options.sessions = ["lint", "test"]
8+
9+
10+
@nox.session
11+
def format(session):
12+
"""Run code formatting."""
13+
session.run("poetry", "install", external=True)
14+
session.run("isort", *project_folders)
15+
session.run("black", *project_folders)
16+
17+
18+
@nox.session
19+
def lint(session):
20+
"""Run linting checks on the code."""
21+
session.run("poetry", "install", "--with", "test", external=True)
22+
session.run("isort", "--check", *project_folders)
23+
session.run("black", "--check", *project_folders)
24+
session.run("flake8", *project_folders)
25+
session.run("mypy", *source_folders)
26+
session.run("bandit", "-r", *source_folders)
27+
28+
29+
@nox.session(python=["3.10", "3.11"])
30+
def test(session):
31+
"""Run tests on the code."""
32+
session.run("poetry", "install", "--with", "test", external=True)
33+
try:
34+
session.run("coverage", "run", "-m", "pytest")
35+
finally:
36+
session.run("coverage", "report", "-m")

poetry.lock

+152-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+26-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ license = "Apache-2.0"
1111
include = [
1212
"LICENSE.txt",
1313
]
14+
classifiers = [
15+
'Development Status :: 3 - Alpha',
16+
'Framework :: Pytest',
17+
'Intended Audience :: Information Technology',
18+
'Intended Audience :: System Administrators',
19+
'Natural Language :: English',
20+
'Operating System :: OS Independent',
21+
'Topic :: System :: Monitoring',
22+
'Topic :: System :: Networking :: Monitoring',
23+
'Typing :: Typed',
24+
]
1425

1526
[tool.poetry.dependencies]
1627
python = "^3.10"
@@ -20,7 +31,15 @@ dynaconf = "^3.1.8"
2031
types-requests = "^2.27.25"
2132
jsonrpcclient = "^4.0.2"
2233

23-
[tool.poetry.dev-dependencies]
34+
[tool.poetry.group.dev.dependencies]
35+
isort = "*"
36+
black = "*"
37+
nox = "*"
38+
39+
[tool.poetry.group.test]
40+
optional = true
41+
42+
[tool.poetry.group.test.dependencies]
2443
pytest = "*"
2544
pytest-cov = "*"
2645
requests-mock = "*"
@@ -30,6 +49,12 @@ flake8 = "*"
3049
mypy = "*"
3150
bandit = "*"
3251

52+
[tool.poetry.scripts]
53+
linkhub_exporter = "linkhub_prometheus_exporter.exporter:main"
54+
55+
[tool.poetry.urls]
56+
"Bug Tracker" = "https://github.com/imrehg/linkhub_prometheus_exporter/issues"
57+
3358
[tool.isort]
3459
profile = "black"
3560
src_paths = ["src", "tests"]
@@ -43,17 +68,11 @@ module = [
4368
]
4469
ignore_missing_imports = true
4570

46-
[tool.poetry.scripts]
47-
linkhub_exporter = "linkhub_prometheus_exporter.exporter:main"
48-
4971
[tool.poetry-dynamic-versioning]
5072
enable = true
5173
vcs = "git"
5274
style = "pep440"
5375

54-
[tool.poetry-dynamic-versioning.substitution]
55-
files = ["*/__init__.py", "*/*/__init__.py"]
56-
5776
[build-system]
5877
requires = ["poetry>=1.2.0b1", "poetry-dynamic-versioning-plugin"]
5978
build-backend = "poetry.masonry.api"
+9-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# Will be dynamically filled
2-
__version__ = "0.0.0"
1+
from importlib.metadata import PackageNotFoundError, version
2+
3+
try:
4+
__version__ = version("linkhub_prometheus_exporter")
5+
except PackageNotFoundError:
6+
# This package is not installed.
7+
__version__ = "unknown"
8+
finally:
9+
del PackageNotFoundError, version

src/linkhub_prometheus_exporter/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Validator("POLLING_INTERVAL_SECONDS", is_type_of=int, default=5),
1010
Validator("BOX_ADDRESS", is_type_of=str, default="192.168.1.1"),
1111
Validator("EXPORTER_PORT", is_type_of=int, default=9877),
12-
Validator("EXPORTER_ADDRESS", is_type_of=str, default="0.0.0.0"),
12+
Validator("EXPORTER_ADDRESS", is_type_of=str, default="localhost"),
1313
],
1414
)
1515

src/linkhub_prometheus_exporter/exporter.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _box_api_request(self, method: str) -> dict[str, Any]:
7878
)
7979
raise RuntimeError(message)
8080
case _:
81-
assert False, "Impossible parsed response received."
81+
raise AssertionError("Impossible parsed response received.")
8282

8383
def _read_network_info(self) -> None:
8484
"""Requesting, parsing, and updating network info metrics."""
@@ -140,6 +140,13 @@ def fetch_metrics(self) -> None:
140140
def main() -> None:
141141
"""Main entry point for the exporter"""
142142
logging.info("Linkhub Prometheus Exporter, version %s", __version__)
143+
# Add exporter metadata to what's exported
144+
exporter_info = Info("exporter_info", "Exporter information")
145+
exporter_info.info(
146+
{
147+
"version": __version__,
148+
}
149+
)
143150

144151
try:
145152
router_metrics = RouterMetrics(
@@ -152,6 +159,11 @@ def main() -> None:
152159
logging.error("Missing REQUEST_KEY configuration.")
153160
raise RuntimeError("Missing REQUEST_KEY configuration.") from exc
154161

162+
logging.info(
163+
"Server starting on http://%s:%d",
164+
settings.EXPORTER_ADDRESS,
165+
settings.EXPORTER_PORT,
166+
)
155167
start_http_server(
156168
port=settings.EXPORTER_PORT, addr=settings.EXPORTER_ADDRESS
157169
)

0 commit comments

Comments
 (0)