Skip to content

Commit f51cf76

Browse files
#33: Adding prometheus metrics (#83)
* #33: Adding prometheus metrics * #33: Deleting todo Co-authored-by: Daniil Bondarenko <[email protected]>
1 parent b7befc3 commit f51cf76

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

g2w/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
from fastapi.routing import APIRouter
1111

1212
from g2w import Push, Ws, LoggableRoute, Alert, Log, __version__
13+
from prometheus_fastapi_instrumentator import Instrumentator
1314

1415
ws = Ws()
1516
app = FastAPI(version=__version__, title="g2w")
1617
router = APIRouter(route_class=LoggableRoute)
1718
log = logging.getLogger(f"g2w.{__name__}")
19+
Instrumentator().instrument(app).expose(app)
1820

1921

2022
@router.post(
@@ -103,8 +105,6 @@ def main() -> None: # pragma: no cover
103105
args.log_file, args.log.upper(), args.log_format
104106
).read(),
105107
)
106-
# @todo #/DEV Add prometheus client library for app monitoring
107-
# https://github.com/prometheus/client_python
108108

109109

110110
if __name__ == "__main__": # pragma: no cover

requirements-test.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ codecov
99
mypy
1010
gitchangelog
1111
mkdocs
12-
requests
12+
requests
13+
prometheus_fastapi_instrumentator

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ fastapi
1111
uvicorn[standard]
1212
pydantic
1313
Airspeed
14-
types-PyYAML
14+
types-PyYAML
15+
prometheus_fastapi_instrumentator

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def go_to_tmpdir(request):
1919

2020

2121
class AbstractTest(unittest.TestCase):
22-
2322
def body(self, json_file: str, folder="tests/resources") -> dict:
2423
filename = os.path.join(os.path.realpath(folder), json_file)
2524
with open(filename, "r") as read_file:

tests/test_app.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,14 @@ class ClientTest(AbstractTest):
2222
def test_e2e_push(self):
2323
# ws = 'http://worksection.api'
2424
# requests_mock.get('http://test.com', text='data')
25-
response = TestClient(app).post(
26-
"/gitlab/push/223728",
27-
json=self.body("sample2_commits.json")
28-
)
25+
response = TestClient(app).post("/gitlab/push/223728", json=self.body("sample2_commits.json"))
2926
self.assertEqual(response.status_code, 200)
3027
self.assertGreater(int(response.json()["comments"][0]["id"]), 0)
3128

3229
@pytest.mark.skipif(os.getenv("WS_ADMIN_EMAIL") is None, reason="Environment variable 'WS_ADMIN_EMAIL' is absent")
3330
@pytest.mark.skipif(os.getenv("WS_URL_POST_TASK") is None, reason="Environment variable 'WS_URL_POST_TASK' is absent")
3431
@pytest.mark.skipif(os.getenv("WS_INT_TESTS_DISABLED") is not None, reason="Integration tests are disabled")
3532
def test_e2e_alert(self):
36-
response = TestClient(app).post(
37-
"/grafana/alert/223728",
38-
json=self.body("sample1_alert.json")
39-
)
33+
response = TestClient(app).post("/grafana/alert/223728", json=self.body("sample1_alert.json"))
4034
self.assertEqual(response.status_code, 200)
4135
self.assertGreater(response.json()["created"]["id"], 0)
42-
43-
44-

0 commit comments

Comments
 (0)