From 2e2591f7c992ba2b4b48ef6a7b1450a1c3c69d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 6 Jan 2020 22:22:47 +0000 Subject: [PATCH 1/2] fix(api): hash is not used by the UI, don't expose it --- cmd/karma/api_test.go | 3 --- internal/models/alertgroup.go | 2 +- internal/models/api_test.go | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/cmd/karma/api_test.go b/cmd/karma/api_test.go index bc3eb65e5..ac25c61ba 100644 --- a/cmd/karma/api_test.go +++ b/cmd/karma/api_test.go @@ -954,9 +954,6 @@ func testAlert(version string, t *testing.T, expectedAlert, gotAlert models.Aler } func testAlertGroup(version string, t *testing.T, testCase groupTest, group models.APIAlertGroup) { - if group.Hash == "" { - t.Errorf("Empty hash for group %v", group.Labels) - } if testCase.id != group.ID { t.Errorf("[%s] Alert group.ID mismatch, expected '%s' but got '%s' for group %v", version, testCase.id, group.ID, group.Labels) diff --git a/internal/models/alertgroup.go b/internal/models/alertgroup.go index bd8c856bd..54a929966 100644 --- a/internal/models/alertgroup.go +++ b/internal/models/alertgroup.go @@ -41,7 +41,7 @@ type AlertGroup struct { Labels map[string]string `json:"labels"` Alerts AlertList `json:"alerts"` ID string `json:"id"` - Hash string `json:"hash"` + Hash string `json:"-"` AlertmanagerCount map[string]int `json:"alertmanagerCount"` StateCount map[string]int `json:"stateCount"` LatestStartsAt time.Time `json:"-"` diff --git a/internal/models/api_test.go b/internal/models/api_test.go index d093871e3..1eb5783a8 100644 --- a/internal/models/api_test.go +++ b/internal/models/api_test.go @@ -198,7 +198,6 @@ func TestDedupSharedMaps(t *testing.T) { } ], "id": "", - "hash": "", "alertmanagerCount": null, "stateCount": null, "shared": { From 378866ae34223bd9194201c36f26fcbdb4795f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 6 Jan 2020 22:23:16 +0000 Subject: [PATCH 2/2] fix(ui): remove hash tests, it's no longer exposed in the API --- .../Components/Grid/AlertGrid/index.test.js | 2 -- ui/src/Models/API.js | 1 - ui/src/Stores/AlertStore.test.js | 36 ------------------- ui/src/__mocks__/Alerts.js | 1 - ui/src/__mocks__/Stories.js | 2 -- 5 files changed, 42 deletions(-) diff --git a/ui/src/Components/Grid/AlertGrid/index.test.js b/ui/src/Components/Grid/AlertGrid/index.test.js index 97dbee9c0..023ee5ce3 100644 --- a/ui/src/Components/Grid/AlertGrid/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/index.test.js @@ -61,10 +61,8 @@ const MockGroupList = (count, alertPerGroup) => { let groups = []; for (let i = 1; i <= count; i++) { let id = `id${i}`; - let hash = `hash${i}`; let group = MockGroup(`group${i}`, alertPerGroup); group.id = id; - group.hash = hash; groups.push(group); } alertStore.data.upstreams = { diff --git a/ui/src/Models/API.js b/ui/src/Models/API.js index e6e7e9c44..d55e94782 100644 --- a/ui/src/Models/API.js +++ b/ui/src/Models/API.js @@ -33,7 +33,6 @@ const APIGroup = PropTypes.exact({ labels: PropTypes.object.isRequired, alerts: PropTypes.arrayOf(APIAlert), id: PropTypes.string.isRequired, - hash: PropTypes.string.isRequired, alertmanagerCount: PropTypes.objectOf(PropTypes.number).isRequired, stateCount: PropTypes.exact({ active: PropTypes.number.isRequired, diff --git a/ui/src/Stores/AlertStore.test.js b/ui/src/Stores/AlertStore.test.js index e15a1cc78..6b95b35d9 100644 --- a/ui/src/Stores/AlertStore.test.js +++ b/ui/src/Stores/AlertStore.test.js @@ -485,21 +485,6 @@ describe("AlertStore.fetch", () => { expect(store.data.groups).toMatchObject({ foo: "foo", bar: "bar" }); }); - it("is no-op for groups that didn't change", () => { - const store = new AlertStore(["label=value"]); - store.data.groups = { foo: { hash: "foo" }, bar: { hash: "bar" } }; - - const response = EmptyAPIResponse(); - response.groups = { foo: { hash: "foo" }, bar: { hash: "bar" } }; - - store.parseAPIResponse(response); - expect(Object.keys(store.data.groups)).toHaveLength(2); - expect(store.data.groups).toMatchObject({ - foo: { hash: "foo" }, - bar: { hash: "bar" } - }); - }); - it("removes old groups from the store after fetch", () => { const store = new AlertStore(["label=value"]); store.data.groups = { foo: "foo", delete: "me", bar: "bar" }; @@ -512,25 +497,4 @@ describe("AlertStore.fetch", () => { expect(Object.keys(store.data.groups)).toHaveLength(2); expect(store.data.groups).toMatchObject({ foo: "foo", bar: "bar" }); }); - - it("updates groups with new hash after fetch", () => { - const store = new AlertStore(["label=value"]); - store.data.groups = [ - { id: "foo", hash: "foo" }, - { id: "bar", hash: "bar" } - ]; - - const response = EmptyAPIResponse(); - response.groups = [ - { id: "foo", hash: "newFoo" }, - { id: "bar", hash: "newBar" } - ]; - - store.parseAPIResponse(response); - expect(store.data.groups).toHaveLength(2); - expect(store.data.groups).toMatchObject([ - { id: "foo", hash: "newFoo" }, - { id: "bar", hash: "newBar" } - ]); - }); }); diff --git a/ui/src/__mocks__/Alerts.js b/ui/src/__mocks__/Alerts.js index afec1d72a..d09fce329 100644 --- a/ui/src/__mocks__/Alerts.js +++ b/ui/src/__mocks__/Alerts.js @@ -35,7 +35,6 @@ const MockAlertGroup = ( labels: rootLabels, alerts: alerts, id: "099c5ca6d1c92f615b13056b935d0c8dee70f18c", - hash: "53a4bb3d7e916450b3bda550976f9578db5b2ad3", alertmanagerCount: { default: 1 }, diff --git a/ui/src/__mocks__/Stories.js b/ui/src/__mocks__/Stories.js index 5952976d0..4932fc4e0 100644 --- a/ui/src/__mocks__/Stories.js +++ b/ui/src/__mocks__/Stories.js @@ -185,7 +185,6 @@ const MockGrid = alertStore => { const unprocessed = Math.max(0, i - active - suppressed); const id = `id${i}`; - const hash = `hash${i}`; const group = MockGroup(`group${i}`, i, active, suppressed, unprocessed); for (let j = 0; j < group.alerts.length; j++) { @@ -207,7 +206,6 @@ const MockGrid = alertStore => { } group.id = id; - group.hash = hash; group.stateCount.active = active; group.stateCount.suppressed = suppressed; group.stateCount.unprocessed = unprocessed;