diff --git a/src/monitoring/.gitlab-ci.yml b/src/monitoring/.gitlab-ci.yml index 1cfbde21f02a3217df88154ed6184f46800ef754..b1aa8e2edd4763f8ea3426dcad131bc1b496bfca 100644 --- a/src/monitoring/.gitlab-ci.yml +++ b/src/monitoring/.gitlab-ci.yml @@ -62,6 +62,7 @@ test monitoring run: - docker ps after_script: - docker stop "$IMAGE_NAME" + - docker network rm teraflowbridge rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' @@ -82,9 +83,15 @@ test monitoring pytest: stage: unit_test needs: - build monitoring + before_script: + - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi script: + - docker run -p 8086:8086 -e INFLUXDB_DB=$INFLUXDB_DATABASE -e INFLUXDB_ADMIN_USER=$INFLUXDB_USER -e INFLUXDB_ADMIN_PASSWORD=$INFLUXDB_PASSWORD -e INXLUXDB_HTTP_AUTH_ENABLED=True --network=teraflowbridge --name influxdb-tests influxdb:1.8 - docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/ - - docker run -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" $IMAGE_NAME_TEST:$IMAGE_TAG + - docker run -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --build-arg user=$INFLUXDB_USER --build-arg pass=$INFLUXDB_PASSWORD --build-arg db=$INFLUXDB_DATABASE --network=teraflowbridge $IMAGE_NAME_TEST:$IMAGE_TAG + after_script: + - docker stop influxdb-tests + - docker network rm teraflowbridge rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' diff --git a/src/monitoring/service/MonitoringServiceServicerImpl.py b/src/monitoring/service/MonitoringServiceServicerImpl.py index f1ee6d1cd55f99d2867bdf162b702368b0e6a4ef..0e85d6bb46bcd1b9e219de187db505591171d8b9 100644 --- a/src/monitoring/service/MonitoringServiceServicerImpl.py +++ b/src/monitoring/service/MonitoringServiceServicerImpl.py @@ -23,11 +23,12 @@ INFLUXDB_DB = os.environ.get("INFLUXDB_DATABASE") class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceServicer): def __init__(self): LOGGER.info('Init monitoringService') + # Init sqlite monitoring db self.sql_db = sqlite_tools.SQLite('monitoring.db') # Create influx_db client - self.influx_db = influx_tools.Influx("localhost","8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB) + self.influx_db = influx_tools.Influx("influxdb-tests","8086",INFLUXDB_USER,INFLUXDB_PASS,INFLUXDB_DB) # CreateKpi (CreateKpiRequest) returns (KpiId) {} def CreateKpi(self, request : monitoring_pb2.CreateKpiRequest, context) -> monitoring_pb2.KpiId : diff --git a/src/monitoring/tests/Dockerfile b/src/monitoring/tests/Dockerfile index 6d57e059ed92b5e9a2a1bc71b9531656954ad3fe..13524052d125ef23358b686871967996f6d911d4 100644 --- a/src/monitoring/tests/Dockerfile +++ b/src/monitoring/tests/Dockerfile @@ -31,6 +31,14 @@ RUN python3 -m pip install -r requirements.txt COPY monitoring/. monitoring COPY common/logger.py common +# define variables for the influxdb +ARG user +ARG pass +ARG db +ENV INFLUXDB_USER=$user +ENV INFLUXDB_PASSWORD=$pass +ENV INFLUXDB_DATABASE=$db + # set listen port ENV PORT=7070 EXPOSE 7070