mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Rename Id to ID in alerting models (#62777)
* Chore: Rename Id to ID in alerting models * Add xorm tags for datasource * Add xorm tag for uid
This commit is contained in:
@@ -118,7 +118,7 @@ func (srv ConfigSrv) RouteDeleteNGalertConfig(c *contextmodel.ReqContext) respon
|
||||
func (srv ConfigSrv) externalAlertmanagers(ctx context.Context, orgID int64) ([]string, error) {
|
||||
var alertmanagers []string
|
||||
query := &datasources.GetDataSourcesByTypeQuery{
|
||||
OrgId: orgID,
|
||||
OrgID: orgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
}
|
||||
err := srv.datasourceService.GetDataSourcesByType(ctx, query)
|
||||
@@ -129,7 +129,7 @@ func (srv ConfigSrv) externalAlertmanagers(ctx context.Context, orgID int64) ([]
|
||||
if ds.JsonData.Get(apimodels.HandleGrafanaManagedAlerts).MustBool(false) {
|
||||
// we don't need to build the exact URL as we only need
|
||||
// to know if any is set
|
||||
alertmanagers = append(alertmanagers, ds.Uid)
|
||||
alertmanagers = append(alertmanagers, ds.UID)
|
||||
}
|
||||
}
|
||||
return alertmanagers, nil
|
||||
|
||||
@@ -28,9 +28,9 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
|
||||
alertmanagerChoice: definitions.ExternalAlertmanagers,
|
||||
datasources: []*datasources.DataSource{
|
||||
{
|
||||
OrgId: 1,
|
||||
OrgID: 1,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
Url: "http://localhost:9000",
|
||||
URL: "http://localhost:9000",
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
definitions.HandleGrafanaManagedAlerts: true,
|
||||
}),
|
||||
@@ -44,9 +44,9 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
|
||||
alertmanagerChoice: definitions.ExternalAlertmanagers,
|
||||
datasources: []*datasources.DataSource{
|
||||
{
|
||||
OrgId: 1,
|
||||
OrgID: 1,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
Url: "http://localhost:9000",
|
||||
URL: "http://localhost:9000",
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{}),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -67,8 +67,8 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
ds := &fakes.FakeCacheService{DataSources: []*datasources.DataSource{
|
||||
{Uid: data1.DatasourceUID},
|
||||
{Uid: data2.DatasourceUID},
|
||||
{UID: data1.DatasourceUID},
|
||||
{UID: data2.DatasourceUID},
|
||||
}}
|
||||
|
||||
var result []eval.Result
|
||||
@@ -110,7 +110,7 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
data1 := models.GenerateAlertQuery()
|
||||
|
||||
ds := &fakes.FakeCacheService{DataSources: []*datasources.DataSource{
|
||||
{Uid: data1.DatasourceUID},
|
||||
{UID: data1.DatasourceUID},
|
||||
}}
|
||||
currentTime := time.Now()
|
||||
|
||||
@@ -193,8 +193,8 @@ func TestRouteEvalQueries(t *testing.T) {
|
||||
})
|
||||
|
||||
ds := &fakes.FakeCacheService{DataSources: []*datasources.DataSource{
|
||||
{Uid: data1.DatasourceUID},
|
||||
{Uid: data2.DatasourceUID},
|
||||
{UID: data1.DatasourceUID},
|
||||
{UID: data2.DatasourceUID},
|
||||
}}
|
||||
|
||||
evaluator := &eval_mocks.ConditionEvaluatorMock{}
|
||||
@@ -237,7 +237,7 @@ func TestRouteEvalQueries(t *testing.T) {
|
||||
data1 := models.GenerateAlertQuery()
|
||||
|
||||
ds := &fakes.FakeCacheService{DataSources: []*datasources.DataSource{
|
||||
{Uid: data1.DatasourceUID},
|
||||
{UID: data1.DatasourceUID},
|
||||
}}
|
||||
|
||||
currentTime := time.Now()
|
||||
|
||||
@@ -87,7 +87,7 @@ func (p *LotexProm) getEndpoints(ctx *contextmodel.ReqContext) (*promEndpoints,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ds.Url == "" {
|
||||
if ds.URL == "" {
|
||||
return nil, fmt.Errorf("URL for this data source is empty")
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ func (r *LotexRuler) validateAndGetPrefix(ctx *contextmodel.ReqContext) (string,
|
||||
}
|
||||
|
||||
// Validate URL
|
||||
if ds.Url == "" {
|
||||
if ds.URL == "" {
|
||||
return "", fmt.Errorf("URL for this data source is empty")
|
||||
}
|
||||
|
||||
@@ -206,12 +206,12 @@ func (r *LotexRuler) validateAndGetPrefix(ctx *contextmodel.ReqContext) (string,
|
||||
if !ok {
|
||||
r.log.Debug(
|
||||
"Unable to determine prometheus datasource subtype, using default prefix",
|
||||
"datasource", ds.Uid, "datasourceType", ds.Type, "subtype", subtype, "prefix", prefix)
|
||||
"datasource", ds.UID, "datasourceType", ds.Type, "subtype", subtype, "prefix", prefix)
|
||||
return prefix, nil
|
||||
}
|
||||
|
||||
r.log.Debug("Determined prometheus datasource subtype",
|
||||
"datasource", ds.Uid, "datasourceType", ds.Type, "subtype", subtype)
|
||||
"datasource", ds.UID, "datasourceType", ds.Type, "subtype", subtype)
|
||||
return subTypePrefix, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,46 +45,46 @@ func TestLotexRuler_ValidateAndGetPrefix(t *testing.T) {
|
||||
{
|
||||
name: "with an unsupported datasource type",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com"}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com"}},
|
||||
err: errors.New("unexpected datasource type. expecting loki or prometheus"),
|
||||
},
|
||||
{
|
||||
name: "with a Loki datasource",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: LokiDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: LokiDatasourceType}},
|
||||
expected: "/api/prom/rules",
|
||||
},
|
||||
{
|
||||
name: "with a Prometheus datasource",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
expected: "/rules",
|
||||
},
|
||||
{
|
||||
name: "with a Prometheus datasource and subtype of Cortex",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
urlParams: "?subtype=cortex",
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
expected: "/rules",
|
||||
},
|
||||
{
|
||||
name: "with a Prometheus datasource and subtype of Mimir",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
urlParams: "?subtype=mimir",
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
expected: "/config/v1/rules",
|
||||
},
|
||||
{
|
||||
name: "with a Prometheus datasource and subtype of Prometheus",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
urlParams: "?subtype=prometheus",
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
expected: "/rules",
|
||||
},
|
||||
{
|
||||
name: "with a Prometheus datasource and no subtype",
|
||||
namedParams: map[string]string{":DatasourceUID": "d164"},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
datasourceCache: fakeCacheService{datasource: &datasources.DataSource{URL: "http://loki.com", Type: PrometheusDatasourceType}},
|
||||
expected: "/rules",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user