From c432672c14cfb6199e93996e120d16d2525b6313 Mon Sep 17 00:00:00 2001 From: Mustafain Ali Khan Date: Thu, 12 Dec 2024 13:50:47 -0800 Subject: [PATCH] Add license header to fix CI Signed-off-by: Mustafain Ali Khan --- rules/alerting.go | 3 +++ rules/manager.go | 2 +- rules/store.go | 15 ++++++++++++++- rules/store_test.go | 15 ++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/rules/alerting.go b/rules/alerting.go index 1fa3e2bb5..e25028ab2 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -42,6 +42,7 @@ const ( alertMetricName = "ALERTS" // AlertForStateMetricName is the metric name for 'for' state of alert. alertForStateMetricName = "ALERTS_FOR_STATE" + // AlertStateLabel is the label name indicating the state of an alert. alertStateLabel = "alertstate" ) @@ -577,6 +578,8 @@ func (r *AlertingRule) sendAlerts(ctx context.Context, ts time.Time, resendDelay notifyFunc(ctx, r.vector.String(), alerts...) } +// Note that changing format of String() changes value of GetFingerprint() leading to loss of persisted state +// when the `alert-state-persistence` feature is enabled. func (r *AlertingRule) String() string { ar := rulefmt.Rule{ Alert: r.name, diff --git a/rules/manager.go b/rules/manager.go index ad872679a..5dbb1783c 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -129,7 +129,7 @@ type ManagerOptions struct { RuleDependencyController RuleDependencyController AlertStore AlertStore - Metrics *Metrics + Metrics *Metrics } // NewManager returns an implementation of Manager, ready to be started diff --git a/rules/store.go b/rules/store.go index 7dd63a5e2..07f374de8 100644 --- a/rules/store.go +++ b/rules/store.go @@ -1,3 +1,16 @@ +// Copyright 2024 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package rules import ( @@ -65,9 +78,9 @@ func (s *FileStore) initState(registerer prometheus.Registerer) { var data *FileData err = json.NewDecoder(file).Decode(&data) if err != nil { - data = nil s.logger.Error("Failed reading alerts state from file", "err", err) s.storeInitErrors.Inc() + return } alertsByRule := make(map[uint64][]*Alert) if data != nil && data.Alerts != nil { diff --git a/rules/store_test.go b/rules/store_test.go index 398c39bb3..8f649e69a 100644 --- a/rules/store_test.go +++ b/rules/store_test.go @@ -1,3 +1,16 @@ +// Copyright 2024 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package rules import ( @@ -6,9 +19,9 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/promslog" "github.com/stretchr/testify/require" - "github.com/prometheus/common/promslog" "github.com/prometheus/prometheus/model/labels" )