mirror of
https://github.com/prymitive/karma
synced 2026-08-28 11:17:28 +00:00
Merge pull request #109 from prymitive/color-filters
feat(api): always provide color information for foo=bar filters
This commit is contained in:
@@ -10,8 +10,10 @@ import (
|
||||
|
||||
"github.com/prymitive/unsee/internal/alertmanager"
|
||||
"github.com/prymitive/unsee/internal/config"
|
||||
"github.com/prymitive/unsee/internal/filters"
|
||||
"github.com/prymitive/unsee/internal/models"
|
||||
"github.com/prymitive/unsee/internal/slices"
|
||||
"github.com/prymitive/unsee/internal/transform"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -50,6 +52,24 @@ func logAlertsView(c *gin.Context, cacheStatus string, duration time.Duration) {
|
||||
log.Infof("[%s %s] <%d> %s %s took %s", c.ClientIP(), cacheStatus, http.StatusOK, c.Request.Method, c.Request.RequestURI, duration)
|
||||
}
|
||||
|
||||
func populateAPIFilters(matchFilters []filters.FilterT) []models.Filter {
|
||||
apiFilters := []models.Filter{}
|
||||
for _, filter := range matchFilters {
|
||||
af := models.Filter{
|
||||
Text: filter.GetRawText(),
|
||||
Name: filter.GetName(),
|
||||
Matcher: filter.GetMatcher(),
|
||||
Value: filter.GetValue(),
|
||||
Hits: filter.GetHits(),
|
||||
IsValid: filter.GetIsValid(),
|
||||
}
|
||||
if af.Text != "" {
|
||||
apiFilters = append(apiFilters, af)
|
||||
}
|
||||
}
|
||||
return apiFilters
|
||||
}
|
||||
|
||||
// alerts endpoint, json, JS will query this via AJAX call
|
||||
func alerts(c *gin.Context) {
|
||||
noCache(c)
|
||||
@@ -80,7 +100,6 @@ func alerts(c *gin.Context) {
|
||||
}
|
||||
|
||||
// get filters
|
||||
apiFilters := []models.Filter{}
|
||||
matchFilters, validFilters := getFiltersFromQuery(c.QueryArray("q"))
|
||||
|
||||
// set pointers for data store objects, need a lock until end of view is reached
|
||||
@@ -185,25 +204,17 @@ func alerts(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
for _, filter := range matchFilters {
|
||||
if filter.GetValue() != "" && filter.GetMatcher() == "=" {
|
||||
transform.ColorLabel(colors, filter.GetName(), filter.GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
resp.AlertGroups = alerts
|
||||
resp.Silences = silences
|
||||
resp.Colors = colors
|
||||
resp.Counters = counters
|
||||
|
||||
for _, filter := range matchFilters {
|
||||
af := models.Filter{
|
||||
Text: filter.GetRawText(),
|
||||
Name: filter.GetName(),
|
||||
Matcher: filter.GetMatcher(),
|
||||
Value: filter.GetValue(),
|
||||
Hits: filter.GetHits(),
|
||||
IsValid: filter.GetIsValid(),
|
||||
}
|
||||
if af.Text != "" {
|
||||
apiFilters = append(apiFilters, af)
|
||||
}
|
||||
}
|
||||
resp.Filters = apiFilters
|
||||
resp.Filters = populateAPIFilters(matchFilters)
|
||||
|
||||
data, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user