(cherry picked from commit 879ee82b83)
Co-authored-by: Adam Simpson <adam@adamsimpson.net>
This commit is contained in:
co-authored by
Adam Simpson
parent
f80a9388cf
commit
a41e6ae453
@@ -113,8 +113,13 @@ func (e *AzureMonitorDatasource) buildQueries(queries []backend.DataQuery, dsInf
|
||||
params.Add("timespan", fmt.Sprintf("%v/%v", query.TimeRange.From.UTC().Format(time.RFC3339), query.TimeRange.To.UTC().Format(time.RFC3339)))
|
||||
params.Add("interval", timeGrain)
|
||||
params.Add("aggregation", azJSONModel.Aggregation)
|
||||
params.Add("metricnames", azJSONModel.MetricName) // MetricName or MetricNames ?
|
||||
params.Add("metricnamespace", azJSONModel.MetricNamespace)
|
||||
params.Add("metricnames", azJSONModel.MetricName)
|
||||
|
||||
if azJSONModel.CustomNamespace != "" {
|
||||
params.Add("metricnamespace", azJSONModel.CustomNamespace)
|
||||
} else {
|
||||
params.Add("metricnamespace", azJSONModel.MetricNamespace)
|
||||
}
|
||||
|
||||
// old model
|
||||
dimension := strings.TrimSpace(azJSONModel.Dimension)
|
||||
|
||||
@@ -250,6 +250,27 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomNamespace(t *testing.T) {
|
||||
datasource := &AzureMonitorDatasource{}
|
||||
|
||||
t.Run("it should set the metricNamespace to a customNamespace value if customNamespace is present as a parameter", func(t *testing.T) {
|
||||
q := []backend.DataQuery{
|
||||
{
|
||||
JSON: []byte(`{
|
||||
"azureMonitor": {
|
||||
"customNamespace": "custom/namespace"
|
||||
}
|
||||
}`),
|
||||
},
|
||||
}
|
||||
|
||||
result, err := datasource.buildQueries(q, types.DatasourceInfo{})
|
||||
require.NoError(t, err)
|
||||
expected := "custom/namespace"
|
||||
require.Equal(t, expected, result[0].Params.Get("metricnamespace"))
|
||||
})
|
||||
}
|
||||
|
||||
func makeDates(startDate time.Time, count int, interval time.Duration) (times []time.Time) {
|
||||
for i := 0; i < count; i++ {
|
||||
times = append(times, startDate.Add(interval*time.Duration(i)))
|
||||
|
||||
@@ -115,6 +115,7 @@ type AzureMonitorJSONQuery struct {
|
||||
ResourceURI string `json:"resourceUri"`
|
||||
// These are used to reconstruct a resource URI
|
||||
MetricNamespace string `json:"metricNamespace"`
|
||||
CustomNamespace string `json:"customNamespace"`
|
||||
MetricName string `json:"metricName"`
|
||||
ResourceGroup string `json:"resourceGroup"`
|
||||
ResourceName string `json:"resourceName"`
|
||||
|
||||
Reference in New Issue
Block a user