AzureMonitor: Fix queries with Microsoft.NetApp/../../volumes resources (#32661)
* Extend description of existing tests (#28350) * Tests for building MetricNamespaces URL (#28350) * Added tests that break the URL builder (#28350) * Arbitrary length of metric definition (#28350) * Change var to const as requested (#32661) * Adding tests to datasource url builder (#28350) * Fixes to datasource url builder (#28350) * Fixed linting issue that broke build (#28350)
This commit is contained in:
@@ -23,13 +23,17 @@ func (ub *urlBuilder) Build() string {
|
||||
subscription = ub.DefaultSubscription
|
||||
}
|
||||
|
||||
if strings.Count(ub.MetricDefinition, "/") > 1 {
|
||||
rn := strings.Split(ub.ResourceName, "/")
|
||||
lastIndex := strings.LastIndex(ub.MetricDefinition, "/")
|
||||
service := ub.MetricDefinition[lastIndex+1:]
|
||||
md := ub.MetricDefinition[0:lastIndex]
|
||||
return fmt.Sprintf("%s/resourceGroups/%s/providers/%s/%s/%s/%s/providers/microsoft.insights/metrics", subscription, ub.ResourceGroup, md, rn[0], service, rn[1])
|
||||
metricDefinitionArray := strings.Split(ub.MetricDefinition, "/")
|
||||
resourceNameArray := strings.Split(ub.ResourceName, "/")
|
||||
provider := metricDefinitionArray[0]
|
||||
metricDefinitionArray = metricDefinitionArray[1:]
|
||||
|
||||
urlArray := []string{subscription, "resourceGroups", ub.ResourceGroup, "providers", provider}
|
||||
|
||||
for i := range metricDefinitionArray {
|
||||
urlArray = append(urlArray, metricDefinitionArray[i])
|
||||
urlArray = append(urlArray, resourceNameArray[i])
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/resourceGroups/%s/providers/%s/%s/providers/microsoft.insights/metrics", subscription, ub.ResourceGroup, ub.MetricDefinition, ub.ResourceName)
|
||||
return fmt.Sprintf("%s/providers/microsoft.insights/metrics", strings.Join(urlArray[:], "/"))
|
||||
}
|
||||
|
||||
@@ -56,5 +56,17 @@ func TestURLBuilder(t *testing.T) {
|
||||
url := ub.Build()
|
||||
So(url, ShouldEqual, "default-sub/resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/rn1/fileServices/default/providers/microsoft.insights/metrics")
|
||||
})
|
||||
|
||||
Convey("when metric definition is Microsoft.NetApp/netAppAccounts/capacityPools/volumes", func() {
|
||||
ub := &urlBuilder{
|
||||
DefaultSubscription: "default-sub",
|
||||
ResourceGroup: "rg",
|
||||
MetricDefinition: "Microsoft.NetApp/netAppAccounts/capacityPools/volumes",
|
||||
ResourceName: "rn1/rn2/rn3",
|
||||
}
|
||||
|
||||
url := ub.Build()
|
||||
So(url, ShouldEqual, "default-sub/resourceGroups/rg/providers/Microsoft.NetApp/netAppAccounts/rn1/capacityPools/rn2/volumes/rn3/providers/microsoft.insights/metrics")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user