Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hint banners in /status page #307 #418

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/mqueryfront/src/components/WarningPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

const WarningPage = (props) => (
<div className="alert alert-warning alert-dismissible fade show">
<h2>Warning</h2>
{props.msg}
{props.dismissable && (
<button
type="button"
class="btn-close"
data-bs-dismiss="alert"
aria-label="Close"
/>
)}
</div>
);

export default WarningPage;
21 changes: 21 additions & 0 deletions src/mqueryfront/src/status/DatabaseTopology.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { filesize } from "filesize";

import ErrorBoundary from "../components/ErrorBoundary";
import api from "../api";
import WarningPage from "../components/WarningPage";

class DatasetRow extends Component {
render() {
Expand Down Expand Up @@ -71,6 +72,19 @@ class DatabaseTopology extends Component {
});
}

getDatasetsCompactingWarning(datasets) {
var fileCountThreshold = 1000 * 1000;
var amountThreshhold = 20;
var smallDatasets = datasets.filter(
(dataset) => dataset.file_count < fileCountThreshold
);
if (smallDatasets.length < amountThreshhold) {
return null;
}
return `At least ${amountThreshhold} datasets have less \
than ${fileCountThreshold} samples - consider compacting them.`;
}

render() {
const datasetRows = Object.keys(
this.state.datasets
Expand All @@ -93,9 +107,16 @@ class DatabaseTopology extends Component {
const totalSize = filesize(totalBytes, { standard: "iec" });
const filesTooltip = `Total files: ${totalCount} (${totalSize})`;

const datasetsCompactingWarning = this.getDatasetsCompactingWarning(
datasets
);

return (
<ErrorBoundary error={this.state.error}>
<h2 className="text-center mq-bottom">Topology</h2>
{datasetsCompactingWarning && (
<WarningPage msg={datasetsCompactingWarning} dismissable />
)}
<div className="table-responsive">
<table className="table table-bordered table-topology">
<thead>
Expand Down
39 changes: 38 additions & 1 deletion src/mqueryfront/src/status/StatusPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BackendStatus from "./BackendStatus";
import DatabaseTopology from "./DatabaseTopology";
import VersionStatus from "./VersionStatus";
import api from "../api";
import WarningPage from "../components/WarningPage";

class StatusPage extends Component {
constructor(props) {
Expand All @@ -28,17 +29,53 @@ class StatusPage extends Component {
});
}

getAgentsUrsaURLDuplicatesWarning(agentgroups) {
var ursaURLS = agentgroups.map((agent) => agent.spec.ursadb_url);
var duplicateURLS = ursaURLS.filter(
(url, index) => ursaURLS.indexOf(url) !== index
);
if (!duplicateURLS.length) {
return null;
}
return `At least two agents share the same UrsaDB URL(s): \
${duplicateURLS.join(
", "
)}. Something might be wrong with backend configuration.`;
Comment on lines +42 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another nitpick, but maybe extract duplicateURLS.join to a separate variable (to avoid long expression inside)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess i'm merging it like it is.

}

getNoAgentsWarning(agentgroups) {
if (agentgroups.length) {
return null;
}
return "There are no connected agents! Check your backend configuration.";
}

render() {
const ursaURLWarning = this.getAgentsUrsaURLDuplicatesWarning(
this.state.backend.agents
);
const noAgentsWarning = this.getNoAgentsWarning(
this.state.backend.agents
);
return (
<ErrorBoundary error={this.state.error}>
<div className="container-fluid">
{ursaURLWarning && (
<WarningPage msg={ursaURLWarning} dismissable />
)}
<h1 className="text-center mq-bottom">Status</h1>
<div className="row">
<div className="col-md-6">
<VersionStatus
components={this.state.backend.components}
/>
<BackendStatus agents={this.state.backend.agents} />
{noAgentsWarning ? (
<WarningPage msg={noAgentsWarning} />
) : (
<BackendStatus
agents={this.state.backend.agents}
/>
)}
</div>
<div className="col-md-6">
<DatabaseTopology />
Expand Down
Loading