Skip to content

Commit

Permalink
fix(ui): first try healthy cluster members
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Apr 3, 2024
1 parent a049b0f commit 8009f4a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
86 changes: 86 additions & 0 deletions ui/src/Stores/AlertStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,92 @@ describe("AlertStore.data", () => {
store.data.getClusterAlertmanagersWithoutReadOnly("default"),
).toEqual([]);
});

it("clustersWithoutReadOnly lists healthy members first", () => {
const store = new AlertStore([]);
store.data.setUpstreams({
counters: { total: 2, healthy: 1, failed: 1 },
clusters: { default: ["am1", "am2"] },
instances: [
{
name: "am1",
uri: "http://localhost",
publicURI: "http://example.com:8080",
readonly: false,
headers: { foo: "bar" },
corsCredentials: "include",
error: "bad",
version: "0.24.0",
cluster: "default",
clusterMembers: ["am1", "am2"],
},
{
name: "am2",
uri: "http://localhost:8081",
publicURI: "http://example.com",
readonly: false,
headers: {},
corsCredentials: "include",
error: "",
version: "0.24.0",
cluster: "default",
clusterMembers: ["am1", "am2"],
},
],
});
expect(store.data.clustersWithoutReadOnly).toEqual({
default: ["am2", "am1"],
});
});

it("clustersWithoutReadOnly keeps healthy order", () => {
const store = new AlertStore([]);
store.data.setUpstreams({
counters: { total: 3, healthy: 3, failed: 0 },
clusters: { default: ["am1", "am2", "am3"] },
instances: [
{
name: "am1",
uri: "http://localhost",
publicURI: "http://example.com:8080",
readonly: false,
headers: { foo: "bar" },
corsCredentials: "include",
error: "",
version: "0.24.0",
cluster: "default",
clusterMembers: ["am1", "am2", "am3"],
},
{
name: "am2",
uri: "http://localhost:8081",
publicURI: "http://example.com",
readonly: false,
headers: {},
corsCredentials: "include",
error: "",
version: "0.24.0",
cluster: "default",
clusterMembers: ["am1", "am2", "am3"],
},
{
name: "am3",
uri: "http://localhost:8081",
publicURI: "http://example.com",
readonly: false,
headers: {},
corsCredentials: "include",
error: "",
version: "0.24.0",
cluster: "default",
clusterMembers: ["am1", "am2", "am3"],
},
],
});
expect(store.data.clustersWithoutReadOnly).toEqual({
default: ["am1", "am2", "am3"],
});
});
});

describe("AlertStore.status", () => {
Expand Down
8 changes: 7 additions & 1 deletion ui/src/Stores/AlertStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,19 @@ class AlertStore {
);
},
get clustersWithoutReadOnly(): APIAlertsResponseUpstreamsClusterMapT {
const unhealthy = this.upstreams.instances
.filter((upstream) => upstream.error !== "")
.map((upstream) => upstream.name);
const clusters: APIAlertsResponseUpstreamsClusterMapT = {};
for (const clusterID of Object.keys(this.upstreams.clusters)) {
const members = this.upstreams.clusters[clusterID].filter(
(member) => this.isReadOnlyAlertmanager(member) === false,
);
if (members.length > 0) {
clusters[clusterID] = members;
clusters[clusterID] = [
...members.filter((member) => !unhealthy.includes(member)),
...members.filter((member) => unhealthy.includes(member)),
];
}
}
return clusters;
Expand Down

0 comments on commit 8009f4a

Please sign in to comment.