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:
@@ -209,7 +209,7 @@ func (d *AlertsRouter) alertmanagersFromDatasources(orgID int64) ([]string, erro
|
||||
// We might have alertmanager datasources that are acting as external
|
||||
// alertmanager, let's fetch them.
|
||||
query := &datasources.GetDataSourcesByTypeQuery{
|
||||
OrgId: orgID,
|
||||
OrgID: orgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
@@ -225,8 +225,8 @@ func (d *AlertsRouter) alertmanagersFromDatasources(orgID int64) ([]string, erro
|
||||
amURL, err := d.buildExternalURL(ds)
|
||||
if err != nil {
|
||||
d.logger.Error("Failed to build external alertmanager URL",
|
||||
"org", ds.OrgId,
|
||||
"uid", ds.Uid,
|
||||
"org", ds.OrgID,
|
||||
"uid", ds.UID,
|
||||
"error", err)
|
||||
continue
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (d *AlertsRouter) alertmanagersFromDatasources(orgID int64) ([]string, erro
|
||||
func (d *AlertsRouter) buildExternalURL(ds *datasources.DataSource) (string, error) {
|
||||
// We re-use the same parsing logic as the datasource to make sure it matches whatever output the user received
|
||||
// when doing the healthcheck.
|
||||
parsed, err := datasource.ValidateURL(datasources.DS_ALERTMANAGER, ds.Url)
|
||||
parsed, err := datasource.ValidateURL(datasources.DS_ALERTMANAGER, ds.URL)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse alertmanager datasource url: %w", err)
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ func TestIntegrationSendingToExternalAlertmanager(t *testing.T) {
|
||||
}
|
||||
|
||||
ds1 := datasources.DataSource{
|
||||
Url: fakeAM.Server.URL,
|
||||
OrgId: ruleKey.OrgID,
|
||||
URL: fakeAM.Server.URL,
|
||||
OrgID: ruleKey.OrgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
@@ -123,8 +123,8 @@ func TestIntegrationSendingToExternalAlertmanager_WithMultipleOrgs(t *testing.T)
|
||||
}
|
||||
|
||||
ds1 := datasources.DataSource{
|
||||
Url: fakeAM.Server.URL,
|
||||
OrgId: ruleKey1.OrgID,
|
||||
URL: fakeAM.Server.URL,
|
||||
OrgID: ruleKey1.OrgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
@@ -150,8 +150,8 @@ func TestIntegrationSendingToExternalAlertmanager_WithMultipleOrgs(t *testing.T)
|
||||
|
||||
// 1. Now, let's assume a new org comes along.
|
||||
ds2 := datasources.DataSource{
|
||||
Url: fakeAM.Server.URL,
|
||||
OrgId: ruleKey2.OrgID,
|
||||
URL: fakeAM.Server.URL,
|
||||
OrgID: ruleKey2.OrgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
@@ -196,8 +196,8 @@ func TestIntegrationSendingToExternalAlertmanager_WithMultipleOrgs(t *testing.T)
|
||||
// 2. Next, let's modify the configuration of an organization by adding an extra alertmanager.
|
||||
fakeAM2 := NewFakeExternalAlertmanager(t)
|
||||
ds3 := datasources.DataSource{
|
||||
Url: fakeAM2.Server.URL,
|
||||
OrgId: ruleKey2.OrgID,
|
||||
URL: fakeAM2.Server.URL,
|
||||
OrgID: ruleKey2.OrgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
@@ -225,7 +225,7 @@ func TestIntegrationSendingToExternalAlertmanager_WithMultipleOrgs(t *testing.T)
|
||||
assertAlertmanagersStatusForOrg(t, alertsRouter, ruleKey2.OrgID, 2, 0)
|
||||
|
||||
// 3. Now, let's provide a configuration that fails for OrgID = 1.
|
||||
fakeDs.DataSources[0].Url = "123://invalid.org"
|
||||
fakeDs.DataSources[0].URL = "123://invalid.org"
|
||||
mockedGetAdminConfigurations.Return([]*models.AdminConfiguration{
|
||||
{OrgID: ruleKey1.OrgID, SendAlertsTo: models.AllAlertmanagers},
|
||||
{OrgID: ruleKey2.OrgID},
|
||||
@@ -242,7 +242,7 @@ func TestIntegrationSendingToExternalAlertmanager_WithMultipleOrgs(t *testing.T)
|
||||
require.Equal(t, 0, len(alertsRouter.AlertmanagersFor(ruleKey1.OrgID)))
|
||||
|
||||
// If we fix it - it should be applied.
|
||||
fakeDs.DataSources[0].Url = "notarealalertmanager:3030"
|
||||
fakeDs.DataSources[0].URL = "notarealalertmanager:3030"
|
||||
mockedGetAdminConfigurations.Return([]*models.AdminConfiguration{
|
||||
{OrgID: ruleKey1.OrgID, SendAlertsTo: models.AllAlertmanagers},
|
||||
{OrgID: ruleKey2.OrgID},
|
||||
@@ -283,8 +283,8 @@ func TestChangingAlertmanagersChoice(t *testing.T) {
|
||||
}
|
||||
|
||||
ds := datasources.DataSource{
|
||||
Url: fakeAM.Server.URL,
|
||||
OrgId: ruleKey.OrgID,
|
||||
URL: fakeAM.Server.URL,
|
||||
OrgID: ruleKey.OrgID,
|
||||
Type: datasources.DS_ALERTMANAGER,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
@@ -437,21 +437,21 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
{
|
||||
name: "datasource without auth",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "https://localhost:9000",
|
||||
URL: "https://localhost:9000",
|
||||
},
|
||||
expectedURL: "https://localhost:9000",
|
||||
},
|
||||
{
|
||||
name: "datasource without auth and with path",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "https://localhost:9000/path/to/am",
|
||||
URL: "https://localhost:9000/path/to/am",
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/am",
|
||||
},
|
||||
{
|
||||
name: "datasource with auth",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "https://localhost:9000",
|
||||
URL: "https://localhost:9000",
|
||||
BasicAuth: true,
|
||||
BasicAuthUser: "johndoe",
|
||||
SecureJsonData: map[string][]byte{
|
||||
@@ -463,7 +463,7 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
{
|
||||
name: "datasource with auth and path",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "https://localhost:9000/path/to/am",
|
||||
URL: "https://localhost:9000/path/to/am",
|
||||
BasicAuth: true,
|
||||
BasicAuthUser: "johndoe",
|
||||
SecureJsonData: map[string][]byte{
|
||||
@@ -475,7 +475,7 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
{
|
||||
name: "with no scheme specified in the datasource",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "localhost:9000/path/to/am",
|
||||
URL: "localhost:9000/path/to/am",
|
||||
BasicAuth: true,
|
||||
BasicAuthUser: "johndoe",
|
||||
SecureJsonData: map[string][]byte{
|
||||
@@ -487,7 +487,7 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
{
|
||||
name: "with no scheme specified not auth in the datasource",
|
||||
ds: &datasources.DataSource{
|
||||
Url: "localhost:9000/path/to/am",
|
||||
URL: "localhost:9000/path/to/am",
|
||||
},
|
||||
expectedURL: "http://localhost:9000/path/to/am",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user