]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Handle errors for /api/osd/settings 55704/head
authorAfreen <afreen23.git@gmail.com>
Tue, 13 Feb 2024 10:26:09 +0000 (15:56 +0530)
committerAfreen <afreen23.git@gmail.com>
Thu, 22 Feb 2024 09:02:46 +0000 (14:32 +0530)
Fixes https://tracker.ceph.com/issues/62089

issue:
=====
/api/osd/settings returns "TypeError: string indices must be
integers" sometimes.
The result is coming from `osd dump` command which instead of returning
an object returns an error message which then displays error on
dashboard.

fix:
====
Added a try-catch block to handle error and updated frontend code to
handle those

Signed-off-by: Afreen <afreen23.git@gmail.com>
(cherry picked from commit 518bff9c7ed6f6756aff8aa8013c48a5bfdd7b32)

src/pybind/mgr/dashboard/controllers/osd.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard-pie/dashboard-pie.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html

index f6f8ce1f58a8a651f48c2b57a07afa3e0e628d6b..c9d14177200053db383601aed7277a69b5d8043e 100644 (file)
@@ -168,11 +168,18 @@ class Osd(RESTController):
     @RESTController.Collection('GET', version=APIVersion.EXPERIMENTAL)
     @ReadPermission
     def settings(self):
-        result = CephService.send_command('mon', 'osd dump')
-        return {
-            'nearfull_ratio': result['nearfull_ratio'],
-            'full_ratio': result['full_ratio']
+        data = {
+            'nearfull_ratio': -1,
+            'full_ratio': -1
         }
+        try:
+            result = CephService.send_command('mon', 'osd dump')
+            data['nearfull_ratio'] = result['nearfull_ratio']
+            data['full_ratio'] = result['full_ratio']
+        except TypeError:
+            logger.error(
+                'Error setting nearfull_ratio and full_ratio:', exc_info=True)
+        return data
 
     def _get_operational_status(self, osd_id: int, removing_osd_ids: Optional[List[int]]):
         if removing_osd_ids is None:
index 4680fb850a144d0fbc7344384bff751b747dcc23..b0c253c33e9d8c7c436c827ff5eb7a35668b02e4 100644 (file)
@@ -59,7 +59,7 @@ export class DashboardPieComponent implements OnChanges, OnInit {
   constructor(private cssHelper: CssHelper, private dimlessBinary: DimlessBinaryPipe) {
     this.chartConfig = {
       chartType: 'doughnut',
-      labels: ['', '', ''],
+      labels: [],
       dataset: [
         {
           label: null,
@@ -97,19 +97,20 @@ export class DashboardPieComponent implements OnChanges, OnInit {
                   fillStyle: chart.data.datasets[1].backgroundColor[0],
                   strokeStyle: chart.data.datasets[1].backgroundColor[0]
                 };
-                labels[1] = {
-                  text: $localize`Warning: ${chart.data.datasets[0].data[0]}%`,
-                  fillStyle: chart.data.datasets[0].backgroundColor[1],
-                  strokeStyle: chart.data.datasets[0].backgroundColor[1]
-                };
-                labels[2] = {
-                  text: $localize`Danger: ${
-                    chart.data.datasets[0].data[0] + chart.data.datasets[0].data[1]
-                  }%`,
-                  fillStyle: chart.data.datasets[0].backgroundColor[2],
-                  strokeStyle: chart.data.datasets[0].backgroundColor[2]
-                };
-
+                if (chart.data.datasets[0].data?.length) {
+                  labels[1] = {
+                    text: $localize`Warning: ${chart.data.datasets[0].data[0]}%`,
+                    fillStyle: chart.data.datasets[0].backgroundColor[1],
+                    strokeStyle: chart.data.datasets[0].backgroundColor[1]
+                  };
+                  labels[2] = {
+                    text: $localize`Danger: ${
+                      chart.data.datasets[0].data[0] + chart.data.datasets[0].data[1]
+                    }%`,
+                    fillStyle: chart.data.datasets[0].backgroundColor[2],
+                    strokeStyle: chart.data.datasets[0].backgroundColor[2]
+                  };
+                }
                 return labels;
               }
             }
@@ -158,19 +159,24 @@ export class DashboardPieComponent implements OnChanges, OnInit {
     const fullRatioPercent = this.highThreshold * 100;
     const percentAvailable = this.calcPercentage(data.max - data.current, data.max);
     const percentUsed = this.calcPercentage(data.current, data.max);
-    if (percentUsed >= fullRatioPercent) {
+
+    if (fullRatioPercent >= 0 && percentUsed >= fullRatioPercent) {
       this.color = 'chart-color-red';
-    } else if (percentUsed >= nearFullRatioPercent) {
+    } else if (nearFullRatioPercent >= 0 && percentUsed >= nearFullRatioPercent) {
       this.color = 'chart-color-yellow';
     } else {
       this.color = 'chart-color-blue';
     }
 
-    chart.dataset[0].data = [
-      Math.round(nearFullRatioPercent),
-      Math.round(Math.abs(nearFullRatioPercent - fullRatioPercent)),
-      Math.round(100 - fullRatioPercent)
-    ];
+    if (fullRatioPercent >= 0 && nearFullRatioPercent >= 0) {
+      chart.dataset[0].data = [
+        Math.round(nearFullRatioPercent),
+        Math.round(Math.abs(nearFullRatioPercent - fullRatioPercent)),
+        Math.round(100 - fullRatioPercent)
+      ];
+    } else {
+      chart.dataset[1].backgroundColor[1] = this.cssHelper.propertyValue('chart-color-light-gray');
+    }
 
     chart.dataset[1].data = [
       percentUsed,
@@ -178,7 +184,6 @@ export class DashboardPieComponent implements OnChanges, OnInit {
       this.dimlessBinary.transform(data.current)
     ];
     chart.dataset[1].backgroundColor[0] = this.cssHelper.propertyValue(this.color);
-
     chart.dataset[0].label = [`${percentUsed}%\nof ${this.dimlessBinary.transform(data.max)}`];
   }
 
index 8210a4c8103718567a6b0d54a95ab2e1387cd5c0..722886d4477539be751731184f074cb63d43784a 100644 (file)
@@ -164,9 +164,12 @@ export class HealthComponent implements OnInit, OnDestroy {
       data.df.stats.total_bytes
     );
 
-    if (percentUsed / 100 >= this.osdSettings.nearfull_ratio) {
+    const nearfullRatio = this.osdSettings.nearfull_ratio;
+    const fullRatio = this.osdSettings.nearfull_ratio;
+
+    if (nearfullRatio >= 0 && percentUsed / 100 >= nearfullRatio) {
       this.color = 'chart-color-red';
-    } else if (percentUsed / 100 >= this.osdSettings.full_ratio) {
+    } else if (fullRatio >= 0 && percentUsed / 100 >= fullRatio) {
       this.color = 'chart-color-yellow';
     } else {
       this.color = 'chart-color-blue';
index e7d7b17f0791c81c663f251bc55e49014e0337ac..9a0a3398a3c0535ab287a666ac036974f72c9d2c 100644 (file)
@@ -29,7 +29,7 @@
      data-placement="left"
      [ngbTooltip]="usageTooltipTpl">
   <div class="progress-bar bg-info"
-       [ngClass]="{'bg-warning': usedPercentage/100 >= warningThreshold, 'bg-danger': usedPercentage/100 >= errorThreshold}"
+       [ngClass]="{'bg-warning': (warningThreshold >= 0) && (usedPercentage/100 >= warningThreshold), 'bg-danger': (errorThreshold >= 0) && (usedPercentage/100 >= errorThreshold)}"
        role="progressbar"
        [attr.aria-label]="{ title }"
        i18n-aria-label="The title of this usage bar is { title }"