@ -26,7 +26,7 @@ describe('AzureMonitorDatasource', () => {
ctx . instanceSettings = {
ctx . instanceSettings = {
name : 'test' ,
name : 'test' ,
url : 'http://azuremonitor.com' ,
url : 'http://azuremonitor.com' ,
jsonData : { subscriptionId : '9935389e-9122-4ef9-95f9-1513dd24753f ' , cloudName : 'azuremonitor' } ,
jsonData : { subscriptionId : 'mock-subscription-id ' , cloudName : 'azuremonitor' } ,
} as unknown as DataSourceInstanceSettings < AzureDataSourceJsonData > ;
} as unknown as DataSourceInstanceSettings < AzureDataSourceJsonData > ;
ctx . ds = new AzureMonitorDatasource ( ctx . instanceSettings ) ;
ctx . ds = new AzureMonitorDatasource ( ctx . instanceSettings ) ;
} ) ;
} ) ;
@ -76,11 +76,11 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'When performing newG etMetricNamespaces' , ( ) = > {
describe ( 'When performing g etMetricNamespaces' , ( ) = > {
const response = {
const response = {
value : [
value : [
{
{
id : '/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp/providers/microsoft.insights/components/resource1/providers/microsoft.insights/metricNamespaces/Azure.ApplicationInsights' ,
id : '/subscriptions/mock-subscription-id /resourceGroups/nodeapp/providers/microsoft.insights/components/resource1/providers/microsoft.insights/metricNamespaces/Azure.ApplicationInsights' ,
name : 'Azure.ApplicationInsights' ,
name : 'Azure.ApplicationInsights' ,
type : 'Microsoft.Insights/metricNamespaces' ,
type : 'Microsoft.Insights/metricNamespaces' ,
classification : 'Custom' ,
classification : 'Custom' ,
@ -89,7 +89,7 @@ describe('AzureMonitorDatasource', () => {
} ,
} ,
} ,
} ,
{
{
id : '/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp/providers/microsoft.insights/components/resource1/providers/microsoft.insights/metricNamespaces/microsoft.insights-components' ,
id : '/subscriptions/mock-subscription-id /resourceGroups/nodeapp/providers/microsoft.insights/components/resource1/providers/microsoft.insights/metricNamespaces/microsoft.insights-components' ,
name : 'microsoft.insights-components' ,
name : 'microsoft.insights-components' ,
type : 'Microsoft.Insights/metricNamespaces' ,
type : 'Microsoft.Insights/metricNamespaces' ,
classification : 'Platform' ,
classification : 'Platform' ,
@ -102,7 +102,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -114,9 +114,10 @@ describe('AzureMonitorDatasource', () => {
it ( 'should return list of Metric Namspaces' , ( ) = > {
it ( 'should return list of Metric Namspaces' , ( ) = > {
return ctx . ds . azureMonitorDatasource
return ctx . ds . azureMonitorDatasource
. newGetMetricNamespaces (
. getMetricNamespaces ( {
'/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1'
resourceUri :
)
'/subscriptions/mock-subscription-id/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1' ,
} )
. then ( ( results : Array < { text : string ; value : string } > ) = > {
. then ( ( results : Array < { text : string ; value : string } > ) = > {
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Azure.ApplicationInsights' ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Azure.ApplicationInsights' ) ;
@ -127,7 +128,7 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'When performing newG etMetricNames' , ( ) = > {
describe ( 'When performing g etMetricNames' , ( ) = > {
const response = {
const response = {
value : [
value : [
{
{
@ -165,7 +166,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -177,10 +178,11 @@ describe('AzureMonitorDatasource', () => {
it ( 'should return list of Metric Definitions' , ( ) = > {
it ( 'should return list of Metric Definitions' , ( ) = > {
return ctx . ds . azureMonitorDatasource
return ctx . ds . azureMonitorDatasource
. newGetMetricNames (
. getMetricNames ( {
'/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1' ,
resourceUri :
'default'
'/subscriptions/mock-subscription-id/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1' ,
)
metricNamespace : 'default' ,
} )
. then ( ( results : Array < { text : string ; value : string } > ) = > {
. then ( ( results : Array < { text : string ; value : string } > ) = > {
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Used capacity' ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Used capacity' ) ;
@ -191,7 +193,7 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'When performing newG etMetricMetadata' , ( ) = > {
describe ( 'When performing g etMetricMetadata' , ( ) = > {
const response = {
const response = {
value : [
value : [
{
{
@ -229,7 +231,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -241,11 +243,12 @@ describe('AzureMonitorDatasource', () => {
it ( 'should return Aggregation metadata for a Metric' , ( ) = > {
it ( 'should return Aggregation metadata for a Metric' , ( ) = > {
return ctx . ds . azureMonitorDatasource
return ctx . ds . azureMonitorDatasource
. newGetMetricMetadata (
. getMetricMetadata ( {
'/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1' ,
resourceUri :
'default' ,
'/subscriptions/mock-subscription-id/resourceGroups/nodeapp/providers/microsoft.insights/components/resource1' ,
'UsedCapacity'
metricNamespace : 'default' ,
)
metricName : 'UsedCapacity' ,
} )
. then ( ( results ) = > {
. then ( ( results ) = > {
expect ( results . primaryAggType ) . toEqual ( 'Total' ) ;
expect ( results . primaryAggType ) . toEqual ( 'Total' ) ;
expect ( results . supportedAggTypes . length ) . toEqual ( 6 ) ;
expect ( results . supportedAggTypes . length ) . toEqual ( 6 ) ;
@ -342,7 +345,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups' ;
expect ( path ) . toBe ( basePath + '/nodesapp/resources?api-version=2021-04-01' ) ;
expect ( path ) . toBe ( basePath + '/nodesapp/resources?api-version=2021-04-01' ) ;
return Promise . resolve ( response ) ;
return Promise . resolve ( response ) ;
} ) ;
} ) ;
@ -350,7 +353,7 @@ describe('AzureMonitorDatasource', () => {
it ( 'should return list of Metric Definitions with no duplicates and no unsupported namespaces' , ( ) = > {
it ( 'should return list of Metric Definitions with no duplicates and no unsupported namespaces' , ( ) = > {
return ctx . ds
return ctx . ds
. getMetricDefinitions ( '9935389e-9122-4ef9-95f9-1513dd24753f ' , 'nodesapp' )
. getMetricDefinitions ( 'mock-subscription-id ' , 'nodesapp' )
. then ( ( results : Array < { text : string ; value : string } > ) = > {
. then ( ( results : Array < { text : string ; value : string } > ) = > {
expect ( results . length ) . toEqual ( 7 ) ;
expect ( results . length ) . toEqual ( 7 ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Network interface' ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Network interface' ) ;
@ -372,12 +375,12 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
describe ( 'When performing getResourceNames' , ( ) = > {
describe ( 'When performing getResourceNames' , ( ) = > {
let subscription = '9935389e-9122-4ef9-95f9-1513dd24753f ' ;
let subscription = 'mock-subscription-id ' ;
let resourceGroup = 'nodeapp' ;
let resourceGroup = 'nodeapp' ;
let metricDefinition = 'microsoft.insights/components' ;
let metricDefinition = 'microsoft.insights/components' ;
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
subscription = '9935389e-9122-4ef9-95f9-1513dd24753f ' ;
subscription = 'mock-subscription-id ' ;
resourceGroup = 'nodeapp' ;
resourceGroup = 'nodeapp' ;
metricDefinition = 'microsoft.insights/components' ;
metricDefinition = 'microsoft.insights/components' ;
} ) ;
} ) ;
@ -552,7 +555,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -563,14 +566,14 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
it ( 'should return list of Metric Definitions' , ( ) = > {
it ( 'should return list of Metric Definitions' , ( ) = > {
return ctx . ds
return ctx . ds . azureMonitorDatasource
. getMetricNames (
. getMetricNames ( {
'9935389e-9122-4ef9-95f9-1513dd24753f ',
subscription : 'mock-subscription-id ',
'nodeapp',
resourceGroup : 'nodeapp',
'microsoft.insights/components',
metricDefinition : 'microsoft.insights/components',
'resource1',
resourceName : 'resource1',
'default'
metricNamespace : 'default',
)
} )
. then ( ( results : Array < { text : string ; value : string } > ) = > {
. then ( ( results : Array < { text : string ; value : string } > ) = > {
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results . length ) . toEqual ( 2 ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Used capacity' ) ;
expect ( results [ 0 ] . text ) . toEqual ( 'Used capacity' ) ;
@ -619,7 +622,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -630,15 +633,15 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
it ( 'should return Aggregation metadata for a Metric' , ( ) = > {
it ( 'should return Aggregation metadata for a Metric' , ( ) = > {
return ctx . ds
return ctx . ds . azureMonitorDatasource
. getMetricMetadata (
. getMetricMetadata ( {
'9935389e-9122-4ef9-95f9-1513dd24753f ',
subscription : 'mock-subscription-id ',
'nodeapp',
resourceGroup : 'nodeapp',
'microsoft.insights/components',
metricDefinition : 'microsoft.insights/components',
'resource1',
resourceName : 'resource1',
'default',
metricNamespace : 'default',
'UsedCapacity'
metricName : 'UsedCapacity',
)
} )
. then ( ( results ) = > {
. then ( ( results ) = > {
expect ( results . primaryAggType ) . toEqual ( 'Total' ) ;
expect ( results . primaryAggType ) . toEqual ( 'Total' ) ;
expect ( results . supportedAggTypes . length ) . toEqual ( 6 ) ;
expect ( results . supportedAggTypes . length ) . toEqual ( 6 ) ;
@ -688,7 +691,7 @@ describe('AzureMonitorDatasource', () => {
beforeEach ( ( ) = > {
beforeEach ( ( ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
ctx . ds . azureMonitorDatasource . getResource = jest . fn ( ) . mockImplementation ( ( path : string ) = > {
const basePath = 'azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f /resourceGroups/nodeapp' ;
const basePath = 'azuremonitor/subscriptions/mock-subscription-id /resourceGroups/nodeapp' ;
const expected =
const expected =
basePath +
basePath +
'/providers/microsoft.insights/components/resource1' +
'/providers/microsoft.insights/components/resource1' +
@ -699,15 +702,15 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
it ( 'should return dimensions for a Metric that has dimensions' , ( ) = > {
it ( 'should return dimensions for a Metric that has dimensions' , ( ) = > {
return ctx . ds
return ctx . ds . azureMonitorDatasource
. getMetricMetadata (
. getMetricMetadata ( {
'9935389e-9122-4ef9-95f9-1513dd24753f ',
subscription : 'mock-subscription-id ',
'nodeapp',
resourceGroup : 'nodeapp',
'microsoft.insights/components',
metricDefinition : 'microsoft.insights/components',
'resource1',
resourceName : 'resource1',
'default',
metricNamespace : 'default',
'Transactions'
metricName : 'Transactions',
)
} )
. then ( ( results : any ) = > {
. then ( ( results : any ) = > {
expect ( results . dimensions ) . toMatchInlineSnapshot ( `
expect ( results . dimensions ) . toMatchInlineSnapshot ( `
Array [
Array [
@ -759,15 +762,15 @@ describe('AzureMonitorDatasource', () => {
} ) ;
} ) ;
it ( 'should return an empty array for a Metric that does not have dimensions' , ( ) = > {
it ( 'should return an empty array for a Metric that does not have dimensions' , ( ) = > {
return ctx . ds
return ctx . ds . azureMonitorDatasource
. getMetricMetadata (
. getMetricMetadata ( {
'9935389e-9122-4ef9-95f9-1513dd24753f ',
subscription : 'mock-subscription-id ',
'nodeapp',
resourceGroup : 'nodeapp',
'microsoft.insights/components',
metricDefinition : 'microsoft.insights/components',
'resource1',
resourceName : 'resource1',
'default',
metricNamespace : 'default',
'FreeCapacity'
metricName : 'FreeCapacity',
)
} )
. then ( ( results : any ) = > {
. then ( ( results : any ) = > {
expect ( results . dimensions . length ) . toEqual ( 0 ) ;
expect ( results . dimensions . length ) . toEqual ( 0 ) ;
} ) ;
} ) ;