mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-06-25 11:38:49 +03:00
Compare commits
1 Commits
issue-1116
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac82971faa |
6
.github/workflows/codeql-analysis-go.yml
vendored
6
.github/workflows/codeql-analysis-go.yml
vendored
@@ -54,14 +54,14 @@ jobs:
|
||||
restore-keys: go-artifacts-${{ runner.os }}-codeql-analyze-${{ steps.go.outputs.go-version }}-
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
|
||||
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||
with:
|
||||
languages: go
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
|
||||
uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
|
||||
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
|
||||
with:
|
||||
category: 'language:go'
|
||||
|
||||
@@ -236,11 +236,11 @@ func NewAlertAPI(ar *AlertingRule, a *notifier.Alert) *ApiAlert {
|
||||
return aa
|
||||
}
|
||||
|
||||
func (r *ApiRule) ExtendState(normalizeAlertState bool) {
|
||||
if !normalizeAlertState && len(r.Alerts) > 0 {
|
||||
func (r *ApiRule) ExtendState() {
|
||||
if len(r.Alerts) > 0 {
|
||||
return
|
||||
}
|
||||
if r.State == "" || r.State == "inactive" || r.State == "pending" || r.State == "firing" {
|
||||
if r.State == "" {
|
||||
r.State = "ok"
|
||||
}
|
||||
if r.Health != "ok" {
|
||||
|
||||
@@ -54,26 +54,6 @@ func TestRecordingToApi(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApiRuleExtendStateForWeb(t *testing.T) {
|
||||
seriesFetched := 1
|
||||
r := ApiRule{
|
||||
State: "firing",
|
||||
Health: "ok",
|
||||
LastSeriesFetched: &seriesFetched,
|
||||
Alerts: []*ApiAlert{{State: "firing"}},
|
||||
}
|
||||
|
||||
r.ExtendState(false)
|
||||
if r.State != "firing" {
|
||||
t.Fatalf("expected alert rule state to expect %q; got %q", "firing", r.State)
|
||||
}
|
||||
|
||||
r.ExtendState(true)
|
||||
if r.State != "ok" {
|
||||
t.Fatalf("expected alert rule state to expect %q; got %q", "ok", r.State)
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLValuesToStrings(t *testing.T) {
|
||||
mapQueryParams := map[string][]string{
|
||||
"param1": {"param1"},
|
||||
|
||||
@@ -122,9 +122,6 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
|
||||
httpserver.Errorf(w, r, "%s", err)
|
||||
return true
|
||||
}
|
||||
if r.URL.Path == "/vmalert/groups" {
|
||||
rf.normalizeAlertState = true
|
||||
}
|
||||
// only support filtering by a single state
|
||||
state := ""
|
||||
if len(rf.states) > 0 {
|
||||
@@ -374,17 +371,16 @@ func newAlertsFilter(r *http.Request) (*alertsFilter, *httpserver.ErrorWithStatu
|
||||
|
||||
// see https://prometheus.io/docs/prometheus/latest/querying/api/#rules
|
||||
type rulesFilter struct {
|
||||
gf *groupsFilter
|
||||
ruleNames []string
|
||||
ruleType string
|
||||
excludeAlerts bool
|
||||
states []string
|
||||
maxGroups int
|
||||
pageNum int
|
||||
search string
|
||||
match [][]metricsql.LabelFilter
|
||||
extendedStates bool
|
||||
normalizeAlertState bool
|
||||
gf *groupsFilter
|
||||
ruleNames []string
|
||||
ruleType string
|
||||
excludeAlerts bool
|
||||
states []string
|
||||
maxGroups int
|
||||
pageNum int
|
||||
search string
|
||||
match [][]metricsql.LabelFilter
|
||||
extendedStates bool
|
||||
}
|
||||
|
||||
func newRulesFilter(r *http.Request) (*rulesFilter, *httpserver.ErrorWithStatusCode) {
|
||||
@@ -547,10 +543,8 @@ func (rh *requestHandler) groups(rf *rulesFilter) *listGroupsResponse {
|
||||
if !groupFound && !strings.Contains(strings.ToLower(rule.Name), rf.search) {
|
||||
continue
|
||||
}
|
||||
ruleWithExtendedState := rule
|
||||
ruleWithExtendedState.ExtendState(rf.normalizeAlertState)
|
||||
if rf.extendedStates {
|
||||
rule = ruleWithExtendedState
|
||||
rule.ExtendState()
|
||||
}
|
||||
if !rf.matchesRule(&rule) {
|
||||
continue
|
||||
@@ -558,7 +552,7 @@ func (rh *requestHandler) groups(rf *rulesFilter) *listGroupsResponse {
|
||||
if rf.excludeAlerts {
|
||||
rule.Alerts = nil
|
||||
}
|
||||
g.States[ruleWithExtendedState.State]++
|
||||
g.States[rule.State]++
|
||||
filteredRules = append(filteredRules, rule)
|
||||
}
|
||||
if len(g.Rules) == 0 || len(filteredRules) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user