Added fallback to default dashboard in case Prometheus is not accesible (#1302)

This commit is contained in:
Alex
2021-12-07 15:39:50 -06:00
committed by GitHub
parent 1e59f131e8
commit bf126d3a84
10 changed files with 141 additions and 65 deletions

View File

@@ -42,6 +42,9 @@ type AdminInfoResponse struct {
// objects
Objects int64 `json:"objects,omitempty"`
// prometheus not ready
PrometheusNotReady bool `json:"prometheusNotReady,omitempty"`
// servers
Servers []*ServerProperties `json:"servers"`

View File

@@ -472,7 +472,12 @@ export const getTimeFromTimestamp = (
timestamp: string,
fullDate: boolean = false
) => {
const dateObject = new Date(parseInt(timestamp) * 1000);
const timestampToInt = parseInt(timestamp);
if (isNaN(timestampToInt)) {
return "";
}
const dateObject = new Date(timestampToInt * 1000);
if (fullDate) {
return `${dateObject.getFullYear()}-${String(

View File

@@ -133,6 +133,31 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
return (
<Fragment>
<div className={classes.dashboardBG} />
{usage?.prometheusNotReady && (
<Grid
container
justifyContent={"center"}
alignContent={"center"}
alignItems={"center"}
>
<Grid item xs={8}>
<HelpBox
iconComponent={<PrometheusIcon />}
title={"We can't retrieve advanced metrics at this time"}
help={
<Fragment>
MinIO Dashboard will display basic metrics as we couldn't
connect to Prometheus successfully.
<br /> <br />
Please try again in a few minutes. If the problem persists,
you can review your configuration and confirm that Prometheus
server is up and running.
</Fragment>
}
/>
</Grid>
</Grid>
)}
<Grid container spacing={2}>
<Grid item xs={12} className={classes.generalStatusTitle}>
General Status
@@ -241,6 +266,7 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
</TabPanel>
</Grid>
</Grid>
{!usage?.prometheusNotReady && (
<Grid
container
justifyContent={"center"}
@@ -280,6 +306,7 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
/>
</Grid>
</Grid>
)}
</Fragment>
);
};

View File

@@ -154,7 +154,12 @@ const LinearGraphWidget = ({
if (key === "name") {
continue;
}
const val = parseInt(dp[key]);
let val = parseInt(dp[key]);
if (isNaN(val)) {
val = 0;
}
if (maxVal < val) {
maxVal = val;
}

View File

@@ -111,6 +111,18 @@ const SingleRepWidget = ({
}, [loading, panelItem, timeEnd, timeStart, displayErrorMessage, apiPrefix]);
const gradientID = `colorGradient-${title.split(" ").join("-")}`;
let repNumber = "";
if (result) {
const resultRep = parseInt(result.innerLabel || "0");
if (!isNaN(resultRep)) {
repNumber = representationNumber(resultRep);
} else {
repNumber = "0";
}
}
return (
<div className={classes.singleValueContainer}>
<div className={classes.titleContainer}>{title}</div>
@@ -150,7 +162,7 @@ const SingleRepWidget = ({
fill={"#07193E"}
>
{result
? representationNumber(parseInt(result.innerLabel || "0"))
? repNumber
: ""}
</text>
</AreaChart>

View File

@@ -20,6 +20,7 @@ export interface Usage {
usage: number;
buckets: number;
objects: number;
prometheusNotReady?: boolean;
widgets?: any;
servers: ServerInfo[];
}

View File

@@ -89,6 +89,7 @@ const EditConfiguration = ({
useState<boolean>(false);
//Effects
useEffect(() => {
if (loadingConfig) {
const configId = get(selectedConfiguration, "configuration_id", false);
if (configId) {
@@ -97,14 +98,18 @@ const EditConfiguration = ({
.then((res) => {
const keyVals = get(res, "key_values", []);
setConfigValues(keyVals);
setLoadingConfig(false);
})
.catch((err: ErrorResponseHandler) => {
setLoadingConfig(false);
setErrorSnackMessage(err);
});
return;
}
setLoadingConfig(false);
}, [selectedConfiguration, setErrorSnackMessage]);
}
}, [loadingConfig, selectedConfiguration, setErrorSnackMessage]);
useEffect(() => {
if (saving) {
@@ -153,6 +158,9 @@ const EditConfiguration = ({
const continueReset = (restart: boolean) => {
setResetConfigurationOpen(false);
serverNeedsRestart(restart);
if (restart) {
setLoadingConfig(true);
}
};
return (

View File

@@ -63,6 +63,7 @@ type UsageInfo struct {
Usage int64
DisksUsage int64
Servers []*models.ServerProperties
EndpointNotReady bool
}
// GetAdminInfo invokes admin info and returns a parsed `UsageInfo` structure
@@ -845,7 +846,12 @@ func getAdminInfoResponse(session *models.Principal, params admin_api.AdminInfoP
}
func getUsageWidgetsForDeployment(prometheusURL string, mAdmin *madmin.AdminClient) (*models.AdminInfoResponse, *models.Error) {
if prometheusURL == "" {
prometheusNotReady := false
if prometheusURL != "" && !testPrometheusURL(prometheusURL) {
prometheusNotReady = true
}
if prometheusURL == "" || prometheusNotReady {
// create a minioClient interface implementation
// defining the client to be used
adminClient := AdminClient{Client: mAdmin}
@@ -862,6 +868,7 @@ func getUsageWidgetsForDeployment(prometheusURL string, mAdmin *madmin.AdminClie
Objects: usage.Objects,
Usage: usage.Usage,
Servers: usage.Servers,
PrometheusNotReady: prometheusNotReady,
}
return sessionResp, nil
}

View File

@@ -3655,6 +3655,9 @@ func init() {
"objects": {
"type": "integer"
},
"prometheusNotReady": {
"type": "boolean"
},
"servers": {
"type": "array",
"items": {
@@ -9503,6 +9506,9 @@ func init() {
"objects": {
"type": "integer"
},
"prometheusNotReady": {
"type": "boolean"
},
"servers": {
"type": "array",
"items": {

View File

@@ -3228,6 +3228,8 @@ definitions:
type: integer
usage:
type: integer
prometheusNotReady:
type: boolean
widgets:
type: array
items: