Commit 58fd2c5a authored by Waleed Akbar's avatar Waleed Akbar
Browse files

changs to make KPI manager inline with TFS formats

parent d0c3b728
Loading
Loading
Loading
Loading
+99 −0
Original line number Original line Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kpi_managerservice
spec:
  selector:
    matchLabels:
      app: kpi_managerservice
  #replicas: 1
  template:
    metadata:
      annotations:
        config.linkerd.io/skip-outbound-ports: "4222"
      labels:
        app: kpi_managerservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/context:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 7071
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          envFrom:
            - secretRef:
                name: crdb-data
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:7071"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:7071"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: kpi_managerservice
  labels:
    app: kpi_managerservice
spec:
  type: ClusterIP
  selector:
    app: kpi_managerservice
  ports:
    - name: grpc
      protocol: TCP
      port: 7071
      targetPort: 7071
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: kpi_managerservice-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: kpi_managerservice
  minReplicas: 1
  maxReplicas: 20
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80
  #behavior:
  #  scaleDown:
  #    stabilizationWindowSeconds: 30
+1 −1
Original line number Original line Diff line number Diff line
@@ -24,5 +24,5 @@ cd $PROJECTDIR/src
# python3 kpi_manager/tests/test_unitary.py
# python3 kpi_manager/tests/test_unitary.py


RCFILE=$PROJECTDIR/coverage/.coveragerc
RCFILE=$PROJECTDIR/coverage/.coveragerc
python3 -m pytest --log-level=INFO --log-cli-level=INFO --verbose \
python3 -m pytest --log-level=DEBUG --log-cli-level=DEBUG --verbose \
    kpi_manager/tests/test_kpi_manager.py
    kpi_manager/tests/test_kpi_manager.py
 No newline at end of file
+133 −0
Original line number Original line Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build, tag, and push the Docker image to the GitLab Docker registry
build kpi_manager:
  variables:
    IMAGE_NAME: 'kpi_manager' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: build
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  after_script:
    - docker images --filter="dangling=true" --quiet | xargs -r docker rmi
  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"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml

# Apply unit test to the component
unit_test context:
  variables:
    IMAGE_NAME: 'kpi_manager' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build context
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
    - if docker container ls | grep crdb; then docker rm -f crdb; else echo "CockroachDB container is not in the system"; fi
    - if docker volume ls | grep crdb; then docker volume rm -f crdb; else echo "CockroachDB volume is not in the system"; fi
    - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME container is not in the system"; fi
    - docker container prune -f
  script:
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker pull "cockroachdb/cockroach:latest-v22.2"
    - docker volume create crdb
    - >
      docker run --name crdb -d --network=teraflowbridge -p 26257:26257 -p 8080:8080
      --env COCKROACH_DATABASE=tfs_test --env COCKROACH_USER=tfs --env COCKROACH_PASSWORD=tfs123
      --volume "crdb:/cockroach/cockroach-data"
      cockroachdb/cockroach:latest-v22.2 start-single-node
    - echo "Waiting for initialization..."
    - while ! docker logs crdb 2>&1 | grep -q 'finished creating default user \"tfs\"'; do sleep 1; done
    - docker logs crdb
    - docker ps -a
    - CRDB_ADDRESS=$(docker inspect crdb --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $CRDB_ADDRESS
    - NATS_ADDRESS=$(docker inspect nats --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $NATS_ADDRESS
    - >
      docker run --name $IMAGE_NAME -d -p 1010:1010
      --env "CRDB_URI=cockroachdb://tfs:tfs123@${CRDB_ADDRESS}:26257/tfs_test?sslmode=require"
      --volume "$PWD/src/$IMAGE_NAME/tests:/opt/results"
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
    - docker ps -a
    - sleep 5
    - docker logs $IMAGE_NAME
    - >
      docker exec -i $IMAGE_NAME bash -c
      "coverage run -m pytest --log-level=INFO --verbose --junitxml=/opt/results/${IMAGE_NAME}_report.xml $IMAGE_NAME/tests/test_*.py"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    - docker volume rm -f crdb
    - docker network rm teraflowbridge
    - docker volume prune --force
    - docker image prune --force
  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"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - src/$IMAGE_NAME/tests/Dockerfile
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml
  artifacts:
      when: always
      reports:
        junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml

## Deployment of the service in Kubernetes Cluster
#deploy context:
#  variables:
#    IMAGE_NAME: 'context' # name of the microservice
#    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
#  stage: deploy
#  needs:
#    - unit test context
#    # - integ_test execute
#  script:
#    - 'sed -i "s/$IMAGE_NAME:.*/$IMAGE_NAME:$IMAGE_TAG/" manifests/${IMAGE_NAME}service.yaml'
#    - kubectl version
#    - kubectl get all
#    - kubectl apply -f "manifests/${IMAGE_NAME}service.yaml"
#    - kubectl get all
#  # environment:
#  #   name: test
#  #   url: https://example.com
#  #   kubernetes:
#  #     namespace: test
#  rules:
#    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
#      when: manual    
#    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
#      when: manual
+0 −2
Original line number Original line Diff line number Diff line
@@ -62,8 +62,6 @@ RUN python3 -m pip install -r requirements.txt


# Add component files into working directory
# Add component files into working directory
WORKDIR /var/teraflow
WORKDIR /var/teraflow
COPY src/context/. context/
COPY src/device/. device/
COPY src/kpi_manager/. kpi_manager/
COPY src/kpi_manager/. kpi_manager/


# Start the service
# Start the service
+1 −1
Original line number Original line Diff line number Diff line
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
Loading