From a3ef1dd40e81d25340fd92587591239ac3804d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 12 Dec 2018 23:40:50 +0000 Subject: [PATCH] chore(api): drop counters from API response Not used by any UI code, remove it. --- alerts.go | 11 --------- api_test.go | 47 ------------------------------------- internal/models/api.go | 4 ---- ui/src/Stores/AlertStore.js | 3 +-- ui/src/__mocks__/Fetch.js | 1 - views.go | 7 ------ views_test.go | 3 --- 7 files changed, 1 insertion(+), 75 deletions(-) diff --git a/alerts.go b/alerts.go index 483d02488..5d06bd338 100644 --- a/alerts.go +++ b/alerts.go @@ -22,17 +22,6 @@ func getFiltersFromQuery(filterStrings []string) ([]filters.FilterT, bool) { return matchFilters, validFilters } -func countLabel(countStore models.LabelsCountMap, key string, val string) { - if _, found := countStore[key]; !found { - countStore[key] = make(map[string]int) - } - if _, found := countStore[key][val]; found { - countStore[key][val]++ - } else { - countStore[key][val] = 1 - } -} - func getUpstreams() models.AlertmanagerAPISummary { summary := models.AlertmanagerAPISummary{} diff --git a/api_test.go b/api_test.go index b3e4163a3..a94bc076c 100644 --- a/api_test.go +++ b/api_test.go @@ -647,44 +647,6 @@ var groupTests = []groupTest{ }, } -var countsMap = models.LabelsCountMap{ - "@receiver": map[string]int{ - "by-cluster-service": 12, - "by-name": 12, - }, - "@state": map[string]int{ - "active": 16, - "suppressed": 8, - }, - "alertname": map[string]int{ - "Free_Disk_Space_Too_Low": 2, - "HTTP_Probe_Failed": 4, - "Host_Down": 16, - "Memory_Usage_Too_High": 2, - }, - "cluster": map[string]int{ - "dev": 10, - "prod": 6, - "staging": 8, - }, - "instance": map[string]int{ - "server1": 2, - "server2": 4, - "server3": 2, - "server4": 2, - "server5": 4, - "server6": 2, - "server7": 2, - "server8": 2, - "web1": 2, - "web2": 2, - }, - "job": map[string]int{ - "node_exporter": 8, - "node_ping": 16, - }, -} - var filtersExpected = []models.Filter{} func compareAlertGroups(testCase groupTest, group models.APIAlertGroup) bool { @@ -874,15 +836,6 @@ func TestVerifyAllGroups(t *testing.T) { t.Errorf("[%s] Silences mismatch, expected >0 but got %d", version, len(am)) } - for key, expectedCounts := range countsMap { - gotCounts, foundCounts := ur.Counters[key] - if !foundCounts { - t.Errorf("[%s] Counters missing for key '%s'", version, key) - } else if !reflect.DeepEqual(expectedCounts, gotCounts) { - t.Errorf("[%s] Counters mismatch for key '%s', expected %v but got %v", - version, key, expectedCounts, gotCounts) - } - } if !reflect.DeepEqual(ur.Filters, filtersExpected) { t.Errorf("[%s] Filters mismatch, expected %v but got %v", version, filtersExpected, ur.Filters) } diff --git a/internal/models/api.go b/internal/models/api.go index 68b779310..a20c85fca 100644 --- a/internal/models/api.go +++ b/internal/models/api.go @@ -34,9 +34,6 @@ type LabelColors struct { // LabelsColorMap is a map of "Label Key" -> "Label Value" -> karmaLabelColors type LabelsColorMap map[string]map[string]LabelColors -// LabelsCountMap is a map of "Label Key" -> "Label Value" -> number of occurence -type LabelsCountMap map[string]map[string]int - // APIAlertGroupSharedMaps defines shared part of APIAlertGroup type APIAlertGroupSharedMaps struct { Annotations Annotations `json:"annotations"` @@ -177,7 +174,6 @@ type AlertsResponse struct { TotalAlerts int `json:"totalAlerts"` Colors LabelsColorMap `json:"colors"` Filters []Filter `json:"filters"` - Counters LabelsCountMap `json:"counters"` Settings Settings `json:"settings"` } diff --git a/ui/src/Stores/AlertStore.js b/ui/src/Stores/AlertStore.js index cac899929..d0e7b7fec 100644 --- a/ui/src/Stores/AlertStore.js +++ b/ui/src/Stores/AlertStore.js @@ -137,7 +137,6 @@ class AlertStore { data = observable( { colors: {}, - counters: {}, groups: {}, silences: {}, upstreams: { instances: [], clusters: {} }, @@ -290,7 +289,7 @@ class AlertStore { let updates = {}; // update data dicts if they changed - for (const key of ["colors", "counters", "silences", "upstreams"]) { + for (const key of ["colors", "silences", "upstreams"]) { if (!equal(this.data[key], result[key])) { updates[key] = result[key]; } diff --git a/ui/src/__mocks__/Fetch.js b/ui/src/__mocks__/Fetch.js index 89675a104..7165ac539 100644 --- a/ui/src/__mocks__/Fetch.js +++ b/ui/src/__mocks__/Fetch.js @@ -22,7 +22,6 @@ const EmptyAPIResponse = () => ({ isValid: true } ], - counters: {}, settings: { staticColorLabels: ["job"], annotationsDefaultHidden: false, diff --git a/views.go b/views.go index 1d1a8391c..97ff166eb 100644 --- a/views.go +++ b/views.go @@ -105,8 +105,6 @@ func alerts(c *gin.Context) { // set pointers for data store objects, need a lock until end of view is reached alerts := map[string]models.APIAlertGroup{} colors := models.LabelsColorMap{} - // used for top labels dropdown - counters := models.LabelsCountMap{} dedupedAlerts := alertmanager.DedupAlerts() dedupedColors := alertmanager.DedupColors() @@ -155,9 +153,6 @@ func alerts(c *gin.Context) { alert.UpdateFingerprints() agCopy.Alerts = append(agCopy.Alerts, alert) - countLabel(counters, "@state", alert.State) - - countLabel(counters, "@receiver", alert.Receiver) if ck, foundKey := dedupedColors["@receiver"]; foundKey { if cv, foundVal := ck[alert.Receiver]; foundVal { if _, found := colors["@receiver"]; !found { @@ -186,7 +181,6 @@ func alerts(c *gin.Context) { colors[key][value] = color } } - countLabel(counters, key, value) } } } @@ -226,7 +220,6 @@ func alerts(c *gin.Context) { resp.AlertGroups = alerts resp.Silences = silences resp.Colors = colors - resp.Counters = counters resp.Filters = populateAPIFilters(matchFilters) data, err := json.Marshal(resp) diff --git a/views_test.go b/views_test.go index e36d45ebf..f58a3be53 100644 --- a/views_test.go +++ b/views_test.go @@ -132,9 +132,6 @@ func TestAlerts(t *testing.T) { if ur.Status != "success" { t.Errorf("[%s] Invalid status in response: %s", version, ur.Status) } - if len(ur.Counters) != 6 { - t.Errorf("[%s] Invalid number of counters in response (%d): %v", version, len(ur.Counters), ur.Counters) - } for _, ag := range ur.AlertGroups { for _, a := range ag.Alerts { linkCount := 0