mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Refactor time durations (#58484)
This change uses `time.Second` in place of `1000 * time.Millisecond` and `time.Minute` in place of `60*time.Second`.
This commit is contained in:
parent
6ac43c9cb4
commit
c02003af3c
@ -26,7 +26,7 @@ type WebdavUploader struct {
|
||||
var netTransport = &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 60 * time.Second,
|
||||
Timeout: time.Minute,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ func TestIntegrationAlertNotificationSQLAccess(t *testing.T) {
|
||||
err := store.UpdateAlertNotification(context.Background(), newCmd)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "NewName", newCmd.Result.Name)
|
||||
require.Equal(t, 60*time.Second, newCmd.Result.Frequency)
|
||||
require.Equal(t, time.Minute, newCmd.Result.Frequency)
|
||||
require.True(t, newCmd.Result.DisableResolveMessage)
|
||||
})
|
||||
|
||||
|
@ -542,7 +542,7 @@ func TestService_GetHttpTransport(t *testing.T) {
|
||||
func TestService_getTimeout(t *testing.T) {
|
||||
cfg := &setting.Cfg{}
|
||||
originalTimeout := sdkhttpclient.DefaultTimeoutOptions.Timeout
|
||||
sdkhttpclient.DefaultTimeoutOptions.Timeout = 60 * time.Second
|
||||
sdkhttpclient.DefaultTimeoutOptions.Timeout = time.Minute
|
||||
t.Cleanup(func() {
|
||||
sdkhttpclient.DefaultTimeoutOptions.Timeout = originalTimeout
|
||||
})
|
||||
@ -551,9 +551,9 @@ func TestService_getTimeout(t *testing.T) {
|
||||
jsonData *simplejson.Json
|
||||
expectedTimeout time.Duration
|
||||
}{
|
||||
{jsonData: simplejson.New(), expectedTimeout: 60 * time.Second},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": nil}), expectedTimeout: 60 * time.Second},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": 0}), expectedTimeout: 60 * time.Second},
|
||||
{jsonData: simplejson.New(), expectedTimeout: time.Minute},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": nil}), expectedTimeout: time.Minute},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": 0}), expectedTimeout: time.Minute},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": 1}), expectedTimeout: time.Second},
|
||||
{jsonData: simplejson.NewFromAny(map[string]interface{}{"timeout": "2"}), expectedTimeout: 2 * time.Second},
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ type Data struct {
|
||||
func postTestData() {
|
||||
i := 0
|
||||
for {
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
time.Sleep(time.Second)
|
||||
num1 := rand.Intn(10)
|
||||
num2 := rand.Intn(10)
|
||||
d := Data{
|
||||
|
@ -75,7 +75,7 @@ func WithCheckConfig(interval time.Duration, maxChecks int) ManagerOption {
|
||||
|
||||
const (
|
||||
defaultCheckInterval = 5 * time.Second
|
||||
defaultDatasourceCheckInterval = 60 * time.Second
|
||||
defaultDatasourceCheckInterval = time.Minute
|
||||
defaultMaxChecks = 3
|
||||
)
|
||||
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
screenshotCacheTTL = 60 * time.Second
|
||||
screenshotTimeout = 10 * time.Second
|
||||
screenshotCacheTTL = time.Minute
|
||||
)
|
||||
|
||||
// DeleteExpiredService is a service to delete expired images.
|
||||
|
@ -38,7 +38,7 @@ func setupAMTest(t *testing.T) *Alertmanager {
|
||||
s := &store.DBstore{
|
||||
Cfg: setting.UnifiedAlertingSettings{
|
||||
BaseInterval: 10 * time.Second,
|
||||
DefaultRuleEvaluationInterval: 60 * time.Second,
|
||||
DefaultRuleEvaluationInterval: time.Minute,
|
||||
},
|
||||
SQLStore: sqlStore,
|
||||
Logger: log.New("alertmanager-test"),
|
||||
|
@ -2170,7 +2170,7 @@ func printAllAnnotations(annos map[int64]annotations.Item) string {
|
||||
|
||||
func TestStaleResultsHandler(t *testing.T) {
|
||||
evaluationTime := time.Now()
|
||||
interval := 60 * time.Second
|
||||
interval := time.Minute
|
||||
|
||||
ctx := context.Background()
|
||||
_, dbstore := tests.SetupTestEnv(t, 1)
|
||||
|
@ -202,7 +202,7 @@ func TestSetEndsAt(t *testing.T) {
|
||||
name: "more than resend delay: for=1m,interval=5m - endsAt = interval * 3",
|
||||
expected: evaluationTime.Add(time.Second * 300 * 3),
|
||||
testRule: &ngmodels.AlertRule{
|
||||
For: 60 * time.Second,
|
||||
For: time.Minute,
|
||||
IntervalSeconds: 300,
|
||||
},
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ const (
|
||||
alertmanagerDefaultPeerTimeout = 15 * time.Second
|
||||
alertmanagerDefaultGossipInterval = cluster.DefaultGossipInterval
|
||||
alertmanagerDefaultPushPullInterval = cluster.DefaultPushPullInterval
|
||||
alertmanagerDefaultConfigPollInterval = 60 * time.Second
|
||||
alertmanagerDefaultConfigPollInterval = time.Minute
|
||||
// To start, the alertmanager needs at least one route defined.
|
||||
// TODO: we should move this to Grafana settings and define this as the default.
|
||||
alertmanagerDefaultConfiguration = `{
|
||||
@ -45,7 +45,7 @@ const (
|
||||
}
|
||||
`
|
||||
evaluatorDefaultEvaluationTimeout = 30 * time.Second
|
||||
schedulerDefaultAdminConfigPollInterval = 60 * time.Second
|
||||
schedulerDefaultAdminConfigPollInterval = time.Minute
|
||||
schedulereDefaultExecuteAlerts = true
|
||||
schedulerDefaultMaxAttempts = 3
|
||||
schedulerDefaultLegacyMinInterval = 1
|
||||
|
@ -17,14 +17,14 @@ func TestCfg_ReadUnifiedAlertingSettings(t *testing.T) {
|
||||
|
||||
// It sets the correct defaults.
|
||||
{
|
||||
require.Equal(t, 60*time.Second, cfg.UnifiedAlerting.AdminConfigPollInterval)
|
||||
require.Equal(t, 60*time.Second, cfg.UnifiedAlerting.AlertmanagerConfigPollInterval)
|
||||
require.Equal(t, time.Minute, cfg.UnifiedAlerting.AdminConfigPollInterval)
|
||||
require.Equal(t, time.Minute, cfg.UnifiedAlerting.AlertmanagerConfigPollInterval)
|
||||
require.Equal(t, 15*time.Second, cfg.UnifiedAlerting.HAPeerTimeout)
|
||||
require.Equal(t, "0.0.0.0:9094", cfg.UnifiedAlerting.HAListenAddr)
|
||||
require.Equal(t, "", cfg.UnifiedAlerting.HAAdvertiseAddr)
|
||||
require.Len(t, cfg.UnifiedAlerting.HAPeers, 0)
|
||||
require.Equal(t, 200*time.Millisecond, cfg.UnifiedAlerting.HAGossipInterval)
|
||||
require.Equal(t, 60*time.Second, cfg.UnifiedAlerting.HAPushPullInterval)
|
||||
require.Equal(t, time.Minute, cfg.UnifiedAlerting.HAPushPullInterval)
|
||||
}
|
||||
|
||||
// With peers set, it correctly parses them.
|
||||
@ -66,7 +66,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
||||
verifyCfg: func(t *testing.T, cfg Cfg) {
|
||||
require.Equal(t, 120*time.Second, cfg.UnifiedAlerting.AdminConfigPollInterval)
|
||||
require.Equal(t, int64(6), cfg.UnifiedAlerting.MaxAttempts)
|
||||
require.Equal(t, 60*time.Second, cfg.UnifiedAlerting.MinInterval)
|
||||
require.Equal(t, time.Minute, cfg.UnifiedAlerting.MinInterval)
|
||||
require.Equal(t, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||
require.Equal(t, 90*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
||||
|
@ -266,7 +266,7 @@ func TestAdminConfiguration_SendingToExternalAlertmanagers(t *testing.T) {
|
||||
{
|
||||
require.Eventually(t, func() bool {
|
||||
return fakeAM1.AlertsCount() == 1 && fakeAM2.AlertsCount() == 1
|
||||
}, 60*time.Second, 5*time.Second)
|
||||
}, time.Minute, 5*time.Second)
|
||||
}
|
||||
|
||||
// Add an alertmanager datasource fot the other organisation
|
||||
|
@ -63,7 +63,7 @@ const (
|
||||
logStreamIdentifierInternal = "__logstream__grafana_internal__"
|
||||
|
||||
alertMaxAttempts = 8
|
||||
alertPollPeriod = 1000 * time.Millisecond
|
||||
alertPollPeriod = time.Second
|
||||
logsQueryMode = "Logs"
|
||||
|
||||
// QueryTypes
|
||||
|
@ -121,8 +121,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb1"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -136,8 +136,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb2"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -185,8 +185,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb1 Sum"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -200,8 +200,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb2 Average"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -248,8 +248,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb3"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -263,8 +263,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb4"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
@ -307,8 +307,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb3"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{},
|
||||
StatusCode: aws.String("Complete"),
|
||||
@ -346,8 +346,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb3"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{},
|
||||
StatusCode: aws.String("Complete"),
|
||||
@ -432,8 +432,8 @@ func TestCloudWatchResponseParser(t *testing.T) {
|
||||
Label: aws.String("lb"),
|
||||
Timestamps: []*time.Time{
|
||||
aws.Time(timestamp),
|
||||
aws.Time(timestamp.Add(60 * time.Second)),
|
||||
aws.Time(timestamp.Add(180 * time.Second)),
|
||||
aws.Time(timestamp.Add(time.Minute)),
|
||||
aws.Time(timestamp.Add(3 * time.Minute)),
|
||||
},
|
||||
Values: []*float64{
|
||||
aws.Float64(10),
|
||||
|
@ -27,8 +27,8 @@ func TestIntervalCalculator_Calculate(t *testing.T) {
|
||||
{"from 15m to now and 100 resolution", backend.TimeRange{From: timeNow, To: timeNow.Add(15 * time.Minute)}, 100, "10s"},
|
||||
{"from 30m to now and default resolution", backend.TimeRange{From: timeNow, To: timeNow.Add(30 * time.Minute)}, 0, "1s"},
|
||||
{"from 30m to now and 3000 resolution", backend.TimeRange{From: timeNow, To: timeNow.Add(30 * time.Minute)}, 3000, "500ms"},
|
||||
{"from 1h to now and default resolution", backend.TimeRange{From: timeNow, To: timeNow.Add(60 * time.Minute)}, 0, "2s"},
|
||||
{"from 1h to now and 1000 resoluion", backend.TimeRange{From: timeNow, To: timeNow.Add(60 * time.Minute)}, 1000, "5s"},
|
||||
{"from 1h to now and default resolution", backend.TimeRange{From: timeNow, To: timeNow.Add(time.Hour)}, 0, "2s"},
|
||||
{"from 1h to now and 1000 resoluion", backend.TimeRange{From: timeNow, To: timeNow.Add(time.Hour)}, 1000, "5s"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
@ -933,7 +933,7 @@ func TestMSSQL(t *testing.T) {
|
||||
}
|
||||
|
||||
events := []*event{}
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), 60*time.Minute, 25*time.Minute) {
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), time.Hour, 25*time.Minute) {
|
||||
events = append(events, &event{
|
||||
TimeSec: t.Unix(),
|
||||
Description: "Someone deployed something",
|
||||
|
@ -905,7 +905,7 @@ func TestIntegrationMySQL(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
events := []*event{}
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), 60*time.Minute, 25*time.Minute) {
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), time.Hour, 25*time.Minute) {
|
||||
events = append(events, &event{
|
||||
TimeSec: t.Unix(),
|
||||
Description: "Someone deployed something",
|
||||
|
@ -1003,7 +1003,7 @@ func TestIntegrationPostgres(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
events := []*event{}
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), 60*time.Minute, 25*time.Minute) {
|
||||
for _, t := range genTimeRangeByInterval(fromStart.Add(-20*time.Minute), time.Hour, 25*time.Minute) {
|
||||
events = append(events, &event{
|
||||
TimeSec: t.Unix(),
|
||||
Description: "Someone deployed something",
|
||||
|
Loading…
Reference in New Issue
Block a user