Skip to content
Snippets Groups Projects
Commit 98f5085e authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

Implementing fixes to use the code with Kubernetes.

parent b5dbea48
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -53,6 +53,7 @@ coverage.xml ...@@ -53,6 +53,7 @@ coverage.xml
.pytest_cache/ .pytest_cache/
.benchmarks/ .benchmarks/
cover/ cover/
*_report.xml
# Translations # Translations
*.mo *.mo
...@@ -158,4 +159,3 @@ cython_debug/ ...@@ -158,4 +159,3 @@ cython_debug/
# TeraFlowSDN-generated files # TeraFlowSDN-generated files
tfs_runtime_env_vars.sh tfs_runtime_env_vars.sh
*_report.xml
...@@ -33,6 +33,9 @@ spec: ...@@ -33,6 +33,9 @@ spec:
image: influxdb:1.8 image: influxdb:1.8
ports: ports:
- containerPort: 8086 - containerPort: 8086
env:
- name: LOG_LEVEL
value: "DEBUG"
envFrom: envFrom:
- secretRef: - secretRef:
name: influxdb-secrets name: influxdb-secrets
...@@ -54,6 +57,9 @@ spec: ...@@ -54,6 +57,9 @@ spec:
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 7070 - containerPort: 7070
env:
- name: LOG_LEVEL
value: "DEBUG"
envFrom: envFrom:
- secretRef: - secretRef:
name: monitoring-secrets name: monitoring-secrets
......
...@@ -40,7 +40,7 @@ spec: ...@@ -40,7 +40,7 @@ spec:
- name: LOG_LEVEL - name: LOG_LEVEL
value: "DEBUG" value: "DEBUG"
- name: WEBUISERVICE_SERVICE_BASEURL_HTTP - name: WEBUISERVICE_SERVICE_BASEURL_HTTP
value: "/webui" value: "/"
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /healthz/ready path: /healthz/ready
......
# Set the URL of your local Docker registry where the images will be uploaded to. # Set the URL of your local Docker registry where the images will be uploaded to.
export TFS_REGISTRY_IMAGE="http://localhost:32000/tfs/" export TFS_REGISTRY_IMAGE=""
# Set the list of components, separated by comas, you want to build images for, and deploy. # Set the list of components, separated by comas, you want to build images for, and deploy.
# Supported components are: # Supported components are:
...@@ -16,7 +16,7 @@ export TFS_IMAGE_TAG="dev" ...@@ -16,7 +16,7 @@ export TFS_IMAGE_TAG="dev"
export TFS_K8S_NAMESPACE="tfs" export TFS_K8S_NAMESPACE="tfs"
# Set additional manifest files to be applied after the deployment # Set additional manifest files to be applied after the deployment
export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" # export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml"
# Set the neew Grafana admin password # Set the neew Grafana admin password
export TFS_GRAFANA_PASSWORD="admin123+" export TFS_GRAFANA_PASSWORD="admin123+"
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
# this script opens the dashboard # this script opens the dashboard
K8S_NAMESPACE=${K8S_NAMESPACE:-'tf-dev'} TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-'tf-dev'}
GRAFANA_IP=$(kubectl get service/webuiservice -n ${K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}') GRAFANA_IP=$(kubectl get service/webuiservice -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}')
GRAFANA_PORT=$(kubectl get service webuiservice-public --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}') GRAFANA_PORT=3000 #$(kubectl get service webuiservice --namespace $TFS_K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}')
URL=http://${GRAFANA_IP}:${GRAFANA_PORT} URL=http://${GRAFANA_IP}:${GRAFANA_PORT}
echo Opening Dashboard on URL ${URL} echo Opening Dashboard on URL ${URL}
......
...@@ -14,24 +14,79 @@ ...@@ -14,24 +14,79 @@
# this script opens the webui # this script opens the webui
K8S_NAMESPACE=${K8S_NAMESPACE:-'tf-dev'} # If not already set, set the neew Grafana admin password
export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-'tfs'}
WEBUI_SERVICE_NAME="webuiservice-public" export TFS_GRAFANA_PASSWORD=${TFS_GRAFANA_PASSWORD:-"admin123+"}
WEBUI_PROTO=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.ports[0].name}'`
WEBUI_IP=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}'` WEBUI_SERVICE_NAME="webuiservice"
# WEBUI_PROTO=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.ports[0].name}'`
WEBUI_IP=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}'`
# WEBUI_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==8004)].nodePort}') # WEBUI_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==8004)].nodePort}')
WEBUI_PORT=8004 WEBUI_PORT=8004
# GRAFANA_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}') # GRAFANA_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}')
GRAFANA_PORT=3000 GRAFANA_PORT=3000
echo "Configuring WebUI DataStores and Dashboards..."
sleep 3
INFLUXDB_HOST="monitoringservice"
INFLUXDB_PORT=$(kubectl --namespace $TFS_K8S_NAMESPACE get service/monitoringservice -o jsonpath='{.spec.ports[?(@.name=="influxdb")].port}')
INFLUXDB_URL="http://${INFLUXDB_HOST}:${INFLUXDB_PORT}"
INFLUXDB_USER=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_ADMIN_USER}' | base64 --decode)
INFLUXDB_PASSWORD=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_ADMIN_PASSWORD}' | base64 --decode)
INFLUXDB_DATABASE=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_DB}' | base64 --decode)
# Exposed through the ingress controller "tfs-ingress"
# GRAFANA_HOSTNAME="127.0.0.1"
# GRAFANA_PORT="80"
# GRAFANA_BASEURL="/grafana"
# Default Grafana credentials
GRAFANA_USERNAME="admin"
GRAFANA_PASSWORD="admin"
# Default Grafana API URL
GRAFANA_URL_DEFAULT=http://${GRAFANA_USERNAME}:${GRAFANA_PASSWORD}@${WEBUI_IP}:${GRAFANA_PORT} #"http://${GRAFANA_USERNAME}:${GRAFANA_PASSWORD}@${GRAFANA_HOSTNAME}:${GRAFANA_PORT}${GRAFANA_BASEURL}"
# Updated Grafana API URL
GRAFANA_URL_UPDATED=http://${GRAFANA_USERNAME}:${TFS_GRAFANA_PASSWORD}@${WEBUI_IP}:${GRAFANA_PORT} #"http://${GRAFANA_USERNAME}:${TFS_GRAFANA_PASSWORD}@${GRAFANA_HOSTNAME}:${GRAFANA_PORT}${GRAFANA_BASEURL}"
echo "Connecting to grafana at URL: ${GRAFANA_URL_DEFAULT}..."
# Configure Grafana Admin Password
# Ref: https://grafana.com/docs/grafana/latest/http_api/user/#change-password
curl -X PUT -H "Content-Type: application/json" -d '{
"oldPassword": "'${GRAFANA_PASSWORD}'",
"newPassword": "'${TFS_GRAFANA_PASSWORD}'",
"confirmNew" : "'${TFS_GRAFANA_PASSWORD}'"
}' ${GRAFANA_URL_DEFAULT}/api/user/password
echo
# Create InfluxDB DataSource
# Ref: https://grafana.com/docs/grafana/latest/http_api/data_source/
curl -X POST -H "Content-Type: application/json" -d '{
"type" : "influxdb",
"name" : "InfluxDB",
"url" : "'"$INFLUXDB_URL"'",
"access" : "proxy",
"basicAuth": false,
"user" : "'"$INFLUXDB_USER"'",
"password" : "'"$INFLUXDB_PASSWORD"'",
"isDefault": true,
"database" : "'"$INFLUXDB_DATABASE"'"
}' ${GRAFANA_URL_UPDATED}/api/datasources
echo
# Create Monitoring Dashboard
# Ref: https://grafana.com/docs/grafana/latest/http_api/dashboard/
curl -X POST -H "Content-Type: application/json" \
-d '@src/webui/grafana_dashboard.json' \
${GRAFANA_URL_UPDATED}/api/dashboards/db
echo
DASHBOARD_URL="${GRAFANA_URL_UPDATED}/api/dashboards/uid/tf-l3-monit"
DASHBOARD_ID=$(curl -s "${DASHBOARD_URL}" | jq '.dashboard.id')
curl -X POST ${GRAFANA_URL_UPDATED}/api/user/stars/dashboard/${DASHBOARD_ID}
# Open WebUI # Open WebUI
URL=${WEBUI_PROTO}://${WEBUI_IP}:${WEBUI_PORT} URL=http://${WEBUI_IP}:${WEBUI_PORT}
echo Opening web UI on URL ${URL} echo Opening web UI on URL ${URL}
# curl -kL ${URL} # curl -kL ${URL}
python3 -m webbrowser ${URL} python3 -m webbrowser ${URL}
# Open Dashboard # Open Dashboard
URL=${WEBUI_PROTO}://${WEBUI_IP}:${GRAFANA_PORT} URL=http://${WEBUI_IP}:${GRAFANA_PORT}
echo Opening Dashboard on URL ${URL} echo Opening Dashboard on URL ${URL}
# curl -kL ${URL} # curl -kL ${URL}
python3 -m webbrowser ${URL} python3 -m webbrowser ${URL}
...@@ -91,8 +91,8 @@ class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceService ...@@ -91,8 +91,8 @@ class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceService
monitor_device_request.kpi_descriptor.CopyFrom(kpiDescriptor) monitor_device_request.kpi_descriptor.CopyFrom(kpiDescriptor)
monitor_device_request.kpi_id.kpi_id.uuid = request.kpi_id.kpi_id.uuid monitor_device_request.kpi_id.kpi_id.uuid = request.kpi_id.kpi_id.uuid
monitor_device_request.sampling_duration_s = request.sampling_duration_s monitor_device_request.sampling_duration_s = request.monitoring_window_s
monitor_device_request.sampling_interval_s = request.sampling_interval_s monitor_device_request.sampling_interval_s = request.sampling_rate_s
device_client = DeviceClient() device_client = DeviceClient()
device_client.MonitorDeviceKpi(monitor_device_request) device_client.MonitorDeviceKpi(monitor_device_request)
......
...@@ -45,8 +45,8 @@ def start_monitoring(): ...@@ -45,8 +45,8 @@ def start_monitoring():
# Create Monitor Kpi Requests # Create Monitor Kpi Requests
monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() monitor_kpi_request = monitoring_pb2.MonitorKpiRequest()
monitor_kpi_request.kpi_id.CopyFrom(kpi_id) monitor_kpi_request.kpi_id.CopyFrom(kpi_id)
monitor_kpi_request.sampling_duration_s = 86400 monitor_kpi_request.monitoring_window_s = 86400
monitor_kpi_request.sampling_interval_s = 30 monitor_kpi_request.sampling_rate_s = 30
events_collector._monitoring_client.MonitorKpi(monitor_kpi_request) events_collector._monitoring_client.MonitorKpi(monitor_kpi_request)
else: else:
# Terminate is set, looping terminates # Terminate is set, looping terminates
......
...@@ -34,11 +34,11 @@ def create_kpi_request(): ...@@ -34,11 +34,11 @@ def create_kpi_request():
_create_kpi_request.endpoint_id.endpoint_uuid.uuid = 'END1' # pylint: disable=maybe-no-member _create_kpi_request.endpoint_id.endpoint_uuid.uuid = 'END1' # pylint: disable=maybe-no-member
return _create_kpi_request return _create_kpi_request
def monitor_kpi_request(kpi_uuid, sampling_duration_s, sampling_interval_s): def monitor_kpi_request(kpi_uuid, monitoring_window_s, sampling_rate_s):
_monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() _monitor_kpi_request = monitoring_pb2.MonitorKpiRequest()
_monitor_kpi_request.kpi_id.kpi_id.uuid = kpi_uuid # pylint: disable=maybe-no-member _monitor_kpi_request.kpi_id.kpi_id.uuid = kpi_uuid # pylint: disable=maybe-no-member
_monitor_kpi_request.sampling_duration_s = sampling_duration_s _monitor_kpi_request.monitoring_window_s = monitoring_window_s
_monitor_kpi_request.sampling_interval_s = sampling_interval_s _monitor_kpi_request.sampling_rate_s = sampling_rate_s
return _monitor_kpi_request return _monitor_kpi_request
def include_kpi_request(): def include_kpi_request():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment