Skip to content

Commit 36d7fd6

Browse files
committed
readme refactoring
1 parent f8dd33b commit 36d7fd6

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

README.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ This project is an example that how to implement FastAPI and the pydiator-core.
77
`uvicorn main:app --reload`
88
or `docker-compose up`
99

10-
swagger http://0.0.0.0:8000
11-
1210
# How to run Tests
1311
`coverage run --source app/ -m pytest`
1412

@@ -31,8 +29,8 @@ This architecture;
3129

3230
There are ready implementations;
3331
* Redis cache
34-
* Swagger
35-
* Opentracing via Jaeger
32+
* Swagger (http://0.0.0.0:8080)
33+
* Opentracing via Jaeger (http://0.0.0.0:16686/)
3634

3735

3836
# How to add the new use case?
@@ -75,15 +73,15 @@ If the cache already exists, the cache pipeline returns with cache data so, the
7573

7674
```python
7775
class GetTodoAllRequest(BaseModel, BaseRequest, BaseCacheable):
78-
# uses for cache key.
76+
# cache key.
7977
def get_cache_key(self) -> str:
8078
return type(self).__name__ # it is cache key
8179

8280
# cache duration value as second
8381
def get_cache_duration(self) -> int:
8482
return 600
8583

86-
# pipeline decides the cache location via this
84+
# cache location type
8785
def get_cache_type(self) -> CacheType:
8886
return CacheType.DISTRIBUTED
8987
```
@@ -97,6 +95,26 @@ Requirements;
9795
2- Must be activated the below environment variables on the config for using the cache;
9896

9997
DISTRIBUTED_CACHE_IS_ENABLED=True
100-
10198
CACHE_PIPELINE_IS_ENABLED=True
10299

100+
# Tracing via Jaeger
101+
Requirements;
102+
103+
1- Must have a jaeger server and should be set the below environment variables
104+
105+
JAEGER_HOST = 'jaeger ip'
106+
JAEGER_PORT = 'jaeger port'
107+
108+
2- Must be activated the below environment variables on the config for using the jaeger;
109+
110+
TRACER_IS_ENABLED=True
111+
112+
![pydiator](https://raw.githubusercontent.com/ozgurkara/pydiator-core/master/assets/jaeger_is_not_enabled.png)
113+
114+
3- If want to trace the handlers, should be activated the below environment variables on the config for using the jaeger. Otherwise, can just see the endpoint trace details.
115+
116+
CACHE_PIPELINE_IS_ENABLED=True
117+
118+
![pydiator](https://raw.githubusercontent.com/ozgurkara/pydiator-core/master/assets/jaeger.png)
119+
120+

app/resources/todo/todo_resource.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
})
2424
async def get_todo_all():
25-
return await pydiator.send(GetTodoAllRequest())
25+
return await pydiator.send(req=GetTodoAllRequest())
2626

2727

2828
@router.get("/{id}",
@@ -41,7 +41,7 @@ async def get_todo_all():
4141
},
4242
})
4343
async def get_todo_by_id(id: int):
44-
return await pydiator.send(GetTodoByIdRequest(id=id))
44+
return await pydiator.send(req=GetTodoByIdRequest(id=id))
4545

4646

4747
@router.post("",
@@ -60,7 +60,7 @@ async def get_todo_by_id(id: int):
6060
},
6161
})
6262
async def add_todo(req: AddTodoRequest):
63-
return await pydiator.send(req)
63+
return await pydiator.send(req=req)
6464

6565

6666
@router.put("/{id}",
@@ -79,7 +79,7 @@ async def add_todo(req: AddTodoRequest):
7979
})
8080
async def update_todo(id: int, req: UpdateTodoRequest):
8181
req.CustomFields.id = id
82-
return await pydiator.send(req)
82+
return await pydiator.send(req=req)
8383

8484

8585
@router.delete("/{id}",
@@ -97,4 +97,4 @@ async def update_todo(id: int, req: UpdateTodoRequest):
9797
},
9898
})
9999
async def delete_todo(id: int):
100-
return await pydiator.send(DeleteTodoByIdRequest(id=id))
100+
return await pydiator.send(req=DeleteTodoByIdRequest(id=id))

app/utils/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
REDIS_DB = config('REDIS_DB', int, 0)
1111
REDIS_KEY_PREFIX = config('REDIS_KEY_PREFIX', str, 'fastapi_pydiator:')
1212

13-
DISTRIBUTED_CACHE_IS_ENABLED = config("DISTRIBUTED_CACHE_IS_ENABLED", bool, False)
13+
DISTRIBUTED_CACHE_IS_ENABLED = config("DISTRIBUTED_CACHE_IS_ENABLED", bool, True)
1414
CACHE_PIPELINE_IS_ENABLED = config("CACHE_PIPELINE_IS_ENABLED", bool, True)
1515
LOG_PIPELINE_IS_ENABLED = config("LOG_PIPELINE_IS_ENABLED", bool, True)
1616
TRACER_PIPELINE_IS_ENABLED = config("TRACER_PIPELINE_IS_ENABLED", bool, True)

app/utils/pydiator/pipelines/tracer_pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ async def handle(self, req: BaseRequest) -> object:
2121

2222
with tracer.start_active_span(req.get_class_name(), child_of=current_span, tags=span_tags,
2323
finish_on_close=True):
24-
response = await self.next().handle(req)
24+
response = await self.next().handle(req=req)
2525
return response

docs/assets/jaeger.png

503 KB
Loading
348 KB
Loading

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
uvicorn==0.13.3
22
fastapi==0.63.0
33
fastapi-contrib==0.2.9
4-
pydiator-core==1.0.6
4+
pydiator-core==1.0.7
55
pydantic==1.7.3
66
redis==3.5.3
77

@@ -13,7 +13,7 @@ pytest-env==0.6.2
1313
python-dotenv==0.15.0
1414

1515
# tracing
16-
jaeger-client==4.3.0
16+
jaeger-client==4.4.0
1717
opentracing==2.4.0
1818
opentracing-instrumentation==3.3.1
1919
tornado==5.1.1

0 commit comments

Comments
 (0)