mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix flaky TestAlertInstanceOperations (#41435)
* use UID generator for text
This commit is contained in:
parent
255efc0570
commit
24ad769831
@ -3,12 +3,9 @@ package tests
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/secrets/database"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert"
|
"github.com/grafana/grafana/pkg/services/ngalert"
|
||||||
@ -16,18 +13,17 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||||
|
"github.com/grafana/grafana/pkg/services/secrets/database"
|
||||||
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
|
"github.com/grafana/grafana/pkg/util"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupTestEnv initializes a store to used by the tests.
|
// SetupTestEnv initializes a store to used by the tests.
|
||||||
func SetupTestEnv(t *testing.T, baseInterval time.Duration) (*ngalert.AlertNG, *store.DBstore) {
|
func SetupTestEnv(t *testing.T, baseInterval time.Duration) (*ngalert.AlertNG, *store.DBstore) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@ -54,8 +50,7 @@ func SetupTestEnv(t *testing.T, baseInterval time.Duration) (*ngalert.AlertNG, *
|
|||||||
|
|
||||||
// CreateTestAlertRule creates a dummy alert definition to be used by the tests.
|
// CreateTestAlertRule creates a dummy alert definition to be used by the tests.
|
||||||
func CreateTestAlertRule(t *testing.T, dbstore *store.DBstore, intervalSeconds int64, orgID int64) *models.AlertRule {
|
func CreateTestAlertRule(t *testing.T, dbstore *store.DBstore, intervalSeconds int64, orgID int64) *models.AlertRule {
|
||||||
d := rand.Intn(1000)
|
ruleGroup := fmt.Sprintf("ruleGroup-%s", util.GenerateShortUID())
|
||||||
ruleGroup := fmt.Sprintf("ruleGroup-%d", d)
|
|
||||||
err := dbstore.UpdateRuleGroup(store.UpdateRuleGroupCmd{
|
err := dbstore.UpdateRuleGroup(store.UpdateRuleGroupCmd{
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
NamespaceUID: "namespace",
|
NamespaceUID: "namespace",
|
||||||
@ -68,7 +63,7 @@ func CreateTestAlertRule(t *testing.T, dbstore *store.DBstore, intervalSeconds i
|
|||||||
Annotations: map[string]string{"testAnnoKey": "testAnnoValue"},
|
Annotations: map[string]string{"testAnnoKey": "testAnnoValue"},
|
||||||
},
|
},
|
||||||
GrafanaManagedAlert: &apimodels.PostableGrafanaRule{
|
GrafanaManagedAlert: &apimodels.PostableGrafanaRule{
|
||||||
Title: fmt.Sprintf("an alert definition %d", d),
|
Title: fmt.Sprintf("an alert definition %s", util.GenerateShortUID()),
|
||||||
Condition: "A",
|
Condition: "A",
|
||||||
Data: []models.AlertQuery{
|
Data: []models.AlertQuery{
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user