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:
co-authored by
Andrew Hackmann
Gilles De Mey
Alexander Akhmetov
parent
22a9e1b5ff
commit
fd6fd91115
@@ -13,6 +13,7 @@ import (
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
models2 "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -176,3 +177,85 @@ func (r *recordingConditionValidator) Validate(_ eval.EvaluationContext, conditi
|
||||
}
|
||||
|
||||
var _ ConditionValidator = &recordingConditionValidator{}
|
||||
|
||||
func TestIsPrometheusCompatible(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
dsType string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "amazon prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_AMAZON_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "azure prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_AZURE_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "loki datasource should not be prometheus compatible",
|
||||
dsType: datasources.DS_LOKI,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "other datasource types should not be compatible",
|
||||
dsType: "some-other-datasource",
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := isPrometheusCompatible(tc.dsType)
|
||||
assert.Equal(t, tc.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLotexRulerCompatible(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
dsType string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "amazon prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_AMAZON_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "azure prometheus datasource should be compatible",
|
||||
dsType: datasources.DS_AZURE_PROMETHEUS,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "loki datasource should be compatible",
|
||||
dsType: datasources.DS_LOKI,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "other datasource types should not be compatible",
|
||||
dsType: "some-other-datasource",
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := isLotexRulerCompatible(tc.dsType)
|
||||
assert.Equal(t, tc.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user