From b8e0480a58c2559807616ebb71d1695a6eb77cd7 Mon Sep 17 00:00:00 2001 From: Waleed Akbar <wakbar@cttc.es> Date: Thu, 25 Jul 2024 14:58:21 +0000 Subject: [PATCH] cleanup for merge --- deploy/tfs.sh | 11 ++++++++ manifests/kpi_managerservice.yaml | 2 +- scripts/show_logs_kpi_value_api.sh | 27 +++++++++++++++++++ scripts/show_logs_kpi_value_writer.sh | 27 +++++++++++++++++++ src/common/tools/kafka/Variables.py | 3 ++- .../service/KpiValueWriter.py | 14 +++------- src/kpi_value_writer/service/__main__.py | 5 ++-- 7 files changed, 74 insertions(+), 15 deletions(-) create mode 100755 scripts/show_logs_kpi_value_api.sh create mode 100755 scripts/show_logs_kpi_value_writer.sh diff --git a/deploy/tfs.sh b/deploy/tfs.sh index 8565077c3..b8e1f8837 100755 --- a/deploy/tfs.sh +++ b/deploy/tfs.sh @@ -146,6 +146,17 @@ kubectl create secret generic crdb-data --namespace ${TFS_K8S_NAMESPACE} --type= --from-literal=CRDB_SSLMODE=require printf "\n" +echo "Create secret with CockroachDB data for KPI Management" +CRDB_SQL_PORT=$(kubectl --namespace ${CRDB_NAMESPACE} get service cockroachdb-public -o 'jsonpath={.spec.ports[?(@.name=="sql")].port}') +kubectl create secret generic crdb-kpi-data --namespace ${TFS_K8S_NAMESPACE} --type='Opaque' \ + --from-literal=CRDB_NAMESPACE=${CRDB_NAMESPACE} \ + --from-literal=CRDB_SQL_PORT=${CRDB_SQL_PORT} \ + --from-literal=CRDB_DATABASE=${CRDB_DATABASE} \ + --from-literal=CRDB_USERNAME=${CRDB_USERNAME} \ + --from-literal=CRDB_PASSWORD=${CRDB_PASSWORD} \ + --from-literal=CRDB_SSLMODE=require +printf "\n" + echo "Create secret with NATS data" NATS_CLIENT_PORT=$(kubectl --namespace ${NATS_NAMESPACE} get service ${NATS_NAMESPACE} -o 'jsonpath={.spec.ports[?(@.name=="client")].port}') if [ -z "$NATS_CLIENT_PORT" ]; then diff --git a/manifests/kpi_managerservice.yaml b/manifests/kpi_managerservice.yaml index 3e106fd92..984d783a9 100644 --- a/manifests/kpi_managerservice.yaml +++ b/manifests/kpi_managerservice.yaml @@ -41,7 +41,7 @@ spec: value: "INFO" envFrom: - secretRef: - name: crdb-data + name: crdb-kpi-data readinessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:30010"] diff --git a/scripts/show_logs_kpi_value_api.sh b/scripts/show_logs_kpi_value_api.sh new file mode 100755 index 000000000..041ad7f1f --- /dev/null +++ b/scripts/show_logs_kpi_value_api.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# 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. + +######################################################################################################################## +# Define your deployment settings here +######################################################################################################################## + +# If not already set, set the name of the Kubernetes namespace to deploy to. +export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"} + +######################################################################################################################## +# Automated steps start here +######################################################################################################################## + +kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/kpi-value-apiservice -c server diff --git a/scripts/show_logs_kpi_value_writer.sh b/scripts/show_logs_kpi_value_writer.sh new file mode 100755 index 000000000..d62f3ea0a --- /dev/null +++ b/scripts/show_logs_kpi_value_writer.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# 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. + +######################################################################################################################## +# Define your deployment settings here +######################################################################################################################## + +# If not already set, set the name of the Kubernetes namespace to deploy to. +export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"} + +######################################################################################################################## +# Automated steps start here +######################################################################################################################## + +kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/kpi-value-writerservice -c server diff --git a/src/common/tools/kafka/Variables.py b/src/common/tools/kafka/Variables.py index e01b33896..bdb6708f3 100644 --- a/src/common/tools/kafka/Variables.py +++ b/src/common/tools/kafka/Variables.py @@ -21,7 +21,8 @@ from confluent_kafka.admin import AdminClient, NewTopic LOGGER = logging.getLogger(__name__) class KafkaConfig(Enum): - SERVER_IP = "127.0.0.1:9092" + # SERVER_IP = "127.0.0.1:9092" + SERVER_IP = "kafka-service:9092" ADMIN_CLIENT = AdminClient({'bootstrap.servers': SERVER_IP}) class KafkaTopic(Enum): diff --git a/src/kpi_value_writer/service/KpiValueWriter.py b/src/kpi_value_writer/service/KpiValueWriter.py index aa0f2cf79..a4b10ed63 100644 --- a/src/kpi_value_writer/service/KpiValueWriter.py +++ b/src/kpi_value_writer/service/KpiValueWriter.py @@ -67,24 +67,17 @@ class KpiValueWriter: kpi_value.ParseFromString(raw_kpi.value()) LOGGER.info("Received KPI : {:}".format(kpi_value)) print("Received KPI : {:}".format(kpi_value)) - KpiValueWriter.get_kpi_descriptor(kpi_value.kpi_id.kpi_id.uuid, kpi_manager_client) - # -------- Testing section --------------- - # test_kpi_descriptor_obj = create_kpi_descriptor_request() - # metric_writer_to_prom.create_and_expose_cooked_kpi( - # test_kpi_descriptor_obj, kpi_value - # ) - # -------- Testing section --------------- - + KpiValueWriter.get_kpi_descriptor(kpi_value, kpi_manager_client) except Exception as e: print("Error detail: {:}".format(e)) continue @staticmethod - def get_kpi_descriptor(kpi_value_uuid: str, kpi_manager_client ): + def get_kpi_descriptor(kpi_value: str, kpi_manager_client ): print("--- START -----") kpi_id = KpiId() - kpi_id.kpi_id.uuid = kpi_value_uuid + kpi_id.kpi_id.uuid = kpi_value.kpi_id.kpi_id.uuid print("KpiId generated: {:}".format(kpi_id)) # print("Kpi manger client created: {:}".format(kpi_manager_client)) @@ -96,6 +89,7 @@ class KpiValueWriter: if isinstance (kpi_descriptor_object, KpiDescriptor): LOGGER.info("Extracted KpiDescriptor: {:}".format(kpi_descriptor_object)) print("Extracted KpiDescriptor: {:}".format(kpi_descriptor_object)) + MetricWriterToPrometheus.create_and_expose_cooked_kpi(kpi_descriptor_object, kpi_value) else: LOGGER.info("Error in extracting KpiDescriptor {:}".format(kpi_descriptor_object)) print("Error in extracting KpiDescriptor {:}".format(kpi_descriptor_object)) diff --git a/src/kpi_value_writer/service/__main__.py b/src/kpi_value_writer/service/__main__.py index 028585575..aa67540fb 100644 --- a/src/kpi_value_writer/service/__main__.py +++ b/src/kpi_value_writer/service/__main__.py @@ -13,9 +13,8 @@ # limitations under the License. import logging, signal, sys, threading -from prometheus_client import start_http_server -from .KpiValueWriter import KpiValueWriter -from common.Settings import get_log_level, get_metrics_port +from kpi_value_writer.service.KpiValueWriter import KpiValueWriter +from common.Settings import get_log_level terminate = threading.Event() LOGGER = None -- GitLab