Skip to content

Commit 02e7514

Browse files
authored
PyMS Documentation issues (#1)
* docs: resolved PyMS issue #162 python-microservices/pyms#162 * docs: resolved PyMS issue #161 python-microservices/pyms#161 * docs: updated command line options Closed issue python-microservices/pyms#203 * docs: added example of jaeger server
1 parent 9fbdd5b commit 02e7514

7 files changed

+172
-11
lines changed

docs/command_line.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,11 @@ This command uses [prance](https://github.com/jfinkhaeuser/prance) to validate t
9090
pyms merge-swagger --file 'app/swagger/swagger.yaml'
9191
>> Swagger file generated [swagger-complete.yaml]
9292
>> OK
93+
```
94+
95+
### Create configuration from command line
96+
PyMS has a command line option to create a config file. You can run the next command in the terminal:
97+
98+
```bash
99+
pyms create-config
93100
```

docs/installation.md

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
## Python Version
44
We recommend using the latest version of Python 3. PyMS supports Python 3.6 and newer and PyPy.
55

6-
```
7-
virtualenv --python=python[3.6|3.7|3.8] venv
8-
source venv/bin/activate
9-
```
10-
116
## Install PyMS
127

138
**Installing pyms with all dependencies**
@@ -35,4 +30,61 @@ pip install py-ms[metrics]
3530
pip install py-ms[trace]
3631
```
3732

33+
## Install with virtualenv and requirements.txt
34+
35+
Create a [virtualenv](https://virtualenv.pypa.io/en/latest/)
36+
37+
```
38+
virtualenv --python=python[3.6|3.7|3.8] venv
39+
source venv/bin/activate
40+
```
41+
42+
Add in your requirements.txt:
43+
44+
```
45+
py-ms[all|metrics|trace]==[VERSION]
46+
```
47+
48+
In example:
49+
50+
```
51+
py-ms[all]>=2.7.0
52+
```
53+
54+
and then install with
55+
56+
```
57+
pip install -r requirements.txt
58+
```
59+
60+
## Install with pipenv and Pipfile
61+
62+
Create a [pipenv](https://pipenv-es.readthedocs.io/) environment
63+
64+
```
65+
pipenv install
66+
```
67+
68+
Or install PyMS with the command:
69+
70+
```
71+
pipenv install py-ms[all]>=2.7.0
72+
```
73+
74+
Or add PyMS in your Pipfile:
75+
76+
```toml
77+
[[source]]
78+
name = "pypi"
79+
url = "https://pypi.org/simple"
80+
verify_ssl = true
81+
82+
[dev-packages]
83+
84+
[packages]
85+
py-ms = {extras = ["all"],version = "==2.6.1"}
86+
```
87+
88+
## Next Steps
89+
3890
See [Quickstart](quickstart.md) to continue with this tutorial

docs/structure_project.md

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

docs/tutorials/tutorial_propagate_traces.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ You have applied the Microservice architecture pattern. Requests often span mult
66
Each service handles a request by performing one or more operations, e.g. database queries, publishes messages, etc.
77

88
PyMS injects a unique request ID with [opentracing](https://github.com/opentracing-contrib/python-flask) and
9-
passes the external request id to all services that are involved in handling the current request with the [service request](services.md)
9+
passes the external request id to all services that are involved in handling the current request with the
10+
[service request](services.md)
1011

1112
## 1. Simple Trace
1213

@@ -189,3 +190,24 @@ You can see the flow of these requests in this diagram:
189190
190191
You can check this example on [this Github page](https://github.com/python-microservices/pyms/tree/master/examples/microservice_distribued_tracing)
191192
193+
The simplest way to start the all-in-one is to use the pre-built image published to DockerHub (a single command line).
194+
195+
# Tracer server
196+
197+
You can see the traces with [jaeger server](https://www.jaegertracing.io/docs/1.20/getting-started/):
198+
199+
```shell
200+
$ docker run -d --name jaeger \
201+
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
202+
-p 5775:5775/udp \
203+
-p 6831:6831/udp \
204+
-p 6832:6832/udp \
205+
-p 5778:5778 \
206+
-p 16686:16686 \
207+
-p 14268:14268 \
208+
-p 14250:14250 \
209+
-p 9411:9411 \
210+
jaegertracing/all-in-one:1.20
211+
```
212+
213+
You can then navigate to `http://localhost:16686` to access the Jaeger UI.

docs/tutorials/tutorial_testing.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Tutorial 3: Testing with Pytest and PyMS
2+
3+
Testing a microservice with PyMS is very similar to a Flask Application.
4+
5+
## Create App Pattern
6+
7+
The recommended way to start is using [Create App Pattern](https://flask.palletsprojects.com/en/1.1.x/patterns/appfactories/).
8+
Using PyMS is like Flask:
9+
10+
```python
11+
from pyms.flask.app import Microservice
12+
13+
def create_app():
14+
ms = Microservice(path=__file__)
15+
return ms.create_app()
16+
```
17+
18+
## Conftest.py and Pytest
19+
20+
Then, you can use these functions in your conftest.py with Pytest:
21+
22+
### Config environment
23+
24+
PyMS needs the environment variable `PYMS_CONFIGMAP_FILE` to look for the configuration file, is recommended
25+
to create a specific config file to testing:
26+
27+
```python
28+
import os
29+
def conf_environment():
30+
if not os.environ.get("PYMS_CONFIGMAP_FILE", False):
31+
os.environ["PYMS_CONFIGMAP_FILE"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config-tests.yml")
32+
```
33+
34+
### Initialize Flask
35+
36+
Create an app object to use in tests
37+
38+
```python
39+
import pytest
40+
@pytest.fixture(scope="session")
41+
def app():
42+
conf_environment()
43+
app = create_app()
44+
return app
45+
```
46+
47+
### Initialize Flask
48+
49+
Create Flask testing client
50+
51+
```python
52+
@pytest.fixture(scope="module")
53+
def client(app, db):
54+
"""A test client for the app."""
55+
return app.test_client()
56+
```
57+
58+
### Extra: url of your tests
59+
60+
Get the url to use in tests
61+
62+
```python
63+
@pytest.fixture(scope="module")
64+
def base_url(app):
65+
"""Base url of the service."""
66+
return app.config["APPLICATION_ROOT"]()
67+
```
68+
69+
### Ready to testing your code
70+
71+
With this configuration, you are ready to create your own tests with PyMS:
72+
73+
```python
74+
def test_list_actors(client, base_url):
75+
response = client.get('{base_url}healthcheck'.format(base_url=base_url))
76+
assert 200 == response.status_code
77+
```
78+
79+
As you can see, is very similar to a normal Flask application :)

docs/tutorials/tutorials.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ With this tutorial you can solve the problem of [distributed tracing](https://mi
1111
## Tutorial 2: How To contribute, Create your own service
1212

1313
[See tutorial](tutorial_create_services.md)
14+
15+
## Tutorial 3: Testing with Pytest and PyMS
16+
17+
[See tutorial](tutorial_testing.md)

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ nav:
1515
- Microservice class: ms_class.md
1616
- Routing: routing.md
1717
- Encrypt/Decrypt Configuration: encrypt_decryt_configuration.md
18-
- Command line: command_line.md
1918
- PyMS structure: structure.md
20-
- Structure of a microservice project: structure_project.md
19+
- Command line: command_line.md
2120
- Introduction to microservices:
2221
- Introduction to microservices (ENG): microservices.md
2322
- Introduction to microservices (SPA): microservicios.md
@@ -26,6 +25,7 @@ nav:
2625
- Basic Examples: tutorials/examples.md
2726
- Create services: tutorials/tutorial_create_services.md
2827
- Propagate traces: tutorials/tutorial_propagate_traces.md
28+
- Testing with PyMS: tutorials/tutorial_testing.md
2929
- Projects:
3030
- Scaffold:
3131
- Index: scaffold/index.md

0 commit comments

Comments
 (0)