Alerting: Remove url based external alertmanagers config (#57918)

* Remove URL-based alertmanagers from endpoint config

* WIP

* Add migration and alertmanagers from admin_configuration

* Empty comment removed

* set BasicAuth true when user is present in url

* Remove Alertmanagers from GET /admin_config payload

* Remove URL-based alertmanager configuration from UI

* Fix new uid generation in external alertmanagers migration

* Fix tests for URL-based external alertmanagers

* Fix API tests

* Add more tests, move migration code to separate file, and remove possible am duplicate urls

* Fix edge cases in migration

* Fix imports

* Remove useless fields and fix created_at/updated_at retrieval

Co-authored-by: George Robinson <george.robinson@grafana.com>
Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
This commit is contained in:
Alex Moreno
2022-11-10 16:34:13 +01:00
committed by GitHub
parent 738e023d13
commit 45facbba11
21 changed files with 411 additions and 796 deletions
@@ -18,23 +18,13 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
tests := []struct {
name string
alertmanagerChoice definitions.AlertmanagersChoice
alertmanagers []string
datasources []*datasources.DataSource
statusCode int
message string
}{
{
name: "setting the choice to external by passing a plain url should succeed",
alertmanagerChoice: definitions.ExternalAlertmanagers,
alertmanagers: []string{"http://localhost:9000"},
datasources: []*datasources.DataSource{},
statusCode: http.StatusCreated,
message: "admin configuration updated",
},
{
name: "setting the choice to external by having a enabled external am datasource should succeed",
alertmanagerChoice: definitions.ExternalAlertmanagers,
alertmanagers: []string{},
datasources: []*datasources.DataSource{
{
OrgId: 1,
@@ -51,7 +41,6 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
{
name: "setting the choice to external by having a disabled external am datasource should fail",
alertmanagerChoice: definitions.ExternalAlertmanagers,
alertmanagers: []string{},
datasources: []*datasources.DataSource{
{
OrgId: 1,
@@ -66,7 +55,6 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
{
name: "setting the choice to external and having no am configured should fail",
alertmanagerChoice: definitions.ExternalAlertmanagers,
alertmanagers: []string{},
datasources: []*datasources.DataSource{},
statusCode: http.StatusBadRequest,
message: "At least one Alertmanager must be provided or configured as a datasource that handles alerts to choose this option",
@@ -74,7 +62,6 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
{
name: "setting the choice to all and having no external am configured should succeed",
alertmanagerChoice: definitions.AllAlertmanagers,
alertmanagers: []string{},
datasources: []*datasources.DataSource{},
statusCode: http.StatusCreated,
message: "admin configuration updated",
@@ -82,7 +69,6 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
{
name: "setting the choice to internal should always succeed",
alertmanagerChoice: definitions.InternalAlertmanager,
alertmanagers: []string{},
datasources: []*datasources.DataSource{},
statusCode: http.StatusCreated,
message: "admin configuration updated",
@@ -94,7 +80,6 @@ func TestExternalAlertmanagerChoice(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
sut := createAPIAdminSut(t, test.datasources)
resp := sut.RoutePostNGalertConfig(ctx, definitions.PostableNGalertConfig{
Alertmanagers: test.alertmanagers,
AlertmanagersChoice: test.alertmanagerChoice,
})
var res map[string]interface{}