Skip to content

Commit 580d152

Browse files
committed
Merge branch 'feature/add_tracer' into develop
2 parents 7353b59 + 31bad0d commit 580d152

File tree

17 files changed

+80
-50
lines changed

17 files changed

+80
-50
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[run]
22
include=
33
*project/*
4+
*pyms/*
45
omit =
56
venv/*

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
FROM python:3.6.4-alpine3.7
22

3-
RUN apk add --update curl gcc g++ libffi-dev openssl-dev python3-dev \
3+
RUN apk add --update curl gcc g++ git libffi-dev openssl-dev python3-dev \
44
&& rm -rf /var/cache/apk/*
55
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
66

77
ENV PYTHONUNBUFFERED=1 ENVIRONMENT=pre APP_HOME=/microservice/
8+
RUN mkdir $APP_HOME && adduser -S -D -H python
89

9-
RUN mkdir $APP_HOME
10+
RUN chown -R python $APP_HOME
1011
WORKDIR $APP_HOME
1112
ADD requirement*.txt $APP_HOME
1213
RUN pip install -r requirements-docker.txt
1314
ADD . $APP_HOME
1415

1516
EXPOSE 5000
17+
USER python
1618

1719
CMD ["gunicorn", "--worker-class", "eventlet", "--workers", "8", "--log-level", "INFO", "--bind", "0.0.0.0:5000", "manage:app"]

app.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

project/__init__.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
from flasgger import Swagger
66
from flask import Flask
7-
from flask_opentracing import FlaskTracer
8-
from jaeger_client import Config
7+
from flask_injector import FlaskInjector
8+
from injector import Injector
99

1010
from project.config import CONFIG
11+
from pyms.healthcheck import healthcheck_blueprint
12+
from pyms.models import db
13+
from pyms.tracer.main import TracerModule
1114

1215
__author__ = "Alberto Vara"
1316
__email__ = "a.vara.1986@gmail.com"
@@ -47,24 +50,13 @@
4750
}
4851

4952

50-
def init_jaeger_tracer(service_name='your-app-name'):
51-
"""This scaffold is configured whith `Jeager <https://github.com/jaegertracing/jaeger>`_ but you can use
52-
one of the `opentracing tracers <http://opentracing.io/documentation/pages/supported-tracers.html>`_
53-
:param service_name: the name of your application to register in the tracer
54-
:return: opentracing.Tracer
55-
"""
56-
config = Config(config={
57-
'sampler': {'type': 'const', 'param': 1}
58-
}, service_name=service_name)
59-
return config.initialize_tracer()
60-
61-
6253
class PrefixMiddleware(object):
6354
"""Set a prefix path to all routes. This action is needed if you have a stack of microservices and each of them
6455
exist in the same domain but different path. Por example:
6556
* mydomain.com/ms1/
6657
* mydomain.com/ms2/
6758
"""
59+
6860
def __init__(self, app, prefix=''):
6961
self.app = app
7062
self.prefix = prefix
@@ -86,20 +78,14 @@ def create_app():
8678
return the app and the database objects.
8779
:return:
8880
"""
89-
from project.models import db
81+
9082
from project.views import views_bp as views_blueprint
91-
from project.views import views_hc as views_hc_blueprint
9283
environment = os.environ.get("ENVIRONMENT", "default")
9384

9485
app = Flask(__name__)
9586
app.config.from_object(CONFIG[environment])
9687
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix=app.config["APPLICATION_ROOT"])
9788

98-
99-
if not app.config["TESTING"] and not app.config["DEBUG"]:
100-
j_tracer = init_jaeger_tracer(app.config["APP_NAME"])
101-
FlaskTracer(j_tracer, True, app)
102-
10389
db.init_app(app)
10490

10591
# Initialize Swagger
@@ -119,7 +105,13 @@ def create_app():
119105

120106
# Initialize Blueprints
121107
app.register_blueprint(views_blueprint)
122-
app.register_blueprint(views_hc_blueprint)
108+
app.register_blueprint(healthcheck_blueprint)
109+
110+
# Inject Modules
111+
if not app.config["TESTING"] and not app.config["DEBUG"]:
112+
injector = Injector([TracerModule(app)])
113+
FlaskInjector(app=app, injector=injector)
114+
123115
with app.test_request_context():
124116
db.create_all()
125117
return app, db

project/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class DevConfig(Config):
2828
"""Configuration to run in local environments"""
2929

3030
DEBUG = True
31-
TESTING = True
3231
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(BASE_DIR, "db.sqlite3")
3332

3433

project/models/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
# encoding: utf-8
2-
from __future__ import absolute_import, print_function, unicode_literals
3-
4-
from flask_sqlalchemy import SQLAlchemy
5-
6-
db = SQLAlchemy()

project/models/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from sqlalchemy import Column, Integer, String, DateTime
77

8-
from project.models import db
8+
from pyms.models import db
99

1010

1111
def dump_datetime(value: datetime) -> list:

project/views/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
from flask import Blueprint
55

66
views_bp = Blueprint('views', __name__, static_url_path='/static')
7-
views_hc = Blueprint('healthcheck', __name__, static_url_path='/static')
87

9-
from project.views import views, healthcheck
8+
from project.views import views

project/views/healthcheck.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

project/views/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
from flask import request, jsonify
55

6-
from project.models.models import db, Colors
6+
from pyms.models import db
7+
from project.models.models import Colors
78
from project.views import views_bp
89

910

0 commit comments

Comments
 (0)