Skip to content

Commit bf126d3

Browse files
authored
Added fallback to default dashboard in case Prometheus is not accesible (#1302)
1 parent 1e59f13 commit bf126d3

File tree

10 files changed

+142
-66
lines changed

10 files changed

+142
-66
lines changed

models/admin_info_response.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

portal-ui/src/common/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,12 @@ export const getTimeFromTimestamp = (
472472
timestamp: string,
473473
fullDate: boolean = false
474474
) => {
475-
const dateObject = new Date(parseInt(timestamp) * 1000);
475+
const timestampToInt = parseInt(timestamp);
476+
477+
if (isNaN(timestampToInt)) {
478+
return "";
479+
}
480+
const dateObject = new Date(timestampToInt * 1000);
476481

477482
if (fullDate) {
478483
return `${dateObject.getFullYear()}-${String(

portal-ui/src/screens/Console/Dashboard/BasicDashboard/BasicDashboard.tsx

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
133133
return (
134134
<Fragment>
135135
<div className={classes.dashboardBG} />
136+
{usage?.prometheusNotReady && (
137+
<Grid
138+
container
139+
justifyContent={"center"}
140+
alignContent={"center"}
141+
alignItems={"center"}
142+
>
143+
<Grid item xs={8}>
144+
<HelpBox
145+
iconComponent={<PrometheusIcon />}
146+
title={"We can't retrieve advanced metrics at this time"}
147+
help={
148+
<Fragment>
149+
MinIO Dashboard will display basic metrics as we couldn't
150+
connect to Prometheus successfully.
151+
<br /> <br />
152+
Please try again in a few minutes. If the problem persists,
153+
you can review your configuration and confirm that Prometheus
154+
server is up and running.
155+
</Fragment>
156+
}
157+
/>
158+
</Grid>
159+
</Grid>
160+
)}
136161
<Grid container spacing={2}>
137162
<Grid item xs={12} className={classes.generalStatusTitle}>
138163
General Status
@@ -241,45 +266,47 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
241266
</TabPanel>
242267
</Grid>
243268
</Grid>
244-
<Grid
245-
container
246-
justifyContent={"center"}
247-
alignContent={"center"}
248-
alignItems={"center"}
249-
>
250-
<Grid item xs={8}>
251-
<HelpBox
252-
iconComponent={<PrometheusIcon />}
253-
title={"Monitoring"}
254-
help={
255-
<Fragment>
256-
The MinIO Dashboard is displaying basic metrics only due to
257-
missing the{" "}
258-
<a
259-
href="https://docs.min.io/minio/baremetal/console/minio-console.html?ref=con#configuration"
260-
target="_blank"
261-
rel="noreferrer"
262-
>
263-
necessary settings
264-
</a>{" "}
265-
for displaying extended metrics.
266-
<br />
267-
<br />
268-
See{" "}
269-
<a
270-
href="https://docs.min.io/minio/baremetal/monitoring/metrics-alerts/collect-minio-metrics-using-prometheus.html?ref=con#minio-metrics-collect-using-prometheus"
271-
target="_blank"
272-
rel="noreferrer"
273-
>
274-
Collect MinIO Metrics Using Prometheus
275-
</a>{" "}
276-
for a complete tutorial on scraping and visualizing MinIO
277-
metrics with Prometheus.
278-
</Fragment>
279-
}
280-
/>
269+
{!usage?.prometheusNotReady && (
270+
<Grid
271+
container
272+
justifyContent={"center"}
273+
alignContent={"center"}
274+
alignItems={"center"}
275+
>
276+
<Grid item xs={8}>
277+
<HelpBox
278+
iconComponent={<PrometheusIcon />}
279+
title={"Monitoring"}
280+
help={
281+
<Fragment>
282+
The MinIO Dashboard is displaying basic metrics only due to
283+
missing the{" "}
284+
<a
285+
href="https://docs.min.io/minio/baremetal/console/minio-console.html?ref=con#configuration"
286+
target="_blank"
287+
rel="noreferrer"
288+
>
289+
necessary settings
290+
</a>{" "}
291+
for displaying extended metrics.
292+
<br />
293+
<br />
294+
See{" "}
295+
<a
296+
href="https://docs.min.io/minio/baremetal/monitoring/metrics-alerts/collect-minio-metrics-using-prometheus.html?ref=con#minio-metrics-collect-using-prometheus"
297+
target="_blank"
298+
rel="noreferrer"
299+
>
300+
Collect MinIO Metrics Using Prometheus
301+
</a>{" "}
302+
for a complete tutorial on scraping and visualizing MinIO
303+
metrics with Prometheus.
304+
</Fragment>
305+
}
306+
/>
307+
</Grid>
281308
</Grid>
282-
</Grid>
309+
)}
283310
</Fragment>
284311
);
285312
};

portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/LinearGraphWidget.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ const LinearGraphWidget = ({
154154
if (key === "name") {
155155
continue;
156156
}
157-
const val = parseInt(dp[key]);
157+
let val = parseInt(dp[key]);
158+
159+
if (isNaN(val)) {
160+
val = 0;
161+
}
162+
158163
if (maxVal < val) {
159164
maxVal = val;
160165
}

portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/SingleRepWidget.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ const SingleRepWidget = ({
111111
}, [loading, panelItem, timeEnd, timeStart, displayErrorMessage, apiPrefix]);
112112
const gradientID = `colorGradient-${title.split(" ").join("-")}`;
113113

114+
let repNumber = "";
115+
116+
if (result) {
117+
const resultRep = parseInt(result.innerLabel || "0");
118+
119+
if (!isNaN(resultRep)) {
120+
repNumber = representationNumber(resultRep);
121+
} else {
122+
repNumber = "0";
123+
}
124+
}
125+
114126
return (
115127
<div className={classes.singleValueContainer}>
116128
<div className={classes.titleContainer}>{title}</div>
@@ -150,7 +162,7 @@ const SingleRepWidget = ({
150162
fill={"#07193E"}
151163
>
152164
{result
153-
? representationNumber(parseInt(result.innerLabel || "0"))
165+
? repNumber
154166
: ""}
155167
</text>
156168
</AreaChart>

portal-ui/src/screens/Console/Dashboard/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Usage {
2020
usage: number;
2121
buckets: number;
2222
objects: number;
23+
prometheusNotReady?: boolean;
2324
widgets?: any;
2425
servers: ServerInfo[];
2526
}

portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/EditConfiguration.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,27 @@ const EditConfiguration = ({
8989
useState<boolean>(false);
9090
//Effects
9191
useEffect(() => {
92-
const configId = get(selectedConfiguration, "configuration_id", false);
93-
94-
if (configId) {
95-
api
96-
.invoke("GET", `/api/v1/configs/${configId}`)
97-
.then((res) => {
98-
const keyVals = get(res, "key_values", []);
99-
setConfigValues(keyVals);
100-
})
101-
.catch((err: ErrorResponseHandler) => {
102-
setLoadingConfig(false);
103-
setErrorSnackMessage(err);
104-
});
92+
if (loadingConfig) {
93+
const configId = get(selectedConfiguration, "configuration_id", false);
94+
95+
if (configId) {
96+
api
97+
.invoke("GET", `/api/v1/configs/${configId}`)
98+
.then((res) => {
99+
const keyVals = get(res, "key_values", []);
100+
setConfigValues(keyVals);
101+
setLoadingConfig(false);
102+
})
103+
.catch((err: ErrorResponseHandler) => {
104+
setLoadingConfig(false);
105+
setErrorSnackMessage(err);
106+
});
107+
108+
return;
109+
}
110+
setLoadingConfig(false);
105111
}
106-
setLoadingConfig(false);
107-
}, [selectedConfiguration, setErrorSnackMessage]);
112+
}, [loadingConfig, selectedConfiguration, setErrorSnackMessage]);
108113

109114
useEffect(() => {
110115
if (saving) {
@@ -153,6 +158,9 @@ const EditConfiguration = ({
153158
const continueReset = (restart: boolean) => {
154159
setResetConfigurationOpen(false);
155160
serverNeedsRestart(restart);
161+
if (restart) {
162+
setLoadingConfig(true);
163+
}
156164
};
157165

158166
return (

restapi/admin_info.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ func registerAdminInfoHandlers(api *operations.ConsoleAPI) {
5858
}
5959

6060
type UsageInfo struct {
61-
Buckets int64
62-
Objects int64
63-
Usage int64
64-
DisksUsage int64
65-
Servers []*models.ServerProperties
61+
Buckets int64
62+
Objects int64
63+
Usage int64
64+
DisksUsage int64
65+
Servers []*models.ServerProperties
66+
EndpointNotReady bool
6667
}
6768

6869
// GetAdminInfo invokes admin info and returns a parsed `UsageInfo` structure
@@ -845,7 +846,12 @@ func getAdminInfoResponse(session *models.Principal, params admin_api.AdminInfoP
845846
}
846847

847848
func getUsageWidgetsForDeployment(prometheusURL string, mAdmin *madmin.AdminClient) (*models.AdminInfoResponse, *models.Error) {
848-
if prometheusURL == "" {
849+
prometheusNotReady := false
850+
851+
if prometheusURL != "" && !testPrometheusURL(prometheusURL) {
852+
prometheusNotReady = true
853+
}
854+
if prometheusURL == "" || prometheusNotReady {
849855
// create a minioClient interface implementation
850856
// defining the client to be used
851857
adminClient := AdminClient{Client: mAdmin}
@@ -858,10 +864,11 @@ func getUsageWidgetsForDeployment(prometheusURL string, mAdmin *madmin.AdminClie
858864
return nil, prepareError(err)
859865
}
860866
sessionResp := &models.AdminInfoResponse{
861-
Buckets: usage.Buckets,
862-
Objects: usage.Objects,
863-
Usage: usage.Usage,
864-
Servers: usage.Servers,
867+
Buckets: usage.Buckets,
868+
Objects: usage.Objects,
869+
Usage: usage.Usage,
870+
Servers: usage.Servers,
871+
PrometheusNotReady: prometheusNotReady,
865872
}
866873
return sessionResp, nil
867874
}

restapi/embedded_spec.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger-console.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,6 +3228,8 @@ definitions:
32283228
type: integer
32293229
usage:
32303230
type: integer
3231+
prometheusNotReady:
3232+
type: boolean
32313233
widgets:
32323234
type: array
32333235
items:

0 commit comments

Comments
 (0)