mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
b05b5d5e3b
* 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)
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package azuremonitor
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// urlBuilder builds the URL for calling the Azure Monitor API
|
|
type urlBuilder struct {
|
|
DefaultSubscription string
|
|
Subscription string
|
|
ResourceGroup string
|
|
MetricDefinition string
|
|
ResourceName string
|
|
}
|
|
|
|
// Build checks the metric definition property to see which form of the url
|
|
// should be returned
|
|
func (ub *urlBuilder) Build() string {
|
|
subscription := ub.Subscription
|
|
|
|
if ub.Subscription == "" {
|
|
subscription = ub.DefaultSubscription
|
|
}
|
|
|
|
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/providers/microsoft.insights/metrics", strings.Join(urlArray[:], "/"))
|
|
}
|