mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): fixed test issues
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
package alerting
|
package alerting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
|
||||||
"github.com/grafana/grafana/pkg/log"
|
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
_ "github.com/grafana/grafana/pkg/tsdb/graphite"
|
_ "github.com/grafana/grafana/pkg/tsdb/graphite"
|
||||||
)
|
)
|
||||||
@@ -29,15 +26,3 @@ func Init() {
|
|||||||
// go scheduler.executor(&ExecutorImpl{})
|
// go scheduler.executor(&ExecutorImpl{})
|
||||||
// go scheduler.handleResponses()
|
// go scheduler.handleResponses()
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveState(result *AlertResult) {
|
|
||||||
cmd := &m.UpdateAlertStateCommand{
|
|
||||||
AlertId: result.AlertJob.Rule.Id,
|
|
||||||
NewState: result.State,
|
|
||||||
Info: result.Description,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bus.Dispatch(cmd); err != nil {
|
|
||||||
log.Error(2, "failed to save state %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -114,11 +114,11 @@ func (e *Engine) resultHandler() {
|
|||||||
|
|
||||||
result.State = alertstates.Critical
|
result.State = alertstates.Critical
|
||||||
result.Description = fmt.Sprintf("Failed to run check after %d retires, Error: %v", maxRetries, result.Error)
|
result.Description = fmt.Sprintf("Failed to run check after %d retires, Error: %v", maxRetries, result.Error)
|
||||||
saveState(result)
|
e.saveState(result)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.AlertJob.RetryCount = 0
|
result.AlertJob.RetryCount = 0
|
||||||
saveState(result)
|
e.saveState(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestAlertingExecutor(t *testing.T) {
|
func TestAlertingExecutor(t *testing.T) {
|
||||||
Convey("Test alert execution", t, func() {
|
Convey("Test alert execution", t, func() {
|
||||||
executor := &ExecutorImpl{}
|
executor := NewExecutor()
|
||||||
|
|
||||||
Convey("single time serie", func() {
|
Convey("single time serie", func() {
|
||||||
Convey("Show return ok since avg is above 2", func() {
|
Convey("Show return ok since avg is above 2", func() {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ func TestAlertRuleChangesDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
SaveAlerts(&cmd)
|
SaveAlerts(&cmd)
|
||||||
|
|
||||||
|
query := &m.GetAlertChangesQuery{OrgId: FakeOrgId}
|
||||||
er := GetAlertRuleChanges(query)
|
er := GetAlertRuleChanges(query)
|
||||||
So(er, ShouldBeNil)
|
So(er, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestGraphite(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
queries := tsdb.QuerySlice{
|
queries := tsdb.QuerySlice{
|
||||||
&tsdb.Query{Query: "apps.backend.*.counters.requests.count"},
|
&tsdb.Query{Query: "{\"target\": \"apps.backend.*.counters.requests.count\"}"},
|
||||||
}
|
}
|
||||||
context := tsdb.NewQueryContext(queries, tsdb.TimeRange{})
|
context := tsdb.NewQueryContext(queries, tsdb.TimeRange{})
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func TestMetricQuery(t *testing.T) {
|
|||||||
Convey("When executing request with one query", t, func() {
|
Convey("When executing request with one query", t, func() {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Queries: QuerySlice{
|
Queries: QuerySlice{
|
||||||
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ func TestMetricQuery(t *testing.T) {
|
|||||||
Convey("When executing one request with two queries from same data source", t, func() {
|
Convey("When executing one request with two queries from same data source", t, func() {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Queries: QuerySlice{
|
Queries: QuerySlice{
|
||||||
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"}},
|
||||||
{RefId: "B", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{RefId: "B", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +100,9 @@ func TestMetricQuery(t *testing.T) {
|
|||||||
Convey("When executing one request with three queries from different datasources", t, func() {
|
Convey("When executing one request with three queries from different datasources", t, func() {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Queries: QuerySlice{
|
Queries: QuerySlice{
|
||||||
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"}},
|
||||||
{RefId: "B", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{RefId: "B", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"}},
|
||||||
{RefId: "C", Query: "asd", DataSource: &DataSourceInfo{Id: 2, Type: "test"}},
|
{RefId: "C", Query: "asd", DataSource: &DataSourceInfo{Id: 2, PluginId: "test"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,24 +117,22 @@ func TestMetricQuery(t *testing.T) {
|
|||||||
Convey("When query uses data source of unknown type", t, func() {
|
Convey("When query uses data source of unknown type", t, func() {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Queries: QuerySlice{
|
Queries: QuerySlice{
|
||||||
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "asdasdas"}},
|
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "asdasdas"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := HandleRequest(req)
|
_, err := HandleRequest(req)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
|
|
||||||
Convey("Should return error", func() {
|
|
||||||
So(res.Results["A"].Error.Error(), ShouldContainSubstring, "not find")
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("When executing request that depend on other query", t, func() {
|
Convey("When executing request that depend on other query", t, func() {
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Queries: QuerySlice{
|
Queries: QuerySlice{
|
||||||
{RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, Type: "test"}},
|
{
|
||||||
{RefId: "B", Query: "#A / 2", DataSource: &DataSourceInfo{Id: 2, Type: "test"},
|
RefId: "A", Query: "asd", DataSource: &DataSourceInfo{Id: 1, PluginId: "test"},
|
||||||
Depends: []string{"A"},
|
},
|
||||||
|
{
|
||||||
|
RefId: "B", Query: "#A / 2", DataSource: &DataSourceInfo{Id: 2, PluginId: "test"}, Depends: []string{"A"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user