Merge pull request #354 from prymitive/drop-counters

chore(api): drop counters from API response
This commit is contained in:
Łukasz Mierzwa
2019-01-05 12:33:36 +00:00
committed by GitHub
7 changed files with 1 additions and 75 deletions
-11
View File
@@ -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{}
-47
View File
@@ -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)
}
-4
View File
@@ -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"`
}
+1 -2
View File
@@ -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];
}
-1
View File
@@ -22,7 +22,6 @@ const EmptyAPIResponse = () => ({
isValid: true
}
],
counters: {},
settings: {
staticColorLabels: ["job"],
annotationsDefaultHidden: false,
-7
View File
@@ -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)
-3
View File
@@ -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