The goal of the Logging Building Block is to provide a set of RESTFul web services to log all the activities of the bp.
cd loggingservice
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
You need to have a .env
file in this directory that contains credentials required for authentication.
Not all of these variables may be required for this building block.
Example file format:
ROKWIRE_API_KEY=<API Key 1>,<API Key 2>,<API Key 3>
ROKWIRE_ISSUER=<Rokwire ID Token Issuer Name>
# AWS environment variables to set when running on development machine.
# This is not required when running within AWS.
AWS_ACCESS_KEY_ID=<AWS Access Key ID>
AWS_SECRET_ACCESS_KEY=<AWS Secret Access Key>
export FLASK_ENV=development
python api/logging_rest_service.py
and the Logging Building Block should be running at localhost at port 5000 (http://localhost:5000/logs).
The detailed API information is in logging.yaml in the OpenAPI Spec 3.0 format.
If you want to use gunicorn, cd into api folder then, use gunicorn logging_rest_service:app -c gunicorn.config.py
instead of python api/logging_rest_service.py
cd rokwire-building-blocks-api
docker build -f loggingservice/Dockerfile -t rokwire/logging-building-block .
docker run --name logging --rm --env-file loggingservice/.env -e API_LOC=. -e PRINT_LOG=True -e DEBUG=False -e LOGGING_URL_PREFIX=<url_prefix_starting_with_slash> -p 5000:5000 rokwire/logging-building-block
You can edit config.py or environment variable to specify a URL prefix by modifying LOGGIN_URL_PREFIX variable. If you need to make just /logs as endpoint, put the variable value to empty string or do not include this variable.
LOGGING_URL_PREFIX="/logs"
Make sure the repository called rokwire/logging-building-block exists in ECR. Then create Docker image for Rokwire Platform API and push to AWS ECR for deployment.
$(aws ecr get-login --no-include-email --region us-east-2)
cd rokwire-building-blocks-api
docker build -f loggingservice/Dockerfile -t rokwire/logging-building-block .
docker tag rokwire/logging-building-block:latest 779619664536.dkr.ecr.us-east-2.amazonaws.com/rokwire/logging-building-block:latest
docker push 779619664536.dkr.ecr.us-east-2.amazonaws.com/rokwire/logging-building-block:latest
Let us use curl
command to post two sample events to the Events Building Block running at http://localhost:5000/logs
.
curl -d '{
"timestamp": "2019-06-01T10:15:23Z",
"uuid": "56fe224b-3600-4b66-ac8d-5d2906e19fc61",
"os": "ios",
"osVersion": "10.1.4",
"appVersion": "1.2",
"device": "iphone 7",
"deviceSettings": {
"description": "test device description",
"setting": "test setting"
},
"userAction": {
"description": "test description",
"type": "test type",
"name": "test name",
"mainFeature": "test main feature",
"subFeature": "test sub feature",
"customAttribute1": "test custom attribute 1",
"customAttribute2": "test custom attribute 2",
"customAttribute3": "test custom attribute 3",
"customAttribute4": "test custom attribute 4",
"customAttribute5": "test custom attribute 5"
}
}' -H "Content-Type: application/json" -X POST http://localhost:5000/logs
It will return back the post
status in json which includes the internal id as below:
{
"message": "logging information successfully posted",
"status": 200
}