-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from DataDog/TRAIN-1523-documentation
Adds documentation to services
- Loading branch information
Showing
6 changed files
with
454 additions
and
2 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,137 @@ | ||
# Advertisements Service | ||
|
||
## Description | ||
|
||
This service is responsible for managing the banner advertisements served to the frontend service of the application. There are two variations of this service, one uses Python and the other uses Java. | ||
|
||
## Python service | ||
|
||
The Python service is a Flask application that uses SQLAlchemy to connect to a PostgreSQL database. The service is packaged as a Docker image and typically used in a Docker Compose file (see the root of this repo). | ||
|
||
### Datadog configuration | ||
|
||
#### Logs | ||
|
||
Logging is configured in the `docker-compose.yml` file along with the Datadog Agent. | ||
|
||
#### APM | ||
|
||
The `ddtrace` library is used to instrument the Python service. The `ddtrace` library is installed in the `requirements.txt` file. The `ddtrace-run` command is used to run the service in the `Dockerfile`. | ||
|
||
Log injection is enabled in the `docker-compose.yml` file, but the logs are formatted in the `ads.py` file. | ||
|
||
### Endpoints (Python) | ||
|
||
Use the following endpoints to interact with the service. | ||
|
||
#### GET / | ||
|
||
Returns a message indicating that the service is running. | ||
|
||
##### Request | ||
|
||
```text | ||
GET / | ||
``` | ||
|
||
##### Response | ||
|
||
```text | ||
Hello from Advertisements! | ||
``` | ||
|
||
#### GET /ads | ||
|
||
Returns a list of all advertisements. There are only three advertisements in the database. | ||
|
||
##### Request | ||
|
||
```text | ||
GET /ads | ||
``` | ||
|
||
##### Response | ||
|
||
```json | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "Discount Clothing", | ||
"path": "1.jpg", | ||
"url": "/t/clothing", | ||
"weight": 15.1 | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "Cool Hats", | ||
"path": "2.jpg", | ||
"url": "/products/datadog-ringer-t-shirt", | ||
"weight": 300.1 | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "Nice Bags", | ||
"path": "3.jpg", | ||
"url": "/t/bags", | ||
"weight": 5242.1 | ||
} | ||
] | ||
``` | ||
|
||
#### GET /banners/<path:banner> | ||
|
||
Returns the banner image specified by the path parameter. Use this to display images on the frontend. | ||
|
||
##### Request | ||
|
||
```text | ||
GET /banners/1.jpg | ||
``` | ||
|
||
##### Response Type | ||
|
||
```text | ||
image/jpg | ||
``` | ||
|
||
#### POST /ads | ||
|
||
Creates a new advertisement with a random name and value. Currently doesn't work as intended (I believe). | ||
|
||
##### Request | ||
|
||
```text | ||
POST /ads | ||
``` | ||
|
||
##### Response | ||
|
||
```json | ||
{ | ||
"id": 4, | ||
"name": "New Ad", | ||
"path": "4.jpg", | ||
"url": "/t/new", | ||
"weight": 0.0 | ||
} | ||
``` | ||
|
||
### Database | ||
|
||
The Python service uses a PostgreSQL database. The database is configured in the `docker-compose.yml` file. | ||
|
||
The application uses SQLAlchemy to connect to the database. The `models.py` file contains the SQLAlchemy model and the `bootstrap.py` file contains database connection and setup code. | ||
|
||
#### Database schema | ||
|
||
The `ads` table has the following schema: | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | integer | Unique identifier for the advertisement (Primary Key) | | ||
| name | string | Name of the advertisement | | ||
| url | string | URL to redirect to when the advertisement is clicked | | ||
| weight | float | Weight of the advertisement (used for A/B testing) | | ||
| path | string | Path to the advertisement image | | ||
|
||
|
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,4 @@ | ||
# Authentication service | ||
|
||
## Description | ||
|
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,6 @@ | ||
# Backend service (product management) | ||
|
||
## Overview | ||
|
||
This service manages the products in the store. It is a Ruby on Rails application built using the Spree framework. The service is packaged as a Docker image and typically used in a Docker Compose file (see the root of this repo). | ||
|
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,34 @@ | ||
# DBM service | ||
|
||
## Description | ||
|
||
This service is used for our database monitoring courses, built with Python that uses the SQLAlchemy ORM to connect to a Postgres database. When the service is started, the library Faker is used to generate fake data for the database and in our labs we run a few queries in the background to simulate a load on the database. | ||
|
||
> TODO: Add queries from labs to this repo | ||
There is also a user-facing component to this service, which can be seen in the `frontend` service with a specific flag thrown in the `featureFlags.config.json` file. Turning it on will result in a product ticker being displayed in the navbar of the application. | ||
|
||
## Database schema | ||
|
||
The database schema can be found in the `models.py` file with these models: | ||
|
||
### items | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | Integer | Primary key | | ||
| description | String | Description of the item | | ||
| order_count | String | Number of times the item has been ordered | | ||
| last_hour_order_count | String | Number of times the item has been ordered in the last hour | | ||
| image_url | String | URL to an image of the item | | ||
|
||
### preorder_items | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | Integer | Primary key | | ||
| description | String | Description of the item | | ||
| order_count | String | Number of times the item has been ordered | | ||
| last_hour | String | Number of times the item has been ordered in the last hour | | ||
| image_url | String | URL to an image of the item | | ||
| is_preorder | Boolean | Whether or not the item is a preorder item | |
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 |
---|---|---|
@@ -1,3 +1,154 @@ | ||
To test the words module: | ||
# Discounts service | ||
|
||
`python3 -m unittest test.py` | ||
## Description | ||
|
||
This service is responsible for managing discounts written in Python using the Flask framework. It uses a PostgreSQL database to store the discounts. | ||
|
||
## Datadog configuration | ||
|
||
### Logs | ||
|
||
Logging is configured in the `docker-compose.yml` file along with the Datadog Agent. | ||
|
||
### APM | ||
|
||
The `ddtrace` library is used to instrument the Python service. The `ddtrace` library is installed in the `requirements.txt` file. The `ddtrace-run` command is used to run the service in the `Dockerfile`. | ||
|
||
Log injection is enabled in the `docker-compose.yml` file, but the logs are formatted in the `ads.py` file. | ||
|
||
## Endpoints | ||
|
||
Use the following endpoints to interact with the service. | ||
|
||
### GET / (health check) | ||
|
||
Returns a message indicating that the service is up and running. | ||
|
||
#### Request | ||
|
||
```text | ||
GET / | ||
``` | ||
|
||
#### Response | ||
|
||
```text | ||
Hello from Discounts! | ||
``` | ||
|
||
### GET /discount | ||
|
||
Returns a list of all discounts. | ||
|
||
#### Request | ||
|
||
```text | ||
GET /discount | ||
``` | ||
|
||
#### Response | ||
|
||
```json | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "10% off", | ||
"description": "10% off all items", | ||
"active": true | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "20% off", | ||
"description": "20% off all items", | ||
"active": true | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "30% off", | ||
"description": "30% off all items", | ||
"active": true | ||
}, | ||
... | ||
] | ||
``` | ||
|
||
### POST /discount | ||
|
||
Creates a new discount at random. It doesn't accept a request body. | ||
|
||
#### Request | ||
|
||
```text | ||
POST /discount | ||
``` | ||
|
||
#### Response | ||
|
||
Returns all discounts with new one appended. | ||
|
||
```json | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "10% off", | ||
"description": "10% off all items", | ||
"active": true | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "20% off", | ||
"description": "20% off all items", | ||
"active": true | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "30% off", | ||
"description": "30% off all items", | ||
"active": true | ||
}, | ||
... | ||
{ | ||
"id": 99, | ||
"name": "100% off", | ||
"description": "New Discount", | ||
"active": true | ||
} | ||
] | ||
``` | ||
|
||
## Database | ||
|
||
The service uses a PostgreSQL database to store the discounts. The database is configured in the `docker-compose.yml` file. | ||
|
||
The application uses the SQLAlchemy ORM to interact with the database. The `Discount` and `Influencer` model are defined in the `models.py` file and the `discounts` table is created in the `bootstrap.py` file. | ||
|
||
### Schema | ||
|
||
The `discounts` table has the following schema: | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | integer | Unique identifier for the discount (Primary Key) | | ||
| name | string | Name of the discount | | ||
| code | string | Discount code | | ||
| value | integer | Discount value | | ||
| discount_type_id | integer | Foreign key to the discount type | | ||
|
||
> **Note**: We use these values the most. The other two tables seem serve a legacy purpose. | ||
The `discount_types` table has the following schema: | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | integer | Unique identifier for the discount type (Primary Key) | | ||
| name | string | Name of the discount type | | ||
| influencer_id | integer | Foreign key to the influencer | | ||
| discount_query | string | Query to get the discount | | ||
|
||
The `influencers` table has the following schema: | ||
|
||
| Column | Type | Description | | ||
| --- | --- | --- | | ||
| id | integer | Unique identifier for the influencer (Primary Key) | | ||
| name | string | Name of the influencer | | ||
| discount_types | string | Discount types associated with the influencer | |
Oops, something went wrong.