Skip to content

Commit

Permalink
add architecture and load test result to readme, fix duplicate metric…
Browse files Browse the repository at this point in the history
…s at main.py
  • Loading branch information
okzapradhana committed Jun 25, 2021
1 parent 0d65e3f commit 5a8d9c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ Those payloads **MUST** pass the gatekeeper's schema rule (specified in [`valida

It is similar to CDC process that empowers message queue with help from Google PubSub.

## Architecture
![archi](images/Architecture.png)
From this architecture, it will receive payloads that comes from API request to our endpoint. Which need to validate by Flask + [jsonschema](https://json-schema.org/) .

If the payload is invalid, push the metrics to Pushgateway which can be pulled by Prometheus later.

But if the payload is valid, besides push the metrics to Pushgateway it also publish the payload message to Topic with Google PubSub.

Then some subscribers listen to specific topic and consumes message that published to that topic. Then, every message will be processed as a Database transaction either `delete` operation, `insert` operation or both.

But, naturally BigQuery doesn't support multiple statement transactions as it's not intend as transaction Database, thus how we handle this case? I've made implementation on that which you might see more in [here](#how-to-handle-transactions-in-bigquery)


## Tech Stack:
1. Python
2. Flask
3. Google PubSub
4. Google BigQuery

5. Prometheus Pushgateway
## Setup
### Initial
To use this project on your computer. You need to clone this repository first.
Expand Down Expand Up @@ -113,6 +126,12 @@ Points your `GOOGLE_APPLICATION_CREDENTIALS` to your service account file path.

Locust tutorial: https://docs.locust.io/en/stable/what-is-locust.html

**Load Test result**
![locust-result](images/Locust%20Performance%20Testing%20max%201000%20user%20with%205%20user%20grow%20rate.png)

For load test I used maximum 1000 users with 5 users spawned per second (spawn rate)


## Explanation
We have to create API endpoint which received message from Backend Team. The example of validated payload which has right structure is:
```
Expand Down
5 changes: 3 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

@app.route("/")
def say_hello():
base_registry = CollectorRegistry()
g = Gauge('job_last_success_unixtime',
'Last time a batch job successfully finished', registry=registry)
'Last time a batch job successfully finished', registry=base_registry)
g.set_to_current_time()
push_to_gateway(PUSHGATEWAY_PROMETHEUS_HOST,
job='base_endpoint', registry=registry)
job='base_endpoint', registry=base_registry)
return "Hello World, congratulations on installing Flask"


Expand Down
Binary file added images/Architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a8d9c6

Please sign in to comment.