Prometheus: Add support for cloud partners Prometheus data sources (#103482)

* wip

* Add prom flavor support for data source variables and export/import dashboards (#103321)

* add dashboard and data source var selection

* use match plugin id instead

* use updated matchpluginid

* formatting

* cleanup

* regex anchor

* update error msg

* Alerting: Clean up prometheus-flavored types and functions (#103703)

* clean up types and utility functions for dealing with
prometheus-flavored data sources

* Refactor alerting datasource types to use constants as source of truth

* Alerting: Clean up prometheus-flavored types and functions on the bac… (#103716)

Alerting: Clean up prometheus-flavored types and functions on the backend

* add matchPluginId tests

* Update matchPluginId func to bidirectional (#103746)

* update matchpluginid func to bidirectional

* lint

* formatting

* use actual isSupportedExternalRulesSourceType in test

* add tests in datasource_srv

* betterer

* remove type assertion

* remove unnecessary case

* use satisifies to not have to convert tuple to an array of string

* add prometheus_flavor test

---------

Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com>
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
Co-authored-by: Alexander Akhmetov <me@alx.cx>
This commit is contained in:
Kevin Yu
2025-04-10 12:49:11 -07:00
committed by GitHub
co-authored by Andrew Hackmann Gilles De Mey Alexander Akhmetov
parent 22a9e1b5ff
commit fd6fd91115
32 changed files with 654 additions and 155 deletions
@@ -46,12 +46,26 @@ func (s *Service) detectPrometheusVariants(ctx context.Context) (map[string]int6
s.log.Error("Failed to read all Prometheus data sources", "error", err)
return nil, err
}
dsAmazonProm := &datasources.GetDataSourcesByTypeQuery{Type: "grafana-amazonprometheus-datasource"}
dataSourcesAmazonProm, err := s.datasources.GetDataSourcesByType(ctx, dsAmazonProm)
if err != nil {
s.log.Error("Failed to read all Amazon Prometheus data sources", "error", err)
return nil, err
}
dsAzureProm := &datasources.GetDataSourcesByTypeQuery{Type: "grafana-azureprometheus-datasource"}
dataSourcesAzureProm, err := s.datasources.GetDataSourcesByType(ctx, dsAzureProm)
if err != nil {
s.log.Error("Failed to read all Azure Prometheus data sources", "error", err)
return nil, err
}
allPromDataSources := append(append(dataSources, dataSourcesAmazonProm...), dataSourcesAzureProm...)
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(10)
flavors := sync.Map{}
for _, ds := range dataSources {
for _, ds := range allPromDataSources {
ds := ds
g.Go(func() error {
variant, err := s.detectPrometheusVariant(ctx, ds)
@@ -32,6 +32,18 @@ func TestDetectPrometheusVariant(t *testing.T) {
}))
t.Cleanup(cortex.Close)
// Amazon Prometheus is Cortex-like
amazonPrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
t.Cleanup(amazonPrometheus.Close)
// Azure Prometheus is Cortex-like
azurePrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
t.Cleanup(azurePrometheus.Close)
sqlStore := dbtest.NewFakeDB()
statsService := statstest.NewFakeService()
s := createService(
@@ -80,6 +92,26 @@ func TestDetectPrometheusVariant(t *testing.T) {
Access: "proxy",
URL: cortex.URL,
},
{
ID: 5,
UID: "amazon-prometheus",
OrgID: 1,
Version: 1,
Name: "Amazon Prometheus",
Type: "prometheus",
Access: "proxy",
URL: amazonPrometheus.URL,
},
{
ID: 6,
UID: "azure-prometheus",
OrgID: 1,
Version: 1,
Name: "Azure Prometheus",
Type: "prometheus",
Access: "proxy",
URL: azurePrometheus.URL,
},
}}),
)
@@ -88,5 +120,5 @@ func TestDetectPrometheusVariant(t *testing.T) {
assert.Equal(t, int64(2), flavors["mimir"])
assert.Equal(t, int64(1), flavors["vanilla"])
assert.Equal(t, int64(1), flavors["cortex-like"])
assert.Equal(t, int64(3), flavors["cortex-like"])
}