-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
055aafd
commit c6112c2
Showing
33 changed files
with
1,845 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
0.0.2 - 2022-12-15 | ||
=================== | ||
|
||
### Features | ||
- Add [Application stack](./generate_data_application/). | ||
- Add CHANGELOG.md. | ||
- Add MAINTAINERS.md. | ||
|
||
### Updating | ||
- Update README with the architecture of application stack and a new source. | ||
- Update [agent.yaml](./agent/agent.yaml) for the application stack. | ||
- Change log level for Grafana in [config.ini](./grafana/config.ini). | ||
- Update [Loki config](./loki/loki-config.yaml) for the application stack. | ||
- Update log level for Mimir in [mimir.yaml](./mimir/mimir.yaml). | ||
- Update log level for NGinx in [nginx.conf](./nginx/nginx.conf). | ||
- Update log level for Tempo in [tempo.yaml](./tempo/tempo.yaml). |
This file contains 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 @@ | ||
- [@tonyglandyl28](https://github.com/tonyglandyl28) |
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,24 @@ | ||
FROM python:bullseye | ||
RUN apt-get update && apt-get install --no-install-recommends -y systemctl=1.4.4181-1.1 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
WORKDIR /usr/local/bin/ | ||
SHELL ["/bin/bash", "-eo", "pipefail", "-c"] | ||
|
||
# Configure Promtail to send logs to Grafana Agent | ||
RUN curl -s -q https://api.github.com/repos/grafana/loki/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep promtail-linux-arm64.zip | wget -i - && \ | ||
unzip promtail-linux-arm64.zip && \ | ||
mv ./promtail-linux-arm64 ./promtail | ||
COPY config/promtail-config.yaml /etc/promtail/ | ||
RUN useradd --system promtail | ||
COPY config/promtail.service /etc/systemd/system/ | ||
|
||
# Configure FastAPI application | ||
WORKDIR /usr/src/app | ||
RUN chmod a+rwx /usr/src/app | ||
COPY config/requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
COPY app . | ||
COPY config/start.sh ./config/ | ||
EXPOSE 5050 | ||
CMD ["/bin/sh", "./config/start.sh"] |
This file contains 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,125 @@ | ||
""" | ||
Function to define FastAPI routes | ||
""" | ||
|
||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy.exc import OperationalError | ||
from schemas import ClientsBase, Clients | ||
from responsesSettings import responsesMessages | ||
import connection, crud_clients | ||
from observability import LOGGER, tracer | ||
|
||
traces = tracer.get_tracer(__name__) | ||
|
||
LOGGER = LOGGER.getChild(__name__) | ||
|
||
router = APIRouter( | ||
tags=["clients"], | ||
responses={ | ||
400: responsesMessages['400'], | ||
403: responsesMessages['403'], | ||
404: responsesMessages['404'], | ||
405: responsesMessages['405'], | ||
422: responsesMessages['422'], | ||
500: responsesMessages['500'] | ||
} | ||
) | ||
|
||
def get_db(): | ||
""" | ||
Database connexion | ||
""" | ||
db = connection.SessionLocal() | ||
try: | ||
LOGGER.debug("Open database connexion") | ||
yield db | ||
finally: | ||
LOGGER.debug("Close database connexion") | ||
db.close() | ||
|
||
@router.post(path="/clients", | ||
response_model=Clients, | ||
status_code=201, | ||
summary="Client creation" | ||
) | ||
async def post_client(client: ClientsBase, db: Session = Depends(get_db)): | ||
""" | ||
Create client with all parameters : | ||
- **firstname**: Firstname of the client | ||
- **lastname**: Lastname of the client | ||
""" | ||
with traces.start_as_current_span("Router GET client by ID"): | ||
LOGGER.info("Start POST Client") | ||
new_client = crud_clients.create(db=db, client=client) | ||
return new_client | ||
|
||
@router.get(path="/clients", | ||
response_model=list[Clients], | ||
status_code=200, | ||
summary="List clients" | ||
) | ||
async def get_clients(db: Session = Depends(get_db)): | ||
""" | ||
List all clients | ||
""" | ||
with traces.start_as_current_span("Router GET clients List"): | ||
LOGGER.info("Start GET Clients List") | ||
try: | ||
list_clients = crud_clients.get_list(db=db) | ||
return list_clients | ||
except OperationalError as error: | ||
LOGGER.error(error) | ||
return "" | ||
|
||
@router.get(path="/clients/{client_id}", | ||
response_model=Clients, | ||
status_code=200, | ||
summary="Details for specific client") | ||
async def get_client(client_id: str, db: Session = Depends(get_db)): | ||
""" | ||
Details for specific client | ||
""" | ||
with traces.start_as_current_span("Router GET client by ID"): | ||
LOGGER.info("Start GET Client by ID") | ||
client = crud_clients.get_client(db=db, client_id=client_id) | ||
LOGGER.debug("Return client : %s" % str(client)) | ||
return client | ||
|
||
@router.put(path="/clients/{client_id}", | ||
response_model=Clients, | ||
status_code=200, | ||
summary="Modify details for a specific client") | ||
async def put_client(client_id: str, client: ClientsBase, db: Session = Depends(get_db)): | ||
""" | ||
Modify details for a specific client : | ||
- **firstname**: Firstname of the client | ||
- **lastname**: Lastname of the client | ||
""" | ||
with traces.start_as_current_span("Router Modify clients by ID"): | ||
LOGGER.info("Start PUT Client by ID") | ||
try: | ||
modify_client = crud_clients.put(db=db, client_id=client_id, client=client) | ||
return modify_client | ||
except OperationalError as error: | ||
LOGGER.error(error) | ||
return "" | ||
|
||
@router.delete(path="/clients/{client_id}", | ||
response_model=None, | ||
status_code=204, | ||
summary="Delete a specific client" | ||
) | ||
async def delete_client(client_id: str, db: Session = Depends(get_db)): | ||
""" | ||
Delete a specific client | ||
""" | ||
with traces.start_as_current_span("Router DELETE clients by ID"): | ||
LOGGER.info("Start DELETE Client by ID") | ||
delete_client = crud_clients.get_client(db=db, client_id=client_id) | ||
if delete_client is None: | ||
raise HTTPException(status_code=405) | ||
crud_clients.delete(db=db, client_id=client_id) | ||
return None |
Oops, something went wrong.