-
Notifications
You must be signed in to change notification settings - Fork 10
Add uWSGI support #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ | |
|
||
# scratch directory for preparing releases | ||
/.release/ | ||
|
||
# Python | ||
__pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM alpine:3.15 | ||
|
||
RUN mkdir /opt/app | ||
WORKDIR /opt/app | ||
|
||
RUN apk update && apk add python3 py3-pip python3-dev build-base linux-headers pcre-dev | ||
RUN pip3 install --no-cache-dir uwsgi flask ddtrace | ||
|
||
COPY ./uwsgi.ini /opt/app/uwsgi.ini | ||
COPY ./wsgi.py /opt/app/wsgi.py | ||
COPY ./app.py /opt/app/app.py | ||
|
||
CMD ["uwsgi", "--ini", "uwsgi.ini"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import Flask, request, jsonify | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/", defaults={"path": ""}) | ||
@app.route("/<string:path>") | ||
@app.route("/<path:path>") | ||
def main(path): | ||
response = { | ||
"service": "uwsgi", | ||
"headers": dict(request.headers) | ||
} | ||
print(response) | ||
return jsonify(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[uwsgi] | ||
module = wsgi:app | ||
master = true | ||
socket = :8080 | ||
|
||
;; dd-trace-py is used to trace the Flask application. | ||
;; It requires these options to supports uWSGI. | ||
;; See <https://ddtrace.readthedocs.io/en/stable/advanced_usage.html#uwsgi>. | ||
enable-threads = 1 | ||
lazy-apps = 1 | ||
import=ddtrace.bootstrap.sitecustomize | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app import app | ||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load_module modules/ngx_http_datadog_module.so; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
|
||
location / { | ||
include /etc/nginx/uwsgi_params; | ||
uwsgi_pass uwsgi:8080; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/cases/auto_propagation/conf/uwsgi_disabled_at_http.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load_module modules/ngx_http_datadog_module.so; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
datadog_disable; | ||
server { | ||
listen 80; | ||
|
||
location / { | ||
include /etc/nginx/uwsgi_params; | ||
uwsgi_pass uwsgi:8080; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/cases/auto_propagation/conf/uwsgi_disabled_at_location.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load_module modules/ngx_http_datadog_module.so; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
|
||
location / { | ||
datadog_disable; | ||
include /etc/nginx/uwsgi_params; | ||
uwsgi_pass uwsgi:8080; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/cases/auto_propagation/conf/uwsgi_disabled_at_server.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load_module modules/ngx_http_datadog_module.so; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
datadog_disable; | ||
|
||
location / { | ||
include /etc/nginx/uwsgi_params; | ||
uwsgi_pass uwsgi:8080; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/cases/auto_propagation/conf/uwsgi_without_module.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
|
||
location / { | ||
include /etc/nginx/uwsgi_params; | ||
uwsgi_pass uwsgi:8080; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from .. import case | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
|
||
class TestUWSGI(case.TestCase): | ||
|
||
def test_auto_propagation(self): | ||
return self.run_test('./conf/uwsgi_auto.conf', should_propagate=True) | ||
|
||
def test_disabled_at_location(self): | ||
return self.run_test('./conf/uwsgi_disabled_at_location.conf', | ||
should_propagate=False) | ||
|
||
def test_disabled_at_server(self): | ||
return self.run_test('./conf/uwsgi_disabled_at_server.conf', | ||
should_propagate=False) | ||
|
||
def test_disabled_at_http(self): | ||
return self.run_test('./conf/uwsgi_disabled_at_http.conf', | ||
should_propagate=False) | ||
|
||
def test_without_module(self): | ||
return self.run_test('./conf/uwsgi_without_module.conf', | ||
should_propagate=False) | ||
|
||
def run_test(self, conf_relative_path, should_propagate): | ||
conf_path = Path(__file__).parent / conf_relative_path | ||
conf_text = conf_path.read_text() | ||
status, log_lines = self.orch.nginx_replace_config( | ||
conf_text, conf_path.name) | ||
self.assertEqual(status, 0, log_lines) | ||
|
||
status, body = self.orch.send_nginx_http_request('/') | ||
self.assertEqual(status, 200) | ||
response = json.loads(body) | ||
self.assertEqual(response['service'], 'uwsgi') | ||
headers = response['headers'] | ||
if should_propagate: | ||
self.assertIn('X-Datadog-Sampling-Priority', headers) | ||
priority = headers['X-Datadog-Sampling-Priority'] | ||
priority = int(priority) | ||
else: | ||
self.assertNotIn('X-Datadog-Sampling-Priority', headers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM alpine:3.15 | ||
|
||
RUN mkdir /opt/app | ||
WORKDIR /opt/app | ||
|
||
RUN apk update && apk add python3 py3-pip python3-dev build-base linux-headers pcre-dev | ||
RUN pip3 install --no-cache-dir uwsgi flask ddtrace | ||
|
||
COPY ./uwsgi.ini /opt/app/uwsgi.ini | ||
COPY ./wsgi.py /opt/app/wsgi.py | ||
COPY ./app.py /opt/app/app.py | ||
|
||
CMD ["uwsgi", "--ini", "uwsgi.ini"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from flask import Flask, request, jsonify | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def main(): | ||
response = { | ||
"service": "uwsgi", | ||
"headers": dict(request.headers) | ||
} | ||
print(response) | ||
return jsonify(response) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a couple of minutes to figure this out, because the spot where ddtrace is installed is quite subtle.
Maybe some additional comments would be helpful
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more informations. As a non native english speaker, any suggestion will be appreciated :) Resolved in d475f16