@ -39,8 +39,9 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
azureMonitorVariedProperties map [ string ] interface { }
azureMonitorQueryTarget string
expectedInterval string
resourceURI string
queryInterval time . Duration
expectedURL string
expectedFilter string
} {
{
name : "Parse queries from frontend and build AzureMonitor API queries" ,
@ -49,9 +50,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
"timeGrain" : "PT1M" ,
"top" : "10" ,
} ,
resourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2018-01 -01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05 -01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
} ,
{
name : "legacy query without resourceURI and time grain set to auto" ,
@ -61,7 +61,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT15M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2018-01 -01&interval=PT15M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05 -01&interval=PT15M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
} ,
{
name : "legacy query without resourceURI and time grain set to auto" ,
@ -72,7 +72,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT5M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2018-01 -01&interval=PT5M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05 -01&interval=PT5M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
} ,
{
name : "legacy query without resourceURI and has a dimension filter" ,
@ -84,7 +84,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob eq '*'" ,
} ,
{
name : "legacy query without resourceURI and has a dimension filter and none Dimension" ,
@ -96,7 +97,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2018-01 -01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05 -01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
} ,
{
name : "legacy query without resourceURI and has dimensionFilter*s* property with one dimension" ,
@ -107,7 +108,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob eq '*'" ,
} ,
{
name : "legacy query without resourceURI and has dimensionFilter*s* property with two dimensions" ,
@ -118,7 +120,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27%2A%27+and+tier+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob eq '*' and tier eq '*'" ,
} ,
{
name : "legacy query without resourceURI and has a dimension filter without specifying a top" ,
@ -129,7 +132,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
expectedFilter : "blob eq '*'" ,
} ,
{
name : "has dimensionFilter*s* property with not equals operator" ,
@ -140,7 +144,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+ne+%27test%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob ne 'test'" ,
} ,
{
name : "has dimensionFilter*s* property with startsWith operator" ,
@ -151,7 +156,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+sw+%27test%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob sw 'test'" ,
} ,
{
name : "correctly sets dimension operator to eq (irrespective of operator) when filter value is '*'" ,
@ -162,7 +168,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27%2A%27+and+tier+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob eq '*' and tier eq '*'" ,
} ,
{
name : "correctly constructs target when multiple filter values are provided for the 'eq' operator" ,
@ -173,7 +180,8 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+eq+%27test%27+or+blob+eq+%27test2%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob eq 'test' or blob eq 'test2'" ,
} ,
{
name : "correctly constructs target when multiple filter values are provided for ne 'eq' operator" ,
@ -184,7 +192,43 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "%24filter=blob+ne+%27test%27+and+blob+ne+%27test2%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "blob ne 'test' and blob ne 'test2'" ,
} ,
{
name : "Includes a region" ,
azureMonitorVariedProperties : map [ string ] interface { } {
"timeGrain" : "PT1M" ,
"top" : "10" ,
"region" : "westus" ,
} ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines®ion=westus×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
expectedURL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/providers/microsoft.insights/metrics" ,
} ,
{
name : "includes a resource as a filter" ,
azureMonitorVariedProperties : map [ string ] interface { } {
"timeGrain" : "PT1M" ,
"resources" : [ ] types . AzureMonitorResource { { ResourceGroup : "rg" , ResourceName : "vm" } } ,
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z" ,
expectedFilter : "Microsoft.ResourceId eq '/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm'" ,
} ,
{
name : "includes a resource and a dimesion as filters" ,
azureMonitorVariedProperties : map [ string ] interface { } {
"timeGrain" : "PT1M" ,
"resources" : [ ] types . AzureMonitorResource { { ResourceGroup : "rg" , ResourceName : "vm" } } ,
"dimensionFilters" : [ ] types . AzureMonitorDimensionFilter { { Dimension : "blob" , Operator : "ne" , Filter : & wildcardFilter , Filters : [ ] string { "test" , "test2" } } } ,
"top" : "30" ,
} ,
queryInterval : duration ,
expectedInterval : "PT1M" ,
azureMonitorQueryTarget : "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30" ,
expectedFilter : "(Microsoft.ResourceId eq '/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm') and (blob ne 'test' and blob ne 'test2')" ,
} ,
}
@ -221,16 +265,18 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
}
azureMonitorQuery := & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Target : tt . azureMonitorQueryTarget ,
RefID : "A" ,
Alias : "testalias" ,
URL : tt . expectedURL ,
Target : tt . azureMonitorQueryTarget ,
RefID : "A" ,
Alias : "testalias" ,
TimeRange : backend . TimeRange {
From : fromStart ,
To : fromStart . Add ( 34 * time . Minute ) ,
} ,
Filter : tt . expectedFilter ,
}
if azureMonitorQuery . URL == "" {
azureMonitorQuery . URL = "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics"
}
queries , err := datasource . buildQueries ( tsdbQuery , dsInfo )
@ -243,7 +289,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
` TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ ` +
` ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C ` +
` %22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D `
actual , err := getQueryUrl ( queries [ 0 ] , "http://ds" )
actual , err := getQueryUrl ( queries [ 0 ] , "http://ds" , "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" , "grafana" )
require . NoError ( t , err )
require . Equal ( t , expected , actual )
} )
@ -315,8 +361,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "average aggregate time series response" ,
responseFile : "1-azure-monitor-response-avg.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
@ -335,8 +380,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "total aggregate time series response" ,
responseFile : "2-azure-monitor-response-total.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Total" } ,
} ,
@ -355,8 +399,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "maximum aggregate time series response" ,
responseFile : "3-azure-monitor-response-maximum.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Maximum" } ,
} ,
@ -375,8 +418,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "minimum aggregate time series response" ,
responseFile : "4-azure-monitor-response-minimum.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Minimum" } ,
} ,
@ -395,8 +437,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "count aggregate time series response" ,
responseFile : "5-azure-monitor-response-count.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Count" } ,
} ,
@ -415,8 +456,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "single dimension time series response" ,
responseFile : "6-azure-monitor-response-single-dimension.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
@ -448,9 +488,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "with alias patterns in the query" ,
responseFile : "2-azure-monitor-response-total.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
Params : url . Values {
"aggregation" : { "Total" } ,
} ,
@ -469,9 +508,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "single dimension with alias" ,
responseFile : "6-azure-monitor-response-single-dimension.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "{{dimensionname}}={{DimensionValue}}" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "{{dimensionname}}={{DimensionValue}}" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
@ -505,9 +543,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "multiple dimension time series response with label alias" ,
responseFile : "7-azure-monitor-response-multi-dimension.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "{{resourcegroup}} {Blob Type={{blobtype}}, Tier={{Tier}}}" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "{{resourcegroup}} {Blob Type={{blobtype}}, Tier={{Tier}}}" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
@ -542,9 +579,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "unspecified unit with alias should not panic" ,
responseFile : "8-azure-monitor-response-unspecified-unit.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "custom" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "custom" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
@ -563,9 +599,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "with legacy azure monitor query properties and without a resource uri" ,
responseFile : "2-azure-monitor-response-total.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
Params : url . Values {
"aggregation" : { "Total" } ,
} ,
@ -584,9 +619,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
name : "with legacy azure monitor query properties and with a resource uri it should use the resource uri" ,
responseFile : "2-azure-monitor-response-total.json" ,
mockQuery : & types . AzureMonitorQuery {
ResourceName : "grafana" ,
ResourceURI : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana/providers/microsoft.insights/metrics" ,
Alias : "custom {{resourcegroup}} {{namespace}} {{resourceName}} {{metric}}" ,
Params : url . Values {
"aggregation" : { "Total" } ,
} ,
@ -601,6 +635,26 @@ func TestAzureMonitorParseResponse(t *testing.T) {
} ) . SetConfig ( & data . FieldConfig { Unit : "percent" , DisplayName : "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU" , Links : [ ] data . DataLink { totalLink } } ) ) ,
} ,
} ,
{
name : "multiple time series response" ,
responseFile : "9-azure-monitor-response-multi.json" ,
mockQuery : & types . AzureMonitorQuery {
URL : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/providers/microsoft.insights/metrics" ,
Params : url . Values {
"aggregation" : { "Average" } ,
} ,
} ,
expectedFrames : data . Frames {
data . NewFrame ( "" ,
data . NewField ( "Time" , nil ,
makeDates ( time . Date ( 2019 , 2 , 8 , 10 , 13 , 0 , 0 , time . UTC ) , 5 , time . Minute ) ,
) . SetConfig ( & data . FieldConfig { Links : [ ] data . DataLink { averageLink } } ) ,
data . NewField ( "Percentage CPU" , data . Labels { "microsoft.resourceid" : "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana" } , [ ] * float64 {
ptr . Float64 ( 2.0875 ) , ptr . Float64 ( 2.1525 ) , ptr . Float64 ( 2.155 ) , ptr . Float64 ( 3.6925 ) , ptr . Float64 ( 2.44 ) ,
} ) . SetConfig ( & data . FieldConfig { Unit : "percent" , Links : [ ] data . DataLink { averageLink } } ) ,
) ,
} ,
} ,
}
datasource := & AzureMonitorDatasource { }