From 612ebf5508446a69dac5135596056d82b8a574f9 Mon Sep 17 00:00:00 2001 From: Fabrizio <135109076+fabrizio-grafana@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:18:54 +0200 Subject: [PATCH] Dynatrace: Add to list of DS with custom label logic (#90258) --- pkg/expr/converter.go | 9 +++++++-- pkg/expr/nodes_test.go | 1 + pkg/services/datasources/models.go | 27 ++++++++++++++------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pkg/expr/converter.go b/pkg/expr/converter.go index 4681aab8b72..e2c8539d4c3 100644 --- a/pkg/expr/converter.go +++ b/pkg/expr/converter.go @@ -3,6 +3,7 @@ package expr import ( "context" "fmt" + "slices" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" @@ -295,10 +296,14 @@ func WideToMany(frame *data.Frame, fixSeries func(series mathexp.Series, valueFi // checkIfSeriesNeedToBeFixed scans all value fields of all provided frames and determines whether the resulting mathexp.Series // needs to be updated so each series could be identifiable by labels. -// NOTE: applicable only to only datasources.DS_GRAPHITE and datasources.DS_TESTDATA data sources +// NOTE: applicable only to some datas ources (datasources.DS_GRAPHITE, datasources.DS_TESTDATA, etc.); a more general solution should be investigated // returns a function that patches the mathexp.Series with information from data.Field from which it was created if the all series need to be fixed. Otherwise, returns nil func checkIfSeriesNeedToBeFixed(frames []*data.Frame, datasourceType string) func(series mathexp.Series, valueField *data.Field) { - if !(datasourceType == datasources.DS_GRAPHITE || datasourceType == datasources.DS_TESTDATA) { + supportedDatasources := []string{datasources.DS_GRAPHITE, datasources.DS_TESTDATA, datasources.DS_DYNATRACE} + checkdatasourceType := func(ds string) bool { + return datasourceType == ds + } + if !slices.ContainsFunc(supportedDatasources, checkdatasourceType) { return nil } diff --git a/pkg/expr/nodes_test.go b/pkg/expr/nodes_test.go index ada215a8ad9..1d4eb32fbdc 100644 --- a/pkg/expr/nodes_test.go +++ b/pkg/expr/nodes_test.go @@ -148,6 +148,7 @@ func TestCheckIfSeriesNeedToBeFixed(t *testing.T) { } supportedDatasources := []string{ + datasources.DS_DYNATRACE, datasources.DS_GRAPHITE, datasources.DS_TESTDATA, } diff --git a/pkg/services/datasources/models.go b/pkg/services/datasources/models.go index 0af097a9d09..6982b13fef5 100644 --- a/pkg/services/datasources/models.go +++ b/pkg/services/datasources/models.go @@ -11,26 +11,27 @@ import ( ) const ( + DS_ACCESS_DIRECT = "direct" + DS_ACCESS_PROXY = "proxy" + DS_ALERTMANAGER = "alertmanager" + DS_AZURE_MONITOR = "grafana-azure-monitor-datasource" + DS_DYNATRACE = "grafana-dynatrace-datasource" + DS_ES = "elasticsearch" + DS_ES_OPEN_DISTRO = "grafana-es-open-distro-datasource" + DS_ES_OPENSEARCH = "grafana-opensearch-datasource" DS_GRAPHITE = "graphite" DS_INFLUXDB = "influxdb" DS_INFLUXDB_08 = "influxdb_08" - DS_ES = "elasticsearch" - DS_PROMETHEUS = "prometheus" - DS_ALERTMANAGER = "alertmanager" DS_JAEGER = "jaeger" DS_LOKI = "loki" - DS_OPENTSDB = "opentsdb" - DS_TEMPO = "tempo" - DS_ZIPKIN = "zipkin" - DS_MYSQL = "mysql" - DS_POSTGRES = "grafana-postgresql-datasource" DS_MSSQL = "mssql" - DS_ACCESS_DIRECT = "direct" - DS_ACCESS_PROXY = "proxy" - DS_ES_OPEN_DISTRO = "grafana-es-open-distro-datasource" - DS_ES_OPENSEARCH = "grafana-opensearch-datasource" - DS_AZURE_MONITOR = "grafana-azure-monitor-datasource" + DS_MYSQL = "mysql" + DS_OPENTSDB = "opentsdb" + DS_POSTGRES = "grafana-postgresql-datasource" + DS_PROMETHEUS = "prometheus" + DS_TEMPO = "tempo" DS_TESTDATA = "grafana-testdata-datasource" + DS_ZIPKIN = "zipkin" // CustomHeaderName is the prefix that is used to store the name of a custom header. CustomHeaderName = "httpHeaderName" // CustomHeaderValue is the prefix that is used to store the value of a custom header.