mirror of
https://github.com/prymitive/karma
synced 2026-02-13 20:59:53 +00:00
Rename models, strip Unsee prefix
Now that models package contains only unsee specific models rename everything stripping Unsee prefix from names
This commit is contained in:
@@ -21,8 +21,8 @@ func init() {
|
||||
|
||||
// GetAlerts will send request to Alertmanager and return list of alert groups
|
||||
// from the API
|
||||
func GetAlerts(version string) ([]models.UnseeAlertGroup, error) {
|
||||
groups := []models.UnseeAlertGroup{}
|
||||
func GetAlerts(version string) ([]models.AlertGroup, error) {
|
||||
groups := []models.AlertGroup{}
|
||||
|
||||
mapper, err := mapper.GetAlertMapper(version)
|
||||
if err != nil {
|
||||
@@ -40,8 +40,8 @@ func GetAlerts(version string) ([]models.UnseeAlertGroup, error) {
|
||||
|
||||
// GetSilences will send request to Alertmanager and return list of silences
|
||||
// from the API
|
||||
func GetSilences(version string) ([]models.UnseeSilence, error) {
|
||||
silences := []models.UnseeSilence{}
|
||||
func GetSilences(version string) ([]models.Silence, error) {
|
||||
silences := []models.Silence{}
|
||||
|
||||
mapper, err := mapper.GetSilenceMapper(version)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,7 +21,7 @@ func getFiltersFromQuery(filterString string) ([]filters.FilterT, bool) {
|
||||
return matchFilters, validFilters
|
||||
}
|
||||
|
||||
func countLabel(countStore models.UnseeCountMap, key string, val string) {
|
||||
func countLabel(countStore models.LabelsCountMap, key string, val string) {
|
||||
if _, found := countStore[key]; !found {
|
||||
countStore[key] = make(map[string]int)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"github.com/cloudflare/unsee/models"
|
||||
)
|
||||
|
||||
type autocompleteFactory func(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete
|
||||
type autocompleteFactory func(name string, operators []string, alerts []models.Alert) []models.Autocomplete
|
||||
|
||||
func makeAC(value string, tokens []string) models.UnseeAutocomplete {
|
||||
acHint := models.UnseeAutocomplete{
|
||||
func makeAC(value string, tokens []string) models.Autocomplete {
|
||||
acHint := models.Autocomplete{
|
||||
Value: value,
|
||||
Tokens: tokens,
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package filters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
"regexp"
|
||||
"strings"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
)
|
||||
|
||||
// FilterT provides methods for interacting with alert filters
|
||||
type FilterT interface {
|
||||
init(name string, matcher *matcherT, rawText string, isValid bool, value string)
|
||||
Match(alert *models.UnseeAlert, matches int) bool
|
||||
Match(alert *models.Alert, matches int) bool
|
||||
GetRawText() string
|
||||
GetHits() int
|
||||
GetIsValid() bool
|
||||
|
||||
@@ -2,9 +2,9 @@ package filters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
)
|
||||
|
||||
type ageFilter struct {
|
||||
@@ -30,7 +30,7 @@ func (filter *ageFilter) init(name string, matcher *matcherT, rawText string, is
|
||||
}
|
||||
}
|
||||
|
||||
func (filter *ageFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *ageFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
ts := time.Now().Add(filter.Value.(time.Duration))
|
||||
isMatch := filter.Matcher.Compare(int(ts.Unix()), int(alert.StartsAt.Unix()))
|
||||
@@ -48,8 +48,8 @@ func newAgeFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func ageAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := []models.UnseeAutocomplete{}
|
||||
func ageAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := []models.Autocomplete{}
|
||||
for _, operator := range operators {
|
||||
tokens = append(tokens, makeAC(
|
||||
fmt.Sprintf("%s%s10m", name, operator),
|
||||
|
||||
@@ -25,7 +25,7 @@ func (filter *fuzzyFilter) init(name string, matcher *matcherT, rawText string,
|
||||
}
|
||||
}
|
||||
|
||||
func (filter *fuzzyFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *fuzzyFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
for _, val := range alert.Annotations {
|
||||
if filter.Matcher.Compare(val, filter.Value) {
|
||||
|
||||
@@ -2,16 +2,16 @@ package filters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
)
|
||||
|
||||
type labelFilter struct {
|
||||
alertFilter
|
||||
}
|
||||
|
||||
func (filter *labelFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *labelFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
isMatch := filter.Matcher.Compare(alert.Labels[filter.Matched], filter.Value)
|
||||
if isMatch {
|
||||
@@ -28,8 +28,8 @@ func newLabelFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func labelAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := map[string]models.UnseeAutocomplete{}
|
||||
func labelAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := map[string]models.Autocomplete{}
|
||||
for _, alert := range alerts {
|
||||
for key, value := range alert.Labels {
|
||||
for _, operator := range operators {
|
||||
@@ -76,7 +76,7 @@ func labelAutocomplete(name string, operators []string, alerts []models.UnseeAle
|
||||
}
|
||||
}
|
||||
}
|
||||
acData := []models.UnseeAutocomplete{}
|
||||
acData := []models.Autocomplete{}
|
||||
for _, token := range tokens {
|
||||
acData = append(acData, token)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package filters
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
"github.com/cloudflare/unsee/models"
|
||||
)
|
||||
|
||||
type limitFilter struct {
|
||||
@@ -28,7 +28,7 @@ func (filter *limitFilter) init(name string, matcher *matcherT, rawText string,
|
||||
}
|
||||
}
|
||||
|
||||
func (filter *limitFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *limitFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
if matches < filter.Value.(int) {
|
||||
return true
|
||||
@@ -45,8 +45,8 @@ func newLimitFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func limitAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := []models.UnseeAutocomplete{}
|
||||
func limitAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := []models.Autocomplete{}
|
||||
for _, operator := range operators {
|
||||
tokens = append(tokens, makeAC(
|
||||
fmt.Sprintf("%s%s10", name, operator),
|
||||
|
||||
@@ -12,7 +12,7 @@ type silenceAuthorFilter struct {
|
||||
alertFilter
|
||||
}
|
||||
|
||||
func (filter *silenceAuthorFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *silenceAuthorFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
var isMatch bool
|
||||
if alert.Silenced != "" {
|
||||
@@ -36,8 +36,8 @@ func newSilenceAuthorFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func sinceAuthorAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := map[string]models.UnseeAutocomplete{}
|
||||
func sinceAuthorAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := map[string]models.Autocomplete{}
|
||||
for _, alert := range alerts {
|
||||
if alert.Silenced != "" {
|
||||
if silence := store.Store.GetSilence(alert.Silenced); silence != nil {
|
||||
@@ -53,7 +53,7 @@ func sinceAuthorAutocomplete(name string, operators []string, alerts []models.Un
|
||||
}
|
||||
}
|
||||
}
|
||||
acData := []models.UnseeAutocomplete{}
|
||||
acData := []models.Autocomplete{}
|
||||
for _, token := range tokens {
|
||||
acData = append(acData, token)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type silenceJiraFilter struct {
|
||||
alertFilter
|
||||
}
|
||||
|
||||
func (filter *silenceJiraFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *silenceJiraFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
var isMatch bool
|
||||
if alert.Silenced != "" {
|
||||
@@ -36,8 +36,8 @@ func newSilenceJiraFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func sinceJiraIDAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := map[string]models.UnseeAutocomplete{}
|
||||
func sinceJiraIDAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := map[string]models.Autocomplete{}
|
||||
for _, alert := range alerts {
|
||||
if alert.Silenced != "" {
|
||||
silence := store.Store.GetSilence(alert.Silenced)
|
||||
@@ -54,7 +54,7 @@ func sinceJiraIDAutocomplete(name string, operators []string, alerts []models.Un
|
||||
}
|
||||
}
|
||||
}
|
||||
acData := []models.UnseeAutocomplete{}
|
||||
acData := []models.Autocomplete{}
|
||||
for _, token := range tokens {
|
||||
acData = append(acData, token)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (filter *silencedFilter) init(name string, matcher *matcherT, rawText strin
|
||||
}
|
||||
}
|
||||
|
||||
func (filter *silencedFilter) Match(alert *models.UnseeAlert, matches int) bool {
|
||||
func (filter *silencedFilter) Match(alert *models.Alert, matches int) bool {
|
||||
if filter.IsValid {
|
||||
var isSilenced bool
|
||||
isSilenced = (alert.Silenced != "")
|
||||
@@ -47,8 +47,8 @@ func newSilencedFilter() FilterT {
|
||||
return &f
|
||||
}
|
||||
|
||||
func silencedAutocomplete(name string, operators []string, alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
tokens := []models.UnseeAutocomplete{}
|
||||
func silencedAutocomplete(name string, operators []string, alerts []models.Alert) []models.Autocomplete {
|
||||
tokens := []models.Autocomplete{}
|
||||
for _, operator := range operators {
|
||||
switch operator {
|
||||
case equalOperator:
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
type filterTest struct {
|
||||
Expression string
|
||||
IsValid bool
|
||||
Alert models.UnseeAlert
|
||||
Silence models.UnseeSilence
|
||||
Alert models.Alert
|
||||
Silence models.Silence
|
||||
IsMatch bool
|
||||
}
|
||||
|
||||
@@ -22,25 +22,25 @@ var tests = []filterTest{
|
||||
filterTest{
|
||||
Expression: "@silenced=true",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{},
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silenced!=true",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{},
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silenced=true",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silenced!=true",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
@@ -51,225 +51,225 @@ var tests = []filterTest{
|
||||
filterTest{
|
||||
Expression: "@silence_jira=1",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", JiraID: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", JiraID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira=2",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira!=3",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", JiraID: "x"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", JiraID: "x"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira!=4",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", JiraID: "4"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", JiraID: "4"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira!=5",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira=~abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", JiraID: "xxabcxx"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxabcxx"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_jira=~abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", JiraID: "xxx"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxx"},
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
Expression: "@silence_author=john",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", CreatedBy: "john"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "john"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_author=john",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", CreatedBy: "bob"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "bob"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", CreatedBy: "bob"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "bob"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", CreatedBy: "john"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "john"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
Expression: "@age<1h",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@age>1h",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@age<-1h",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "@age>-1h",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
IsMatch: true,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
Expression: "node=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps1"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{},
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node!=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps1"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node!=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps2"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps2"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node=~vps",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps1"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node!~vps",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps1"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "node!~abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"node": "vps1"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"key": "abc"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"key": "abc"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"key": "XXXabcx"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"key": "XXXabcx"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Labels: map[string]string{"abc": "xxxab"}},
|
||||
Alert: models.Alert{Labels: map[string]string{"abc": "xxxab"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Annotations: map[string]string{"key": "abc"}},
|
||||
Alert: models.Alert{Annotations: map[string]string{"key": "abc"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Annotations: map[string]string{"key": "ccc abc"}},
|
||||
Alert: models.Alert{Annotations: map[string]string{"key": "ccc abc"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Annotations: map[string]string{"abc": "zzz"}},
|
||||
Alert: models.Alert{Annotations: map[string]string{"abc": "zzz"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", Comment: "abc"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", Comment: "abc"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", Comment: "abcxxx"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", Comment: "abcxxx"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", Comment: "ABCD"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", Comment: "ABCD"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{Silenced: "1"},
|
||||
Silence: models.UnseeSilence{ID: "1", Comment: "xzc"},
|
||||
Alert: models.Alert{Silenced: "1"},
|
||||
Silence: models.Silence{ID: "1", Comment: "xzc"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.UnseeAlert{},
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
@@ -281,11 +281,11 @@ var tests = []filterTest{
|
||||
func TestFilters(t *testing.T) {
|
||||
for _, ft := range tests {
|
||||
if &ft.Silence != nil {
|
||||
store.Store.SetSilences(map[string]models.UnseeSilence{
|
||||
store.Store.SetSilences(map[string]models.Silence{
|
||||
ft.Silence.ID: ft.Silence,
|
||||
})
|
||||
} else {
|
||||
store.Store.SetSilences(map[string]models.UnseeSilence{})
|
||||
store.Store.SetSilences(map[string]models.Silence{})
|
||||
}
|
||||
f := filters.NewFilter(ft.Expression)
|
||||
if f == nil {
|
||||
@@ -366,7 +366,7 @@ func TestLimitFilter(t *testing.T) {
|
||||
t.Errorf("[%s] GetIsValid() returned %#v while %#v was expected", ft.Expression, f.GetIsValid(), ft.IsValid)
|
||||
}
|
||||
if f.GetIsValid() {
|
||||
alert := models.UnseeAlert{}
|
||||
alert := models.Alert{}
|
||||
var index int = 0
|
||||
for _, isMatch := range ft.IsMatch {
|
||||
m := f.Match(&alert, index)
|
||||
|
||||
@@ -15,7 +15,7 @@ var (
|
||||
// for a specific range of Alertmanager versions
|
||||
type AlertMapper interface {
|
||||
IsSupported(version string) bool
|
||||
GetAlerts() ([]models.UnseeAlertGroup, error)
|
||||
GetAlerts() ([]models.AlertGroup, error)
|
||||
}
|
||||
|
||||
// RegisterAlertMapper allows to register mapper implementing alert data
|
||||
@@ -39,7 +39,7 @@ func GetAlertMapper(version string) (AlertMapper, error) {
|
||||
type SilenceMapper interface {
|
||||
Release() string
|
||||
IsSupported(version string) bool
|
||||
GetSilences() ([]models.UnseeSilence, error)
|
||||
GetSilences() ([]models.Silence, error)
|
||||
}
|
||||
|
||||
// RegisterSilenceMapper allows to register mapper implementing silence data
|
||||
|
||||
@@ -53,8 +53,8 @@ func (m AlertMapper) IsSupported(version string) bool {
|
||||
|
||||
// GetAlerts will make a request to Alertmanager API and parse the response
|
||||
// It will only return alerts or error (if any)
|
||||
func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
groups := []models.UnseeAlertGroup{}
|
||||
func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
groups := []models.AlertGroup{}
|
||||
resp := alertsGroupsAPISchema{}
|
||||
|
||||
url, err := transport.JoinURL(config.Config.AlertmanagerURI, "api/v1/alerts/groups")
|
||||
@@ -72,10 +72,10 @@ func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
}
|
||||
|
||||
for _, g := range resp.Groups {
|
||||
alertList := models.UnseeAlertList{}
|
||||
alertList := models.AlertList{}
|
||||
for _, b := range g.Blocks {
|
||||
for _, a := range b.Alerts {
|
||||
us := models.UnseeAlert{
|
||||
us := models.Alert{
|
||||
Annotations: a.Annotations,
|
||||
Labels: a.Labels,
|
||||
StartsAt: a.StartsAt,
|
||||
@@ -89,7 +89,7 @@ func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
alertList = append(alertList, us)
|
||||
}
|
||||
}
|
||||
ug := models.UnseeAlertGroup{
|
||||
ug := models.AlertGroup{
|
||||
Labels: g.Labels,
|
||||
Alerts: alertList,
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ func (m SilenceMapper) IsSupported(version string) bool {
|
||||
|
||||
// GetSilences will make a request to Alertmanager API and parse the response
|
||||
// It will only return silences or error (if any)
|
||||
func (m SilenceMapper) GetSilences() ([]models.UnseeSilence, error) {
|
||||
silences := []models.UnseeSilence{}
|
||||
func (m SilenceMapper) GetSilences() ([]models.Silence, error) {
|
||||
silences := []models.Silence{}
|
||||
resp := silenceAPISchema{}
|
||||
|
||||
url, err := transport.JoinURL(config.Config.AlertmanagerURI, "api/v1/silences")
|
||||
@@ -76,7 +76,7 @@ func (m SilenceMapper) GetSilences() ([]models.UnseeSilence, error) {
|
||||
}
|
||||
|
||||
for _, s := range resp.Data.Silences {
|
||||
us := models.UnseeSilence{
|
||||
us := models.Silence{
|
||||
ID: string(s.ID),
|
||||
Matchers: s.Matchers,
|
||||
StartsAt: s.StartsAt,
|
||||
|
||||
@@ -51,8 +51,8 @@ func (m AlertMapper) IsSupported(version string) bool {
|
||||
|
||||
// GetAlerts will make a request to Alertmanager API and parse the response
|
||||
// It will only return alerts or error (if any)
|
||||
func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
groups := []models.UnseeAlertGroup{}
|
||||
func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
groups := []models.AlertGroup{}
|
||||
resp := alertsGroupsAPISchema{}
|
||||
|
||||
url, err := transport.JoinURL(config.Config.AlertmanagerURI, "api/v1/alerts/groups")
|
||||
@@ -70,10 +70,10 @@ func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
}
|
||||
|
||||
for _, g := range resp.Groups {
|
||||
alertList := models.UnseeAlertList{}
|
||||
alertList := models.AlertList{}
|
||||
for _, b := range g.Blocks {
|
||||
for _, a := range b.Alerts {
|
||||
us := models.UnseeAlert{
|
||||
us := models.Alert{
|
||||
Annotations: a.Annotations,
|
||||
Labels: a.Labels,
|
||||
StartsAt: a.StartsAt,
|
||||
@@ -85,7 +85,7 @@ func (m AlertMapper) GetAlerts() ([]models.UnseeAlertGroup, error) {
|
||||
alertList = append(alertList, us)
|
||||
}
|
||||
}
|
||||
ug := models.UnseeAlertGroup{
|
||||
ug := models.AlertGroup{
|
||||
Labels: g.Labels,
|
||||
Alerts: alertList,
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ func (m SilenceMapper) IsSupported(version string) bool {
|
||||
|
||||
// GetSilences will make a request to Alertmanager API and parse the response
|
||||
// It will only return silences or error (if any)
|
||||
func (m SilenceMapper) GetSilences() ([]models.UnseeSilence, error) {
|
||||
silences := []models.UnseeSilence{}
|
||||
func (m SilenceMapper) GetSilences() ([]models.Silence, error) {
|
||||
silences := []models.Silence{}
|
||||
resp := silenceAPISchema{}
|
||||
|
||||
url, err := transport.JoinURL(config.Config.AlertmanagerURI, "api/v1/silences")
|
||||
@@ -67,7 +67,7 @@ func (m SilenceMapper) GetSilences() ([]models.UnseeSilence, error) {
|
||||
}
|
||||
|
||||
for _, s := range resp.Data {
|
||||
us := models.UnseeSilence{
|
||||
us := models.Silence{
|
||||
ID: s.ID,
|
||||
Matchers: s.Matchers,
|
||||
StartsAt: s.StartsAt,
|
||||
|
||||
@@ -2,11 +2,11 @@ package models
|
||||
|
||||
import "time"
|
||||
|
||||
// UnseeSilence is vanilla silence + some additional attributes
|
||||
// Silence is vanilla silence + some additional attributes
|
||||
// Unsee adds JIRA support, it can extract JIRA IDs from comments
|
||||
// extracted ID is used to generate link to JIRA issue
|
||||
// this means Unsee needs to store additional fields for each silence
|
||||
type UnseeSilence struct {
|
||||
type Silence struct {
|
||||
ID string `json:"id"`
|
||||
Matchers []struct {
|
||||
Name string `json:"name"`
|
||||
@@ -23,13 +23,13 @@ type UnseeSilence struct {
|
||||
JiraURL string `json:"jiraURL"`
|
||||
}
|
||||
|
||||
// UnseeAlert is vanilla alert + some additional attributes
|
||||
// Alert is vanilla alert + some additional attributes
|
||||
// unsee extends an alert object with:
|
||||
// * Links map, it's generated from annotations if annotation value is an url
|
||||
// it's pulled out of annotation map and returned under links field,
|
||||
// unsee UI used this to show links differently than other annotations
|
||||
// * Fingerprint, which is a sha1 of the entire alert
|
||||
type UnseeAlert struct {
|
||||
type Alert struct {
|
||||
Annotations map[string]string `json:"annotations"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
StartsAt time.Time `json:"startsAt"`
|
||||
@@ -42,17 +42,17 @@ type UnseeAlert struct {
|
||||
Fingerprint string `json:"-"`
|
||||
}
|
||||
|
||||
// UnseeAlertList is flat list of UnseeAlert objects
|
||||
type UnseeAlertList []UnseeAlert
|
||||
// AlertList is flat list of UnseeAlert objects
|
||||
type AlertList []Alert
|
||||
|
||||
func (a UnseeAlertList) Len() int {
|
||||
func (a AlertList) Len() int {
|
||||
return len(a)
|
||||
|
||||
}
|
||||
func (a UnseeAlertList) Swap(i, j int) {
|
||||
func (a AlertList) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
func (a UnseeAlertList) Less(i, j int) bool {
|
||||
func (a AlertList) Less(i, j int) bool {
|
||||
// compare timestamps, if equal compare fingerprints to stable sort order
|
||||
if a[i].StartsAt.After(a[j].StartsAt) {
|
||||
return true
|
||||
@@ -63,62 +63,62 @@ func (a UnseeAlertList) Less(i, j int) bool {
|
||||
return a[i].Fingerprint < a[j].Fingerprint
|
||||
}
|
||||
|
||||
// UnseeAlertGroup is vanilla Alertmanager group, but alerts are flattened
|
||||
// AlertGroup is vanilla Alertmanager group, but alerts are flattened
|
||||
// There is a hash computed from all alerts, it's used by UI to quickly tell
|
||||
// if there was any change in a group and it needs to refresh it
|
||||
type UnseeAlertGroup struct {
|
||||
type AlertGroup struct {
|
||||
Labels map[string]string `json:"labels"`
|
||||
Alerts UnseeAlertList `json:"alerts"`
|
||||
Alerts AlertList `json:"alerts"`
|
||||
ID string `json:"id"`
|
||||
Hash string `json:"hash"`
|
||||
SilencedCount int `json:"silencedCount"`
|
||||
UnsilencedCount int `json:"unsilencedCount"`
|
||||
}
|
||||
|
||||
// UnseeFilter holds returned data on any filter passed by the user as part of the query
|
||||
type UnseeFilter struct {
|
||||
// Filter holds returned data on any filter passed by the user as part of the query
|
||||
type Filter struct {
|
||||
Text string `json:"text"`
|
||||
Hits int `json:"hits"`
|
||||
IsValid bool `json:"isValid"`
|
||||
}
|
||||
|
||||
// UnseeColor is used by UnseeLabelColor to reprenset colors as RGBA
|
||||
type UnseeColor struct {
|
||||
// Color is used by UnseeLabelColor to reprenset colors as RGBA
|
||||
type Color struct {
|
||||
Red uint8 `json:"red"`
|
||||
Green uint8 `json:"green"`
|
||||
Blue uint8 `json:"blue"`
|
||||
Alpha uint8 `json:"alpha"`
|
||||
}
|
||||
|
||||
// UnseeLabelColor holds color information for labels that should be colored in the UI
|
||||
// LabelColors holds color information for labels that should be colored in the UI
|
||||
// every configured label will have a distinct coloring for each value
|
||||
type UnseeLabelColor struct {
|
||||
Font UnseeColor `json:"font"`
|
||||
Background UnseeColor `json:"background"`
|
||||
type LabelColors struct {
|
||||
Font Color `json:"font"`
|
||||
Background Color `json:"background"`
|
||||
}
|
||||
|
||||
// UnseeColorMap is a map of "Label Key" -> "Label Value" -> UnseeLabelColor
|
||||
type UnseeColorMap map[string]map[string]UnseeLabelColor
|
||||
// LabelsColorMap is a map of "Label Key" -> "Label Value" -> UnseeLabelColors
|
||||
type LabelsColorMap map[string]map[string]LabelColors
|
||||
|
||||
// UnseeCountMap is a map of "Label Key" -> "Label Value" -> number of occurence
|
||||
type UnseeCountMap map[string]map[string]int
|
||||
// LabelsCountMap is a map of "Label Key" -> "Label Value" -> number of occurence
|
||||
type LabelsCountMap map[string]map[string]int
|
||||
|
||||
// UnseeAlertsResponse is the structure of JSON response UI will use to get alert data
|
||||
type UnseeAlertsResponse struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Version string `json:"version"`
|
||||
AlertGroups []UnseeAlertGroup `json:"groups"`
|
||||
Silences map[string]UnseeSilence `json:"silences"`
|
||||
Colors UnseeColorMap `json:"colors"`
|
||||
Filters []UnseeFilter `json:"filters"`
|
||||
Counters UnseeCountMap `json:"counters"`
|
||||
// AlertsResponse is the structure of JSON response UI will use to get alert data
|
||||
type AlertsResponse struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Version string `json:"version"`
|
||||
AlertGroups []AlertGroup `json:"groups"`
|
||||
Silences map[string]Silence `json:"silences"`
|
||||
Colors LabelsColorMap `json:"colors"`
|
||||
Filters []Filter `json:"filters"`
|
||||
Counters LabelsCountMap `json:"counters"`
|
||||
}
|
||||
|
||||
// UnseeAutocomplete is the structure of autocomplete object for filter hints
|
||||
// Autocomplete is the structure of autocomplete object for filter hints
|
||||
// this is internal represenation, not what's returned to the user
|
||||
type UnseeAutocomplete struct {
|
||||
type Autocomplete struct {
|
||||
Value string `json:"value"`
|
||||
Tokens []string `json:"tokens"`
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ var alertListSortTests = []alertListSortTest{
|
||||
}
|
||||
|
||||
func TestUnseeAlertListSort(t *testing.T) {
|
||||
al := models.UnseeAlertList{}
|
||||
al := models.AlertList{}
|
||||
for _, testCase := range alertListSortTests {
|
||||
a := models.UnseeAlert{}
|
||||
a := models.Alert{}
|
||||
a.StartsAt = testCase.startsAt
|
||||
a.Fingerprint = testCase.fingerprint
|
||||
al = append(al, a)
|
||||
|
||||
@@ -8,17 +8,17 @@ import (
|
||||
|
||||
type dataStore struct {
|
||||
Lock sync.RWMutex
|
||||
Alerts []models.UnseeAlertGroup
|
||||
Silences map[string]models.UnseeSilence
|
||||
Colors models.UnseeColorMap
|
||||
Autocomplete []models.UnseeAutocomplete
|
||||
Alerts []models.AlertGroup
|
||||
Silences map[string]models.Silence
|
||||
Colors models.LabelsColorMap
|
||||
Autocomplete []models.Autocomplete
|
||||
}
|
||||
|
||||
// Store will keep all Alertmanager data we collect
|
||||
var Store = dataStore{}
|
||||
|
||||
// GetSilence returns silence data for specific silence id or nil if not found
|
||||
func (ds *dataStore) GetSilence(s string) *models.UnseeSilence {
|
||||
func (ds *dataStore) GetSilence(s string) *models.Silence {
|
||||
ds.Lock.RLock()
|
||||
defer ds.Lock.RUnlock()
|
||||
if silence, found := ds.Silences[s]; found {
|
||||
@@ -28,14 +28,14 @@ func (ds *dataStore) GetSilence(s string) *models.UnseeSilence {
|
||||
}
|
||||
|
||||
// SetSilences allows to update silence list stored internally
|
||||
func (ds *dataStore) SetSilences(s map[string]models.UnseeSilence) {
|
||||
func (ds *dataStore) SetSilences(s map[string]models.Silence) {
|
||||
ds.Lock.Lock()
|
||||
defer ds.Lock.Unlock()
|
||||
ds.Silences = s
|
||||
}
|
||||
|
||||
// Update will lock the store and update internal data
|
||||
func (ds *dataStore) Update(alerts []models.UnseeAlertGroup, colors models.UnseeColorMap, autocomplete []models.UnseeAutocomplete) {
|
||||
func (ds *dataStore) Update(alerts []models.AlertGroup, colors models.LabelsColorMap, autocomplete []models.Autocomplete) {
|
||||
ds.Lock.Lock()
|
||||
defer ds.Lock.Unlock()
|
||||
ds.Alerts = alerts
|
||||
|
||||
@@ -8,37 +8,37 @@ import (
|
||||
)
|
||||
|
||||
type silenceTest struct {
|
||||
silences map[string]models.UnseeSilence
|
||||
silences map[string]models.Silence
|
||||
silenceId string
|
||||
found bool
|
||||
}
|
||||
|
||||
var silenceTests = []silenceTest{
|
||||
silenceTest{
|
||||
silences: map[string]models.UnseeSilence{
|
||||
"1": models.UnseeSilence{},
|
||||
silences: map[string]models.Silence{
|
||||
"1": models.Silence{},
|
||||
},
|
||||
silenceId: "1",
|
||||
found: true,
|
||||
},
|
||||
silenceTest{
|
||||
silences: map[string]models.UnseeSilence{
|
||||
"1": models.UnseeSilence{},
|
||||
"2": models.UnseeSilence{},
|
||||
"3": models.UnseeSilence{},
|
||||
silences: map[string]models.Silence{
|
||||
"1": models.Silence{},
|
||||
"2": models.Silence{},
|
||||
"3": models.Silence{},
|
||||
},
|
||||
silenceId: "2",
|
||||
found: true,
|
||||
},
|
||||
silenceTest{
|
||||
silences: map[string]models.UnseeSilence{},
|
||||
silences: map[string]models.Silence{},
|
||||
silenceId: "1",
|
||||
found: false,
|
||||
},
|
||||
silenceTest{
|
||||
silences: map[string]models.UnseeSilence{
|
||||
"2": models.UnseeSilence{},
|
||||
"3": models.UnseeSilence{},
|
||||
silences: map[string]models.Silence{
|
||||
"2": models.Silence{},
|
||||
"3": models.Silence{},
|
||||
},
|
||||
silenceId: "1",
|
||||
found: false,
|
||||
|
||||
14
timer.go
14
timer.go
@@ -44,7 +44,7 @@ func PullFromAlertmanager() {
|
||||
return
|
||||
}
|
||||
|
||||
silenceStore := make(map[string]models.UnseeSilence)
|
||||
silenceStore := make(map[string]models.Silence)
|
||||
for _, silence := range silences {
|
||||
silence.JiraID, silence.JiraURL = transform.DetectJIRAs(&silence)
|
||||
silenceStore[silence.ID] = silence
|
||||
@@ -52,10 +52,10 @@ func PullFromAlertmanager() {
|
||||
|
||||
store.Store.SetSilences(silenceStore)
|
||||
|
||||
alertStore := []models.UnseeAlertGroup{}
|
||||
colorStore := make(models.UnseeColorMap)
|
||||
alertStore := []models.AlertGroup{}
|
||||
colorStore := make(models.LabelsColorMap)
|
||||
|
||||
acMap := map[string]models.UnseeAutocomplete{}
|
||||
acMap := map[string]models.Autocomplete{}
|
||||
|
||||
// counters used to update metrics
|
||||
var counterAlertsSilenced float64
|
||||
@@ -65,7 +65,7 @@ func PullFromAlertmanager() {
|
||||
// used to generate group content hash
|
||||
agHasher := sha1.New()
|
||||
|
||||
alerts := map[string]models.UnseeAlert{}
|
||||
alerts := map[string]models.Alert{}
|
||||
|
||||
ignoredLabels := []string{}
|
||||
for _, il := range config.Config.StripLabels {
|
||||
@@ -93,7 +93,7 @@ func PullFromAlertmanager() {
|
||||
}
|
||||
|
||||
// reset alerts, we need to deduplicate
|
||||
ag.Alerts = []models.UnseeAlert{}
|
||||
ag.Alerts = []models.Alert{}
|
||||
for _, alert := range alerts {
|
||||
ag.Alerts = append(ag.Alerts, alert)
|
||||
if alert.Silenced != "" {
|
||||
@@ -116,7 +116,7 @@ func PullFromAlertmanager() {
|
||||
alertStore = append(alertStore, ag)
|
||||
}
|
||||
|
||||
acStore := []models.UnseeAutocomplete{}
|
||||
acStore := []models.Autocomplete{}
|
||||
for _, hint := range acMap {
|
||||
acStore = append(acStore, hint)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
// BuildAutocomplete takes an alert object and generates list of autocomplete
|
||||
// strings for it
|
||||
func BuildAutocomplete(alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
acHints := map[string]models.UnseeAutocomplete{}
|
||||
func BuildAutocomplete(alerts []models.Alert) []models.Autocomplete {
|
||||
acHints := map[string]models.Autocomplete{}
|
||||
for _, filterConfig := range filters.AllFilters {
|
||||
if filterConfig.Autocomplete != nil {
|
||||
for _, hint := range filterConfig.Autocomplete(filterConfig.Label, filterConfig.SupportedOperators, alerts) {
|
||||
@@ -16,7 +16,7 @@ func BuildAutocomplete(alerts []models.UnseeAlert) []models.UnseeAutocomplete {
|
||||
}
|
||||
}
|
||||
}
|
||||
acHintsSlice := []models.UnseeAutocomplete{}
|
||||
acHintsSlice := []models.Autocomplete{}
|
||||
for _, hint := range acHints {
|
||||
acHintsSlice = append(acHintsSlice, hint)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ var colorTests = []colorTest{
|
||||
func TestColorLabel(t *testing.T) {
|
||||
for _, testCase := range colorTests {
|
||||
config.Config.ColorLabelsUnique = testCase.config
|
||||
colorStore := models.UnseeColorMap{}
|
||||
colorStore := models.LabelsColorMap{}
|
||||
for key, value := range testCase.labels {
|
||||
transform.ColorLabel(colorStore, key, value)
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ func labelToSeed(key string, val string) int64 {
|
||||
// ColorLabel update UnseeColorMap object with a color object generated
|
||||
// from label key and value passed here
|
||||
// It's used to generate unique colors for configured labels
|
||||
func ColorLabel(colorStore models.UnseeColorMap, key string, val string) {
|
||||
func ColorLabel(colorStore models.LabelsColorMap, key string, val string) {
|
||||
if stringInSlice(config.Config.ColorLabelsUnique, key) == true {
|
||||
if _, found := colorStore[key]; !found {
|
||||
colorStore[key] = make(map[string]models.UnseeLabelColor)
|
||||
colorStore[key] = make(map[string]models.LabelColors)
|
||||
}
|
||||
if _, found := colorStore[key][val]; !found {
|
||||
rand.Seed(labelToSeed(key, val))
|
||||
color := randomcolor.New(randomcolor.Random, randomcolor.LIGHT)
|
||||
red, green, blue, alpha := color.RGBA()
|
||||
bc := models.UnseeColor{
|
||||
bc := models.Color{
|
||||
Red: uint8(red >> 8),
|
||||
Green: uint8(green >> 8),
|
||||
Blue: uint8(blue >> 8),
|
||||
@@ -44,10 +44,10 @@ func ColorLabel(colorStore models.UnseeColorMap, key string, val string) {
|
||||
// uses https://www.w3.org/WAI/ER/WD-AERT/#color-contrast method
|
||||
var brightness int32
|
||||
brightness = ((int32(bc.Red) * 299) + (int32(bc.Green) * 587) + (int32(bc.Blue) * 114)) / 1000
|
||||
var fc models.UnseeColor
|
||||
var fc models.Color
|
||||
if brightness <= 125 {
|
||||
// background color is dark, use white font
|
||||
fc = models.UnseeColor{
|
||||
fc = models.Color{
|
||||
Red: 255,
|
||||
Green: 255,
|
||||
Blue: 255,
|
||||
@@ -55,7 +55,7 @@ func ColorLabel(colorStore models.UnseeColorMap, key string, val string) {
|
||||
}
|
||||
} else {
|
||||
// background color is bright, use dark font
|
||||
fc = models.UnseeColor{
|
||||
fc = models.Color{
|
||||
Red: 44,
|
||||
Green: 62,
|
||||
Blue: 80,
|
||||
@@ -63,7 +63,7 @@ func ColorLabel(colorStore models.UnseeColorMap, key string, val string) {
|
||||
}
|
||||
}
|
||||
|
||||
colorStore[key][val] = models.UnseeLabelColor{
|
||||
colorStore[key][val] = models.LabelColors{
|
||||
Font: fc,
|
||||
Background: bc,
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func ParseRules(rules []string) {
|
||||
// DetectJIRAs will try to find JIRA links in Alertmanager silence objects
|
||||
// using regexp rules from configuration that were parsed and populated
|
||||
// by ParseRules call
|
||||
func DetectJIRAs(silence *models.UnseeSilence) (jiraID, jiraLink string) {
|
||||
func DetectJIRAs(silence *models.Silence) (jiraID, jiraLink string) {
|
||||
for _, jdr := range jiraDetectRules {
|
||||
jiraID := jdr.Regexp.FindString(silence.Comment)
|
||||
if jiraID != "" {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type jiraTest struct {
|
||||
silence models.UnseeSilence
|
||||
silence models.Silence
|
||||
jiraID string
|
||||
jiraLink string
|
||||
}
|
||||
@@ -20,53 +20,53 @@ var jiraRules = []string{
|
||||
|
||||
var jiraTests = []jiraTest{
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "Lorem ipsum dolor sit amet",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "DVOPS-123",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS team",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "a project-1 b",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "a PROJECT- b",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS-1",
|
||||
},
|
||||
jiraID: "DEVOPS-1",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-1",
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS-123",
|
||||
},
|
||||
jiraID: "DEVOPS-123",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-123",
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "a DEVOPS-1 b",
|
||||
},
|
||||
jiraID: "DEVOPS-1",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-1",
|
||||
},
|
||||
jiraTest{
|
||||
silence: models.UnseeSilence{
|
||||
silence: models.Silence{
|
||||
Comment: "PROJECT-9",
|
||||
},
|
||||
jiraID: "PROJECT-9",
|
||||
|
||||
20
views.go
20
views.go
@@ -90,7 +90,7 @@ func alerts(c *gin.Context) {
|
||||
ts, _ := start.UTC().MarshalText()
|
||||
|
||||
// intialize response object, set fields that don't require any locking
|
||||
resp := models.UnseeAlertsResponse{}
|
||||
resp := models.AlertsResponse{}
|
||||
resp.Status = "success"
|
||||
resp.Timestamp = string(ts)
|
||||
resp.Version = version
|
||||
@@ -115,22 +115,22 @@ func alerts(c *gin.Context) {
|
||||
}
|
||||
|
||||
// get filters
|
||||
apiFilters := []models.UnseeFilter{}
|
||||
apiFilters := []models.Filter{}
|
||||
matchFilters, validFilters := getFiltersFromQuery(c.Query("q"))
|
||||
|
||||
// set pointers for data store objects, need a lock until end of view is reached
|
||||
alerts := []models.UnseeAlertGroup{}
|
||||
silences := map[string]models.UnseeSilence{}
|
||||
colors := models.UnseeColorMap{}
|
||||
counters := models.UnseeCountMap{}
|
||||
alerts := []models.AlertGroup{}
|
||||
silences := map[string]models.Silence{}
|
||||
colors := models.LabelsColorMap{}
|
||||
counters := models.LabelsCountMap{}
|
||||
store.Store.Lock.RLock()
|
||||
|
||||
var matches int
|
||||
for _, ag := range store.Store.Alerts {
|
||||
agCopy := models.UnseeAlertGroup{
|
||||
agCopy := models.AlertGroup{
|
||||
ID: ag.ID,
|
||||
Labels: ag.Labels,
|
||||
Alerts: []models.UnseeAlert{},
|
||||
Alerts: []models.Alert{},
|
||||
}
|
||||
h := sha1.New()
|
||||
|
||||
@@ -169,7 +169,7 @@ func alerts(c *gin.Context) {
|
||||
if keyMap, foundKey := store.Store.Colors[key]; foundKey {
|
||||
if color, foundColor := keyMap[value]; foundColor {
|
||||
if _, found := colors[key]; !found {
|
||||
colors[key] = map[string]models.UnseeLabelColor{}
|
||||
colors[key] = map[string]models.LabelColors{}
|
||||
}
|
||||
colors[key][value] = color
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func alerts(c *gin.Context) {
|
||||
resp.Counters = counters
|
||||
|
||||
for _, filter := range matchFilters {
|
||||
af := models.UnseeFilter{
|
||||
af := models.Filter{
|
||||
Text: filter.GetRawText(),
|
||||
Hits: filter.GetHits(),
|
||||
IsValid: filter.GetIsValid(),
|
||||
|
||||
@@ -116,7 +116,7 @@ func TestAlerts(t *testing.T) {
|
||||
t.Errorf("GET /alerts.json returned status %d", resp.Code)
|
||||
}
|
||||
|
||||
ur := models.UnseeAlertsResponse{}
|
||||
ur := models.AlertsResponse{}
|
||||
json.Unmarshal(resp.Body.Bytes(), &ur)
|
||||
if len(ur.Filters) != 2 {
|
||||
t.Errorf("[%s] No filters in response", version)
|
||||
|
||||
Reference in New Issue
Block a user