API: Add by UID routes for data sources (#29884)

- also add Get by UID+OrgID to datasource cache
- Refactor backend commands for Delete and Get to be unified
This commit is contained in:
Kyle Brandt
2021-01-13 13:16:27 -05:00
committed by GitHub
parent d5cbb17666
commit 1c1a800bc0
18 changed files with 295 additions and 89 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ func (e *AlertEngine) mapRulesToUsageStats(rules []*models.Alert) (DatasourceAle
// map of datsource types and frequency
result := map[string]int{}
for k, v := range typeCount {
query := &models.GetDataSourceByIdQuery{Id: k}
query := &models.GetDataSourceQuery{Id: k}
err := e.Bus.Dispatch(query)
if err != nil {
return map[string]int{}, nil
+1 -1
View File
@@ -38,7 +38,7 @@ func TestAlertingUsageStats(t *testing.T) {
return nil
})
ae.Bus.AddHandler(func(query *models.GetDataSourceByIdQuery) error {
ae.Bus.AddHandler(func(query *models.GetDataSourceQuery) error {
ds := map[int64]*models.DataSource{
1: {Type: "influxdb"},
2: {Type: "graphite"},
+1 -1
View File
@@ -110,7 +110,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio
}
func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *tsdb.TimeRange) (tsdb.TimeSeriesSlice, error) {
getDsInfo := &models.GetDataSourceByIdQuery{
getDsInfo := &models.GetDataSourceQuery{
Id: c.Query.DatasourceID,
OrgId: context.Rule.OrgID,
}
@@ -228,7 +228,7 @@ func (ctx *queryConditionTestContext) exec() (*alerting.ConditionResult, error)
func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
Convey(desc, func() {
bus.AddHandler("test", func(query *models.GetDataSourceByIdQuery) error {
bus.AddHandler("test", func(query *models.GetDataSourceQuery) error {
query.Result = &models.DataSource{Id: 1, Type: "graphite"}
return nil
})
+1 -1
View File
@@ -39,7 +39,7 @@ func (e *DashAlertExtractor) lookupDatasourceID(dsName string) (*models.DataSour
return query.Result, nil
}
query := &models.GetDataSourceByNameQuery{Name: dsName, OrgId: e.OrgID}
query := &models.GetDataSourceQuery{Name: dsName, OrgId: e.OrgID}
if err := bus.Dispatch(query); err != nil {
return nil, err
}
+1 -1
View File
@@ -29,7 +29,7 @@ func TestAlertRuleExtraction(t *testing.T) {
return nil
})
bus.AddHandler("test", func(query *models.GetDataSourceByNameQuery) error {
bus.AddHandler("test", func(query *models.GetDataSourceQuery) error {
if query.Name == defaultDs.Name {
query.Result = defaultDs
}