Skip to content

Commit

Permalink
Add /info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ppietruszewski-consult-red authored and piotr-serafin-red committed Dec 5, 2023
1 parent 43035c7 commit 3a7f58a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 3 additions & 2 deletions service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#

from flask import Flask
from info import Info

app = Flask(__name__)

app_info = Info()

@app.route("/healthz")
def healthz() -> str:
return 'OK'

@app.route('/info')
def info():
return 'OK'
return app_info.get()
29 changes: 29 additions & 0 deletions service/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from datetime import datetime
import os
import socket

class Info:
"""Get information about service"""

def __init__(self) -> None:
"""Read info"""
self.app_start_time = datetime.utcnow()
self.host_name = socket.gethostname()
self.app_branch = os.getenv("APP_BRANCH", "undefined")
self.app_name = os.getenv("APP_NAME", "undefined")
self.app_build_time = os.getenv("APP_BUILD_TIME", "undefined")
self.app_version = os.getenv("APP_VERSION", "undefined")
self.stack_name = os.getenv("STACK_NAME", "undefined")
self.app_revision = os.getenv("APP_REVISION", "undefined")

def get(self) -> dict:
info = {}
info['APP_START_TIME'] = self.app_start_time.strftime('%Y-%m-%dT%H:%M:%SZ')
info['HOST_NAME'] = self.host_name
info['APP_BRANCH'] = self.app_branch
info['APP_NAME'] = self.app_name
info['APP_BUILD_TIME'] = self.app_build_time
info['APP_VERSION'] = self.app_version
info['STACK_NAME'] = self.stack_name
info['APP_REVISION'] = self.app_revision
return info
4 changes: 2 additions & 2 deletions service/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
boto3~=1.17.101
gunicorn>=3.5
flask~=2.0.1
pika~=1.2.0
flask~=3.0.0
pika~=1.2.0

0 comments on commit 3a7f58a

Please sign in to comment.