Here is a simple metrics uploader importer.py (saves test_data.csv to prepared DB) and the service to read the imported data in simple HTML format.
- Postgres DB
- Python 3.7
- pipenv
Its a simple CLI application which allows you to save test_data.csv to a DB. Be aware, you need to setup DB first, before applying CSV to it.
- run
python -m pipenv installto create a virtual environment and install dependencies - run
sh resources/init.shto create DB and all needed tables - run
python importer.py --csv resources/task_data.csv --url postgresql://<user>:<password>@<host>/<db_name>
NOTE: use your own username and password for DB (in init.sh and --url), mine are default from Docker Postgres image
To check that data was really imported the DB:
- run
psql -h <host> -U <user>and type password after to connect to Postgres - run
\c <db_name>to connect to DB - run
SELECT * FROM metrics;
This is a Flask-RestX simple service to get data from DB and return it as simple HTML. Each request to this service is logged separately to table logs in DB.
- make sure you run
python -m pipenv installto install all dependencies and virtual environment - make sure that DB is created (see
resources/init.sh) and populated (seeImportersection) - make sure your DB credentials are valid in
service/config.py - run
python service/app.pyto run an application
To check the output call with CURL or in Browse http://127.0.0.1:5000/api/v1/metrics
Also the service supports query param limit, it will return exact amount of rows from DB what was specified.
For example http://127.0.0.1:5000/api/v1/metrics?limit=1
If this parameter is not specified, you will get the full output.
To check that request was logged run SQL query in DB (see Importer section): SELECT * FROM logs;
To run unit tests use:
python -m unittest discover -s tests/ -v- Its better to use env variables in init.sh instead of hardcoding them
- Importer is not ideal, it would nice to have it more flexible, to be able upload different CSVs, and with better validation
- There is no unit-tests for Importer, I understand it is important to have
- TODO: get output by timestamp
- Instead I added
limitparameter