Skip to content

Commit

Permalink
Merge pull request #48 from CSCI-5828-S24/dev
Browse files Browse the repository at this point in the history
CLoud Function can be run locally
  • Loading branch information
RanajitRoy authored May 3, 2024
2 parents ec76e7c + 384b4bb commit 1e4e9a4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
59 changes: 37 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# BetaFish
Group 12: Emily Parker, Ranajit Roy, Jonathan Gorman
# ![Denver Crime Tracker Banner](./diagrams/project-banner.png)

### Group 12 (Betafish): Emily Parker, Ranajit Roy, Jonathan Gorman

[![analyzer-test](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_analyzer.yml/badge.svg?branch=main)](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_analyzer.yml) [![collector-test](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_collector.yml/badge.svg?branch=main)](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_collector.yml) [![flask-server-test](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_flask_server.yml/badge.svg?branch=main)](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/test_flask_server.yml) [![integration-test](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/integration-tests.yml/badge.svg?branch=main)](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/integration-tests.yml) [![playwright-acceptance-test](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/playwright-acceptance-tests.yml/badge.svg?branch=main)](https://github.com/CSCI-5828-S24/BetaFish/actions/workflows/playwright-acceptance-tests.yml)

Expand All @@ -9,26 +10,39 @@ Below are the instruction run the we app locally on an linux/ubuntu or windows p

Install the below packages before proceeding -
1. Python3
2. Python packages: redis jsonpickle requests flask flask_cors flask-mysqldb python-dotenv
> pip3 install --upgrade redis jsonpickle requests flask flask_cors flask-mysqldb python-dotenv
3. Node.js 20.x lts

2. Node.js 20.x lts

First clone the repository

> git clone \<repo-clone-url\>
A `.env` file is necessary for the MySQL Connection. Create a `.env` in `\flask-backend\src\` and populate with the following 4 lines
A `.env` file is necessary for the MySQL Connection. Create a `.env` in `./flask-backend`, `./cloud-data-collector` and `./cloud-data-analyzer` and populate with the following 5 lines with correct data. (leave analyzer url - used to call analyzer service from collector. Not required if called manually)

```
MYSQL_HOST = host
MYSQL_USER = user
MYSQL_PASSWORD = password
MYSQL_DB = databasename
MYSQL_HOST=<hostname>
MYSQL_USER=<user>
MYSQL_PASSWORD=<password>
MYSQL_DB=crime_db
ANALYZER_URL=http://ip.jsontest.com
```

To build the app, run the commands below in the cloned directory -
Run Collector: -<br>
[working directory: ./cloud-data-collector]
```
pip install -r requirements
python3 main.py
```


Run Analyzer: -<br>
[working directory: ./cloud-data-analyzer]
```
pip install -r requirements
python3 main.py
```


To build the app, run the commands below in the cloned directory -
```
npm --prefix ./react-frontend/ ci
npm --prefix ./react-frontend/ build
Expand All @@ -39,21 +53,22 @@ Now there are two options:
* run with a docker image


### Run locally

> python3 flask-backend/src/flask_server.py
### Run on Docker

In order to run on a docker image, run the below commands:

### Run on terminal
[working directory: ./flask-backend]
```
docker build -t web-app .
docker run -p5000:5000 web-app
python3 src/flask_server.py
```

Now, the web page should be accessible on port 5000 on localhost

### Monitoring
We have implemented `/metrics` endpoint with **prometheus** metrics.

Metrics:
1. Counter: `total_req`
2. Histogram: `analytics_latency`
3. Histogram: `data_latency`

## Current Completed Architecture
![image](./diagrams/architecture.png)

Expand Down
2 changes: 2 additions & 0 deletions cloud-data-analyzer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ def analyze(request):
mydb.commit()
return "success" if status else "failed"

if __name__=="__main__":
analyze(None)
2 changes: 2 additions & 0 deletions cloud-data-collector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ def collect(request):
return "done!!"


if __name__=="__main__":
collect(None)
Binary file added diagrams/project-banner.png
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 1e4e9a4

Please sign in to comment.