Skip to content

Commit

Permalink
#33: Adding prometheus metrics (#83)
Browse files Browse the repository at this point in the history
* #33: Adding prometheus metrics

* #33: Deleting todo

Co-authored-by: Daniil Bondarenko <sumasedsiefakty@gmail.com>
  • Loading branch information
daniilBondarenk and danbond02 authored Feb 18, 2022
1 parent b7befc3 commit f51cf76
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions g2w/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from fastapi.routing import APIRouter

from g2w import Push, Ws, LoggableRoute, Alert, Log, __version__
from prometheus_fastapi_instrumentator import Instrumentator

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


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


if __name__ == "__main__": # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ codecov
mypy
gitchangelog
mkdocs
requests
requests
prometheus_fastapi_instrumentator
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ fastapi
uvicorn[standard]
pydantic
Airspeed
types-PyYAML
types-PyYAML
prometheus_fastapi_instrumentator
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def go_to_tmpdir(request):


class AbstractTest(unittest.TestCase):

def body(self, json_file: str, folder="tests/resources") -> dict:
filename = os.path.join(os.path.realpath(folder), json_file)
with open(filename, "r") as read_file:
Expand Down
13 changes: 2 additions & 11 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,14 @@ class ClientTest(AbstractTest):
def test_e2e_push(self):
# ws = 'http://worksection.api'
# requests_mock.get('http://test.com', text='data')
response = TestClient(app).post(
"/gitlab/push/223728",
json=self.body("sample2_commits.json")
)
response = TestClient(app).post("/gitlab/push/223728", json=self.body("sample2_commits.json"))
self.assertEqual(response.status_code, 200)
self.assertGreater(int(response.json()["comments"][0]["id"]), 0)

@pytest.mark.skipif(os.getenv("WS_ADMIN_EMAIL") is None, reason="Environment variable 'WS_ADMIN_EMAIL' is absent")
@pytest.mark.skipif(os.getenv("WS_URL_POST_TASK") is None, reason="Environment variable 'WS_URL_POST_TASK' is absent")
@pytest.mark.skipif(os.getenv("WS_INT_TESTS_DISABLED") is not None, reason="Integration tests are disabled")
def test_e2e_alert(self):
response = TestClient(app).post(
"/grafana/alert/223728",
json=self.body("sample1_alert.json")
)
response = TestClient(app).post("/grafana/alert/223728", json=self.body("sample1_alert.json"))
self.assertEqual(response.status_code, 200)
self.assertGreater(response.json()["created"]["id"], 0)



0 comments on commit f51cf76

Please sign in to comment.