Skip to content

Commit e8c6a94

Browse files
authored
chore: enable metrics using prometheus-flask-exporter (#755)
* chore: enable metrics using prometheus-flask-exporter Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * chore: remove prefix and attempt to fix docker build failure Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * move env to Dockefile Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * move env to Dockefile Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * fix test expectaion path Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * opt: localize metric tracker to api_v2 blueprint Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * chore: remove useless hacks on v2 Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * fix linter and unit test Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * fix linter and unit test Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * remove obsolute tests Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com> * enable monitoring through Service definition * remove unused decls Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com>
1 parent 3f6df57 commit e8c6a94

12 files changed

Lines changed: 121 additions & 348 deletions

File tree

Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi8/ubi-minimal
1+
FROM registry.access.redhat.com/ubi8/python-36:latest
22

33
LABEL name="bayesian-api" \
44
description="bayesian API server" \
@@ -9,16 +9,14 @@ LABEL name="bayesian-api" \
99

1010
ENV LANG=en_US.UTF-8 PYTHONDONTWRITEBYTECODE=1
1111

12-
ADD ./requirements.txt /coreapi/
13-
ADD bayesian/ /coreapi/bayesian/
14-
15-
RUN microdnf install python3 git && microdnf clean all
1612
RUN pip3 install --upgrade pip --no-cache-dir
13+
14+
ADD ./requirements.txt /coreapi/
1715
RUN pip3 install -r /coreapi/requirements.txt --no-cache-dir
1816

19-
ADD bayesian/scripts/entrypoint.sh /coreapi/bayesian/scripts/entrypoint.sh
20-
# generated by Makefile, contains build date and time
21-
RUN chmod +x /coreapi/bayesian/scripts/entrypoint.sh
2217
ADD hack/coreapi-release /etc/
18+
ADD bayesian/ /coreapi/bayesian/
19+
ADD bayesian/scripts/entrypoint.sh /coreapi/bayesian/scripts/entrypoint.sh
2320

24-
ENTRYPOINT ["/coreapi/bayesian/scripts/entrypoint.sh"]
21+
ENV PROMETHEUS_MULTIPROC_DIR=/tmp
22+
ENTRYPOINT ["bash", "/coreapi/bayesian/scripts/entrypoint.sh"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fast-docker-build: coreapi-release
2626
docker tag $(REGISTRY)/$(REPOSITORY):$(DEFAULT_TAG) $(IMAGE_NAME)
2727

2828
test: fast-docker-build
29-
./runtest.sh
29+
./qa/runtest.sh
3030

3131
get-image-name:
3232
@echo $(REGISTRY)/$(REPOSITORY):$(DEFAULT_TAG)

bayesian/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from f8a_worker.setup_celery import init_selinon
77
from flask import Flask
88
from flask import g
9-
from flask import redirect
10-
from flask import url_for
9+
from flask.json import jsonify
1110
from flask_appconfig import AppConfig
1211
from flask_cache import Cache
1312
from flask_sqlalchemy import SQLAlchemy
@@ -58,8 +57,6 @@ def create_app(configfile=None):
5857
app.register_blueprint(api_v1)
5958
app.register_blueprint(api_v2)
6059
app.register_blueprint(user_api)
61-
# Redirect to latest API version if /api is accessed
62-
app.route('/api')(lambda: redirect(url_for('api_v2.apiendpoints__slashless')))
6360
# Likewise for base URL, and make that accessible by name
6461

6562
# Configure CORS.
@@ -68,10 +65,13 @@ def create_app(configfile=None):
6865
CORS(app, resources={r"/user/*": {"origins": "*"}})
6966

7067
@app.route('/')
68+
@app.route('/api')
7169
def base_url():
72-
return redirect(url_for('api_v2.apiendpoints__slashless'))
73-
74-
setup_logging(app)
70+
endpoints = set()
71+
for rule in app.url_map.iter_rules():
72+
if rule.endpoint != 'static':
73+
endpoints.add(rule.rule)
74+
return jsonify({'paths': sorted(endpoints)})
7575

7676
@app.before_request
7777
def set_current_user():
@@ -87,13 +87,13 @@ def access_control_allow_origin(response):
8787
response.headers["Allow"] = "GET, HEAD, OPTIONS, PATCH, POST, PUT"
8888
return response
8989

90+
setup_logging(app)
9091
return app
9192

9293

9394
init_selinon()
9495

9596
app = create_app()
96-
9797
SENTRY_DSN = os.environ.get("SENTRY_DSN", "")
9898
sentry = Sentry(app, dsn=SENTRY_DSN, logging=True, level=logging.ERROR)
9999

0 commit comments

Comments
 (0)