Skip to content

Commit 3e76b89

Browse files
authored
Merge pull request ceph#55643 from afreen23/fix-62089
mgr/dashboard: Handle errors for /api/osd/settings Reviewed-by: Pedro Gonzalez Gomez <[email protected]> Reviewed-by: Nizamudeen A <[email protected]>
2 parents ac1d58a + 518bff9 commit 3e76b89

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

src/pybind/mgr/dashboard/controllers/osd.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,18 @@ def gauge_stats(osd, osd_spec):
168168
@RESTController.Collection('GET', version=APIVersion.EXPERIMENTAL)
169169
@ReadPermission
170170
def settings(self):
171-
result = CephService.send_command('mon', 'osd dump')
172-
return {
173-
'nearfull_ratio': result['nearfull_ratio'],
174-
'full_ratio': result['full_ratio']
171+
data = {
172+
'nearfull_ratio': -1,
173+
'full_ratio': -1
175174
}
175+
try:
176+
result = CephService.send_command('mon', 'osd dump')
177+
data['nearfull_ratio'] = result['nearfull_ratio']
178+
data['full_ratio'] = result['full_ratio']
179+
except TypeError:
180+
logger.error(
181+
'Error setting nearfull_ratio and full_ratio:', exc_info=True)
182+
return data
176183

177184
def _get_operational_status(self, osd_id: int, removing_osd_ids: Optional[List[int]]):
178185
if removing_osd_ids is None:

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard-pie/dashboard-pie.component.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class DashboardPieComponent implements OnChanges, OnInit {
5959
constructor(private cssHelper: CssHelper, private dimlessBinary: DimlessBinaryPipe) {
6060
this.chartConfig = {
6161
chartType: 'doughnut',
62-
labels: ['', '', ''],
62+
labels: [],
6363
dataset: [
6464
{
6565
label: null,
@@ -97,19 +97,20 @@ export class DashboardPieComponent implements OnChanges, OnInit {
9797
fillStyle: chart.data.datasets[1].backgroundColor[0],
9898
strokeStyle: chart.data.datasets[1].backgroundColor[0]
9999
};
100-
labels[1] = {
101-
text: $localize`Warning: ${chart.data.datasets[0].data[0]}%`,
102-
fillStyle: chart.data.datasets[0].backgroundColor[1],
103-
strokeStyle: chart.data.datasets[0].backgroundColor[1]
104-
};
105-
labels[2] = {
106-
text: $localize`Danger: ${
107-
chart.data.datasets[0].data[0] + chart.data.datasets[0].data[1]
108-
}%`,
109-
fillStyle: chart.data.datasets[0].backgroundColor[2],
110-
strokeStyle: chart.data.datasets[0].backgroundColor[2]
111-
};
112-
100+
if (chart.data.datasets[0].data?.length) {
101+
labels[1] = {
102+
text: $localize`Warning: ${chart.data.datasets[0].data[0]}%`,
103+
fillStyle: chart.data.datasets[0].backgroundColor[1],
104+
strokeStyle: chart.data.datasets[0].backgroundColor[1]
105+
};
106+
labels[2] = {
107+
text: $localize`Danger: ${
108+
chart.data.datasets[0].data[0] + chart.data.datasets[0].data[1]
109+
}%`,
110+
fillStyle: chart.data.datasets[0].backgroundColor[2],
111+
strokeStyle: chart.data.datasets[0].backgroundColor[2]
112+
};
113+
}
113114
return labels;
114115
}
115116
}
@@ -158,27 +159,31 @@ export class DashboardPieComponent implements OnChanges, OnInit {
158159
const fullRatioPercent = this.highThreshold * 100;
159160
const percentAvailable = this.calcPercentage(data.max - data.current, data.max);
160161
const percentUsed = this.calcPercentage(data.current, data.max);
161-
if (percentUsed >= fullRatioPercent) {
162+
163+
if (fullRatioPercent >= 0 && percentUsed >= fullRatioPercent) {
162164
this.color = 'chart-color-red';
163-
} else if (percentUsed >= nearFullRatioPercent) {
165+
} else if (nearFullRatioPercent >= 0 && percentUsed >= nearFullRatioPercent) {
164166
this.color = 'chart-color-yellow';
165167
} else {
166168
this.color = 'chart-color-blue';
167169
}
168170

169-
chart.dataset[0].data = [
170-
Math.round(nearFullRatioPercent),
171-
Math.round(Math.abs(nearFullRatioPercent - fullRatioPercent)),
172-
Math.round(100 - fullRatioPercent)
173-
];
171+
if (fullRatioPercent >= 0 && nearFullRatioPercent >= 0) {
172+
chart.dataset[0].data = [
173+
Math.round(nearFullRatioPercent),
174+
Math.round(Math.abs(nearFullRatioPercent - fullRatioPercent)),
175+
Math.round(100 - fullRatioPercent)
176+
];
177+
} else {
178+
chart.dataset[1].backgroundColor[1] = this.cssHelper.propertyValue('chart-color-light-gray');
179+
}
174180

175181
chart.dataset[1].data = [
176182
percentUsed,
177183
percentAvailable,
178184
this.dimlessBinary.transform(data.current)
179185
];
180186
chart.dataset[1].backgroundColor[0] = this.cssHelper.propertyValue(this.color);
181-
182187
chart.dataset[0].label = [`${percentUsed}%\nof ${this.dimlessBinary.transform(data.max)}`];
183188
}
184189

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ export class HealthComponent implements OnInit, OnDestroy {
164164
data.df.stats.total_bytes
165165
);
166166

167-
if (percentUsed / 100 >= this.osdSettings.nearfull_ratio) {
167+
const nearfullRatio = this.osdSettings.nearfull_ratio;
168+
const fullRatio = this.osdSettings.nearfull_ratio;
169+
170+
if (nearfullRatio >= 0 && percentUsed / 100 >= nearfullRatio) {
168171
this.color = 'chart-color-red';
169-
} else if (percentUsed / 100 >= this.osdSettings.full_ratio) {
172+
} else if (fullRatio >= 0 && percentUsed / 100 >= fullRatio) {
170173
this.color = 'chart-color-yellow';
171174
} else {
172175
this.color = 'chart-color-blue';

src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
data-placement="left"
3030
[ngbTooltip]="usageTooltipTpl">
3131
<div class="progress-bar bg-info"
32-
[ngClass]="{'bg-warning': usedPercentage/100 >= warningThreshold, 'bg-danger': usedPercentage/100 >= errorThreshold}"
32+
[ngClass]="{'bg-warning': (warningThreshold >= 0) && (usedPercentage/100 >= warningThreshold), 'bg-danger': (errorThreshold >= 0) && (usedPercentage/100 >= errorThreshold)}"
3333
role="progressbar"
3434
[attr.aria-label]="{ title }"
3535
i18n-aria-label="The title of this usage bar is { title }"

0 commit comments

Comments
 (0)