Integrate grafana-k8s and prometheus-k8s 73/13573/9
authorPatricia Reinoso <patricia.reinoso@canonical.com>
Fri, 7 Jul 2023 13:01:27 +0000 (13:01 +0000)
committerbeierlm <mark.beierl@canonical.com>
Tue, 8 Aug 2023 12:48:38 +0000 (14:48 +0200)
Update osm bundle
Update osm bundle HA
Update charmed installer

Change-Id: I34806659cd8fa44e4d9b4a1eea33e362cc38ae22
Signed-off-by: Patricia Reinoso <patricia.reinoso@canonical.com>
installers/charm/bundles/osm-ha/bundle.yaml
installers/charm/bundles/osm/bundle.yaml
installers/charmed_install.sh

index a4e84d3..6ae48e1 100644 (file)
@@ -124,19 +124,15 @@ applications:
     channel: latest/stable
     scale: 3
   prometheus:
-    charm: osm-prometheus
-    channel: latest/stable
+    charm: prometheus-k8s
+    channel: latest/edge
     scale: 1
-    series: kubernetes
     storage:
-      data: 50M
-    options:
-      default-target: "mon:8000"
+      database: 50M
   grafana:
-    charm: osm-grafana
-    channel: latest/stable
+    charm: grafana-k8s
+    channel: latest/edge
     scale: 3
-    series: kubernetes
   keystone:
     charm: osm-keystone
     channel: latest/beta
@@ -144,8 +140,6 @@ applications:
     resources:
       keystone-image: opensourcemano/keystone:testing-daily
 relations:
-  - - grafana:prometheus
-    - prometheus:prometheus
   - - kafka:zookeeper
     - zookeeper:zookeeper
   - - keystone:db
@@ -178,12 +172,10 @@ relations:
     - kafka:kafka
   - - nbi:ingress
     - ingress:ingress
-  - - nbi:prometheus
-    - prometheus:prometheus
   - - nbi:keystone
     - keystone:keystone
-  - - mon:prometheus
-    - prometheus:prometheus
+  - - mon:metrics-endpoint
+    - prometheus:metrics-endpoint
   - - ng-ui:nbi
     - nbi:nbi
   - - ng-ui:ingress
@@ -192,5 +184,3 @@ relations:
     - keystone:keystone
   - - mariadb:mysql
     - pol:mysql
-  - - grafana:db
-    - mariadb:mysql
index b2db446..9f6023c 100644 (file)
@@ -123,19 +123,15 @@ applications:
     channel: latest/stable
     scale: 1
   prometheus:
-    charm: osm-prometheus
-    channel: latest/stable
+    charm: prometheus-k8s
+    channel: latest/edge
     scale: 1
-    series: kubernetes
     storage:
-      data: 50M
-    options:
-      default-target: "mon:8000"
+      database: 50M
   grafana:
-    charm: osm-grafana
-    channel: latest/stable
+    charm: grafana-k8s
+    channel: latest/edge
     scale: 1
-    series: kubernetes
   keystone:
     charm: osm-keystone
     channel: latest/beta
@@ -143,8 +139,6 @@ applications:
     resources:
       keystone-image: opensourcemano/keystone:testing-daily
 relations:
-  - - grafana:prometheus
-    - prometheus:prometheus
   - - kafka:zookeeper
     - zookeeper:zookeeper
   - - keystone:db
@@ -177,12 +171,10 @@ relations:
     - kafka:kafka
   - - nbi:ingress
     - ingress:ingress
-  - - nbi:prometheus
-    - prometheus:prometheus
   - - nbi:keystone
     - keystone:keystone
-  - - mon:prometheus
-    - prometheus:prometheus
+  - - mon:metrics-endpoint
+    - prometheus:metrics-endpoint
   - - ng-ui:nbi
     - nbi:nbi
   - - ng-ui:ingress
@@ -191,5 +183,4 @@ relations:
     - keystone:keystone
   - - mariadb:mysql
     - pol:mysql
-  - - grafana:db
-    - mariadb:mysql
+
index a9dfdf1..975cbbd 100755 (executable)
@@ -278,7 +278,17 @@ function deploy_charmed_osm(){
         hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
         API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
     fi
-    # Configure VCA Integrator
+
+    configure_vca_integrator
+    expose_osm_services
+    echo "Waiting for deployment to finish..."
+    check_osm_deployed_before_config
+    config_grafana_and_prometheus
+    check_osm_deployed_after_config
+    echo "OSM with charms deployed"
+}
+
+function configure_vca_integrator(){
     if [ ! -v INSTALL_NOLXD ]; then
         juju config vca \
           k8s-cloud=microk8s \
@@ -293,22 +303,61 @@ function deploy_charmed_osm(){
           accounts="`cat ~/.local/share/juju/accounts.yaml`" \
           public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
     fi
-    # Expose OSM services
+}
+
+function expose_osm_services(){
     juju config -m $MODEL_NAME nbi external-hostname=nbi.${API_SERVER}.nip.io
     juju config -m $MODEL_NAME ng-ui external-hostname=ui.${API_SERVER}.nip.io
-    juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
-    juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
+    juju config -m $MODEL_NAME grafana web_external_url=https://grafana.${API_SERVER}.nip.io
+}
 
-    echo "Waiting for deployment to finish..."
-    check_osm_deployed
+function config_grafana_and_prometheus() {
+    echo "Setting Grafana and Prometheus configuration"
     grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1`
-    grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"`
-    juju config -m $MODEL_NAME mon grafana-password=$grafana_admin_password
-    check_osm_deployed
-    echo "OSM with charms deployed"
+    grafana_admin_password=`juju run-action -m $MODEL_NAME $grafana_leader get-admin-password --wait | grep "admin-password" | cut -d ":" -f 2`
+    juju config -m $MODEL_NAME mon grafana-password="$grafana_admin_password"
+    juju config -m $MODEL_NAME mon grafana-user=admin
+    juju config -m $MODEL_NAME mon grafana-url=http://grafana:3000
+    prometheus_url="http://prometheus:9090"
+    juju config -m $MODEL_NAME mon prometheus-url=$prometheus_url
+    juju config -m $MODEL_NAME nbi prometheus-url=$prometheus_url
+    mon_leader=`juju status -m $MODEL_NAME mon | grep "*" | cut -d "*" -f 1`
+    juju run-action --m $MODEL_NAME $mon_leader create-datasource name=osm_prometheus url=$prometheus_url --wait
+}
+
+function check_osm_deployed_before_config() {
+    TIME_TO_WAIT=600
+    start_time="$(date -u +%s)"
+    total_active_services=13
+    [ -n "$INSTALL_PLA" ] && total_active_services=$((total_active_services + 1))
+    previous_count=0
+    while true
+    do
+        juju_status=$(juju status --format json -m $MODEL_NAME)
+        active_service_count=$(echo $juju_status | jq '.applications[]."application-status".current'| grep active | wc -l)
+        echo "$active_service_count / $total_active_services services active"
+        if [ $active_service_count -eq $total_active_services ]; then
+            mon_is_blocked=$(echo $juju_status | jq '.applications["mon"].units[]."workload-status".current' | grep blocked | wc -l)
+            nbi_is_blocked=$(echo $juju_status | jq '.applications["nbi"].units[]."workload-status".current' | grep blocked | wc -l)
+            if [ $mon_is_blocked -a $nbi_is_blocked ]; then
+                echo "MON and NBI are blocked"
+                break
+            fi
+        fi
+        if [ $active_service_count -ne $previous_count ]; then
+            previous_count=$active_service_count
+            start_time="$(date -u +%s)"
+        fi
+        now="$(date -u +%s)"
+        if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
+            echo "Timed out waiting for OSM services to become ready"
+            FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
+        fi
+        sleep 10
+    done
 }
 
-function check_osm_deployed() {
+function check_osm_deployed_after_config() {
     TIME_TO_WAIT=600
     start_time="$(date -u +%s)"
     total_service_count=15
@@ -335,8 +384,6 @@ function check_osm_deployed() {
 }
 
 function generate_password_overlay() {
-    # prometheus
-    web_config_password=`openssl rand -hex 16`
     # keystone
     keystone_db_password=`openssl rand -hex 16`
     keystone_admin_password=`openssl rand -hex 16`
@@ -346,9 +393,6 @@ function generate_password_overlay() {
     mariadb_root_password=`openssl rand -hex 16`
     cat << EOF > /tmp/password-overlay.yaml
 applications:
-  prometheus:
-    options:
-      web_config_password: $web_config_password
   keystone:
     options:
       keystone-db-password: $keystone_db_password