refactor(api): provide configured list of static labels in the API response

DOM data-* attributes are no longer used for this, feed react data store with this config so it can (re)render labels correctly
This commit is contained in:
Łukasz Mierzwa
2018-07-01 22:32:57 +02:00
parent 8b060054d7
commit e1530e01cd
2 changed files with 12 additions and 9 deletions

View File

@@ -33,15 +33,16 @@ type LabelsCountMap map[string]map[string]int
// AlertsResponse is the structure of JSON response UI will use to get alert data
type AlertsResponse struct {
Status string `json:"status"`
Timestamp string `json:"timestamp"`
Version string `json:"version"`
Upstreams AlertmanagerAPISummary `json:"upstreams"`
AlertGroups map[string]AlertGroup `json:"groups"`
TotalAlerts int `json:"totalAlerts"`
Colors LabelsColorMap `json:"colors"`
Filters []Filter `json:"filters"`
Counters LabelsCountMap `json:"counters"`
Status string `json:"status"`
Timestamp string `json:"timestamp"`
Version string `json:"version"`
Upstreams AlertmanagerAPISummary `json:"upstreams"`
AlertGroups map[string]AlertGroup `json:"groups"`
TotalAlerts int `json:"totalAlerts"`
Colors LabelsColorMap `json:"colors"`
Filters []Filter `json:"filters"`
Counters LabelsCountMap `json:"counters"`
StaticColorLabels []string `json:"staticColorLabels"`
}
// Autocomplete is the structure of autocomplete object for filter hints

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/prymitive/unsee/internal/alertmanager"
"github.com/prymitive/unsee/internal/config"
"github.com/prymitive/unsee/internal/models"
"github.com/prymitive/unsee/internal/slices"
@@ -50,6 +51,7 @@ func alerts(c *gin.Context) {
resp.Timestamp = string(ts)
resp.Version = version
resp.Upstreams = getUpstreams()
resp.StaticColorLabels = config.Config.Labels.Color.Static
// use full URI (including query args) as cache key
cacheKey := c.Request.RequestURI