# CQA Test Application ## Requirements - python3.x - flask - flask_restful ## How to Run with VM 1. Install CQA Test Application - git clone cqa-test-app code - install requirements library : $pip install -r requirements.txt 2. Run CQA Test App Server (server endpoint : http://{VM server ip}:10345) - Run command : $python run_cqa_test_app.py - Run background : $nohup python -u run_cqa_test_app.py & - Note) To use 'lb_least_conn' app, the 'root' privilege is needed - ex: $sudo nohup python -u run_cqa_test_app.py 3. Send RestAPI to server with 'cmd' - Send rest-api to server with 'cmd' argument : - ex : $curl -d '{"cmd": "ls -ll"}' -X POST http://127.0.0.1:10345/run_cmd -H 'Content-Type: application/json' ## How to Run with k8s 1. Install CQA Test Application - git clone cqa-test-app code - install requirements library : $pip install -r requirements.txt 2. Deploy 'cqa-test-app' to k8s - Customize below parts in the ./cqa-test-app/deployments/cqa-test-app-k8s-vbs.yaml file 1) Deployments.spec.replicas - You can set the number of pods for the 'cqa-test-app' application 2) Deployments.spec.template.spec.affinity - Please check 'affinity' configuration which describes a AZ where your pods should be deployed. - Below example deploys your pods to 3 AZs evenly. ```yaml affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: vks.linecorp.com/availability-zone operator: In values: - tokyo-1 - tokyo-2 - tokyo-3 3) Ingress.spec.tls.hosts - Please customize a hostname for the Ingress ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: vqa-test-node-ingress spec: ingressClassName: fabriclb tls: - hosts: - vqa-test-node.vqa-fabriclb.line-apps.com 4) Run command : $kubectl apply -f ./cqa-test-app/deployments/cqa-test-app-k8s-vbs.yaml -n 3. Send RestAPI to server with 'cmd' - Send rest-api to server with 'cmd' argument : - ex : $curl -d '{"cmd": "ls -ll"}' -X POST -H 'Content-Type: application/json' ## How to Monitor with Prometheus To monitor the CQA Test Application with Prometheus, follow these steps: 1. **Set up Environment Variables:** Create a `.env` file in the root directory with the following content for external labels: ```env # The name of the project for which these metrics are being collected. FLAVA_PROJECT_NAME= # The environment in which the application is running (e.g. stage, dev, prod). FLAVA_ENV= # A unique id for the server instance. SERVER_ID= # The availability zone where the server is located. (e.g. kks-az1, kks-az2, kks-az3) FLAVA_AZ= ``` e.g. ```env FLAVA_PROJECT_NAME=flava-qa FLAVA_ENV=prod SERVER_ID=a4111ba5-53b8-454b-9903-77183d49ccc1 FLAVA_AZ=kks-az3 2. **Set File Permissions:** Ensure that the prometheus.yml file has the correct permissions so that it can be accessed by the Prometheus container. Run the following command: ```bash chmod 644 ./config/prometheus.yml 3. **Prometheus Configuration:** Ensure that the `prometheus.yml` file is correctly configured to scrape metrics from the application and use the external labels defined in the `.env` file. (Here you don't have to do anything.) ```yaml global: scrape_interval: 15s external_labels: flava_project_name: ${FLAVA_PROJECT_NAME} flava_product: server flava_resource_type: server-instance flava_env: ${FLAVA_ENV} serverId: ${SERVER_ID} flava_az: ${FLAVA_AZ} flava_region: kks remote_write: - url: http://api.imon.linecorp.com/ingest/metric/prometheus/write scrape_configs: - job_name: cqa_test_app static_configs: - targets: - cqa_test_app:80 4. **Run with Docker Compose:** Use Docker Compose to build and run the services: ```bash docker-compose up --build ``` To run the services in the background, add the -d option: ```bash docker-compose up -d --build 5. **Access the Services:** * Prometheus can be accessed at http://127.0.0.1:9090. By following these steps, you can effectively monitor the CQA Test Application using Prometheus.