|
|
|
@ -4,8 +4,9 @@ import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models" |
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestCanBeInstant(t *testing.T) { |
|
|
|
@ -20,31 +21,24 @@ func TestCanBeInstant(t *testing.T) { |
|
|
|
|
rule: createMigrateableLokiRule(t), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule where the data array is too short to be migrateable", |
|
|
|
|
expected: false, |
|
|
|
|
rule: createMigrateableLokiRule(t, func(r *models.AlertRule) { |
|
|
|
|
r.Data = []models.AlertQuery{r.Data[0]} |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule that is not a range query", |
|
|
|
|
expected: false, |
|
|
|
|
name: "valid rule with external loki datasource", |
|
|
|
|
expected: true, |
|
|
|
|
rule: createMigrateableLokiRule(t, func(r *models.AlertRule) { |
|
|
|
|
r.Data[0].QueryType = "something-else" |
|
|
|
|
r.Data[0].DatasourceUID = "something-external" |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule that does not use a cloud datasource", |
|
|
|
|
name: "invalid rule where the data array is too short to be migrateable", |
|
|
|
|
expected: false, |
|
|
|
|
rule: createMigrateableLokiRule(t, func(r *models.AlertRule) { |
|
|
|
|
r.Data[0].DatasourceUID = "something-else" |
|
|
|
|
r.Data = []models.AlertQuery{r.Data[0]} |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule that has no aggregation as second item", |
|
|
|
|
name: "invalid rule that is not a range query", |
|
|
|
|
expected: false, |
|
|
|
|
rule: createMigrateableLokiRule(t, func(r *models.AlertRule) { |
|
|
|
|
r.Data[1].DatasourceUID = "something-else" |
|
|
|
|
r.Data[0].QueryType = "something-else" |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
@ -59,6 +53,13 @@ func TestCanBeInstant(t *testing.T) { |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule that has no aggregation as second item", |
|
|
|
|
expected: false, |
|
|
|
|
rule: createMigrateableLokiRule(t, func(r *models.AlertRule) { |
|
|
|
|
r.Data[1].DatasourceUID = "something-else" |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "invalid rule that has not last() pointing to range query", |
|
|
|
|
expected: false, |
|
|
|
@ -120,7 +121,7 @@ func createMigrateableLokiRule(t *testing.T, muts ...func(*models.AlertRule)) *m |
|
|
|
|
{ |
|
|
|
|
RefID: "A", |
|
|
|
|
QueryType: "range", |
|
|
|
|
DatasourceUID: grafanaCloudLogs, |
|
|
|
|
DatasourceUID: "grafanacloud-logs", |
|
|
|
|
Model: []byte(`{ |
|
|
|
|
"datasource": { |
|
|
|
|
"type": "loki", |
|
|
|
|