2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  azuremonitor  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"encoding/json" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 20:25:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"io" 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"testing" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"github.com/google/go-cmp/cmp" 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-19 22:56:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana-azure-sdk-go/v2/azcredentials" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana-plugin-sdk-go/backend" 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt" 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-27 06:53:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana-plugin-sdk-go/backend/log" 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana-plugin-sdk-go/experimental/featuretoggles" 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 17:23:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types" 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-04 17:23:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/stretchr/testify/assert" 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"github.com/stretchr/testify/require" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  testRoutes  =  map [ string ] types . AzRoute {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									azureMonitor :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :      "https://management.azure.com" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Scopes :   [ ] string { "https://management.azure.com/.default" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Headers :  map [ string ] string { "x-ms-app" :  "Grafana" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									azureLogAnalytics :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :      "https://api.loganalytics.io" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Scopes :   [ ] string { "https://api.loganalytics.io/.default" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Headers :  map [ string ] string { "x-ms-app" :  "Grafana" ,  "Cache-Control" :  "public, max-age=60" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									azureResourceGraph :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :      "https://management.azure.com" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Scopes :   [ ] string { "https://management.azure.com/.default" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Headers :  map [ string ] string { "x-ms-app" :  "Grafana" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									azureTraces :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :      "https://api.loganalytics.io" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Scopes :   [ ] string { "https://api.loganalytics.io/.default" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Headers :  map [ string ] string { "x-ms-app" :  "Grafana" ,  "Cache-Control" :  "public, max-age=60" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-07 00:53:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									traceExemplar :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :      "https://api.loganalytics.io" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Scopes :   [ ] string { "https://api.loganalytics.io/.default" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Headers :  map [ string ] string { "x-ms-app" :  "Grafana" ,  "Cache-Control" :  "public, max-age=60" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									azurePortal :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										URL :  "https://portal.azure.com" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  TestNewInstanceSettings ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										settings       backend . DataSourceInstanceSettings 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										expectedModel  * types . DatasourceInfo 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										Err            require . ErrorAssertionFunc 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										setupContext   func ( ctx  context . Context )  context . Context 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :  "current user authentication disabled by feature toggle" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											settings :  backend . DataSourceInstanceSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONData :                 [ ] byte ( ` { "azureAuthType":"currentuser"} ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												DecryptedSecureJSONData :  map [ string ] string { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ID :                       60 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedModel :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :  func ( t  require . TestingT ,  err  error ,  _  ... interface { } )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . Error ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . Contains ( t ,  err . Error ( ) ,  "current user authentication is not enabled for azure monitor" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											setupContext :  func ( ctx  context . Context )  context . Context  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												featureToggles  :=  backend . NewGrafanaCfg ( map [ string ] string { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													featuretoggles . EnabledFeatures :  "" ,  // No enabled features
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  backend . WithGrafanaConfig ( ctx ,  featureToggles ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :  "creates an instance" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											settings :  backend . DataSourceInstanceSettings { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-05 18:20:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												JSONData :                 [ ] byte ( ` { "azureAuthType":"msi"} ` ) , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												DecryptedSecureJSONData :  map [ string ] string { "key" :  "value" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ID :                       40 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedModel :  & types . DatasourceInfo { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-05 18:20:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Credentials :              & azcredentials . AzureManagedIdentityCredentials { } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Settings :                 types . AzureMonitorSettings { } , 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Routes :                   testRoutes , 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												JSONData :                 map [ string ] any { "azureAuthType" :  "msi" } , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												DatasourceID :             40 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												DecryptedSecureJSONData :  map [ string ] string { "key" :  "value" } , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Services :                 map [ string ] types . DatasourceService { } , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :  require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-03 18:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :  "creates an instance for customized cloud" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											settings :  backend . DataSourceInstanceSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONData :                 [ ] byte ( ` { "cloudName":"customizedazuremonitor","customizedRoutes": { "Route": { "URL":"url"}},"azureAuthType":"clientsecret"} ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												DecryptedSecureJSONData :  map [ string ] string { "clientSecret" :  "secret" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ID :                       50 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedModel :  & types . DatasourceInfo { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-03 18:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Credentials :  & azcredentials . AzureClientSecretCredentials { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													AzureCloud :    "AzureCustomizedCloud" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ClientSecret :  "secret" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Settings :  types . AzureMonitorSettings { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Routes :  map [ string ] types . AzRoute { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													"Route" :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														URL :  "url" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												JSONData :  map [ string ] any { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-03 18:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													"azureAuthType" :  "clientsecret" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													"cloudName" :      "customizedazuremonitor" , 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 23:46:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													"customizedRoutes" :  map [ string ] any { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														"Route" :  map [ string ] any { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-03 18:33:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															"URL" :  "url" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												DatasourceID :             50 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												DecryptedSecureJSONData :  map [ string ] string { "clientSecret" :  "secret" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Services :                 map [ string ] types . DatasourceService { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :  require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ctx  :=  context . Background ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  tt . setupContext  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ctx  =  tt . setupContext ( ctx ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-27 06:53:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											factory  :=  NewInstanceSettings ( & httpclient . Provider { } ,  map [ string ] azDatasourceExecutor { } ,  log . DefaultLogger ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											instance ,  err  :=  factory ( ctx ,  tt . settings ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											tt . Err ( t ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 22:01:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  tt . expectedModel  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . Nil ( t ,  instance ,  "Expected instance to be nil" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require . NotNil ( t ,  instance ,  "Expected instance to be created" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ! cmp . Equal ( instance ,  * tt . expectedModel )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													t . Errorf ( "Unexpected instance: %v" ,  cmp . Diff ( instance ,  * tt . expectedModel ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  fakeInstance  struct  {  
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									routes    map [ string ] types . AzRoute 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									services  map [ string ] types . DatasourceService 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									settings  types . AzureMonitorSettings 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 16:19:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( f  * fakeInstance )  Get ( _  context . Context ,  _  backend . PluginContext )  ( instancemgmt . Instance ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  types . DatasourceInfo { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Routes :    f . routes , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Services :  f . services , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Settings :  f . settings , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 16:19:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( f  * fakeInstance )  Do ( _  context . Context ,  _  backend . PluginContext ,  _  instancemgmt . InstanceCallbackFunc )  error  {  
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  fakeExecutor  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t            * testing . T 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									queryType    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									expectedURL  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-30 21:39:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( f  * fakeExecutor )  ResourceRequest ( rw  http . ResponseWriter ,  req  * http . Request ,  cli  * http . Client )  ( http . ResponseWriter ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-29 01:06:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( f  * fakeExecutor )  ExecuteTimeSeriesQuery ( ctx  context . Context ,  originalQueries  [ ] backend . DataQuery ,  dsInfo  types . DatasourceInfo ,  client  * http . Client ,  url  string ,  fromAlert  bool )  ( * backend . QueryDataResponse ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  client  ==  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										f . t . Errorf ( "The HTTP client for %s is missing" ,  f . queryType ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  url  !=  f . expectedURL  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											f . t . Errorf ( "Unexpected URL %s wanted %s" ,  url ,  f . expectedURL ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & backend . QueryDataResponse { } ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  Test_newMux ( t  * testing . T )  {  
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										queryType    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedURL  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Err          require . ErrorAssertionFunc 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :         "creates an Azure Monitor executor" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :    azureMonitor , 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedURL :  testRoutes [ azureMonitor ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											Err :          require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :         "creates an Azure Log Analytics executor" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :    azureLogAnalytics , 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedURL :  testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											Err :          require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-28 03:24:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :         "creates an Azure Traces executor" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :    azureTraces , 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											expectedURL :  testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-28 03:24:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Err :          require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											s  :=  & Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												im :  & fakeInstance { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													routes :  testRoutes , 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-02 22:41:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													services :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														tt . queryType :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															URL :         testRoutes [ tt . queryType ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-16 18:47:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												executors :  map [ string ] azDatasourceExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													tt . queryType :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														queryType :    tt . queryType , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														expectedURL :  tt . expectedURL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-21 01:16:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											mux  :=  s . newQueryMux ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-22 18:02:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res ,  err  :=  mux . QueryData ( context . Background ( ) ,  & backend . QueryDataRequest { 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-28 03:24:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												PluginContext :  backend . PluginContext { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													DataSourceInstanceSettings :  & backend . DataSourceInstanceSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Name :  "datasource_name" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														UID :   "datasource_UID" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-11 23:02:24 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												Queries :  [ ] backend . DataQuery { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ QueryType :  tt . queryType } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											tt . Err ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Dummy response from the fake implementation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  res  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Expecting a response" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  RoundTripFunc  func ( req  * http . Request )  ( * http . Response ,  error )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( f  RoundTripFunc )  RoundTrip ( req  * http . Request )  ( * http . Response ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  f ( req ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  NewTestClient ( fn  RoundTripFunc )  * http . Client  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & http . Client { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Transport :  fn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  TestCheckHealth ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									logAnalyticsResponse  :=  func ( empty  bool )  ( * http . Response ,  error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! empty  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											body  :=  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Value  [ ] types . LogAnalyticsWorkspaceResponse 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} { Value :  [ ] types . LogAnalyticsWorkspaceResponse { { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Id :        "abcd-1234" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Location :  "location" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Name :      "test-workspace" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Properties :  types . LogAnalyticsWorkspaceProperties { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													CreatedDate :  "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													CustomerId :   "abcd-1234" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Features :     types . LogAnalyticsWorkspaceFeatures { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ProvisioningState :                "provisioned" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PublicNetworkAccessForIngestion :  "enabled" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PublicNetworkAccessForQuery :      "disabled" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												RetentionInDays :                  0 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bodyMarshal ,  err  :=  json . Marshal ( body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												StatusCode :  200 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Body :        io . NopCloser ( bytes . NewBuffer ( bodyMarshal ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											body  :=  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Value  [ ] types . LogAnalyticsWorkspaceResponse 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} { Value :  [ ] types . LogAnalyticsWorkspaceResponse { } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											bodyMarshal ,  err  :=  json . Marshal ( body ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												StatusCode :  200 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Body :        io . NopCloser ( bytes . NewBuffer ( bodyMarshal ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									azureMonitorClient  :=  func ( logAnalyticsEmpty  bool ,  fail  bool )  * http . Client  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  NewTestClient ( func ( req  * http . Request )  ( * http . Response ,  error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  strings . Contains ( req . URL . String ( ) ,  "workspaces" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  logAnalyticsResponse ( logAnalyticsEmpty ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ! fail  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														StatusCode :  200 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-20 22:32:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														Body :        io . NopCloser ( bytes . NewBufferString ( "{\"value\": [{\"subscriptionId\": \"abcd-1234\"}]}" ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														StatusCode :  404 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														Body :        io . NopCloser ( bytes . NewBufferString ( "not found" ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									okClient  :=  NewTestClient ( func ( req  * http . Request )  ( * http . Response ,  error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											StatusCode :  200 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Body :        io . NopCloser ( bytes . NewBufferString ( "OK" ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									failClient  :=  func ( azureHealthCheckError  bool )  * http . Client  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  NewTestClient ( func ( req  * http . Request )  ( * http . Response ,  error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  azureHealthCheckError  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  nil ,  errors . New ( "not found" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  & http . Response { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												StatusCode :  404 , 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-10 21:37:51 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Body :        io . NopCloser ( bytes . NewBufferString ( "not found" ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Header :      make ( http . Header ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name            string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										errorExpected   bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedResult  * backend . CheckHealthResult 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										customServices  map [ string ] types . DatasourceService 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully queries all endpoints" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusOk , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "Successfully connected to all Azure Monitor endpoints." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  azureMonitorClient ( false ,  false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully queries all endpoints except metrics" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "One or more health checks failed. See details below." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONDetails :  [ ] byte ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													` { "verboseMessage": "1. Error connecting to Azure Monitor endpoint: not found\n2. Successfully connected to Azure Log Analytics endpoint.\n3. Successfully connected to Azure Resource Graph endpoint." } ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  azureMonitorClient ( false ,  true ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully queries all endpoints except log analytics" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "One or more health checks failed. See details below." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONDetails :  [ ] byte ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													` { "verboseMessage": "1. Successfully connected to Azure Monitor endpoint.\n2. Error connecting to Azure Log Analytics endpoint: not found\n3. Successfully connected to Azure Resource Graph endpoint." } ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  azureMonitorClient ( false ,  false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  failClient ( false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully queries all endpoints except resource graph" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "One or more health checks failed. See details below." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONDetails :  [ ] byte ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													` { "verboseMessage": "1. Successfully connected to Azure Monitor endpoint.\n2. Successfully connected to Azure Log Analytics endpoint.\n3. Error connecting to Azure Resource Graph endpoint: not found" } ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  azureMonitorClient ( false ,  false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  failClient ( false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully returns UNKNOWN status if no log analytics workspace is found" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusUnknown , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "One or more health checks failed. See details below." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONDetails :  [ ] byte ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													` { "verboseMessage": "1. Successfully connected to Azure Monitor endpoint.\n2. No Log Analytics workspaces found.\n3. Successfully connected to Azure Resource Graph endpoint." } ` ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  azureMonitorClient ( true ,  false ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  okClient , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Successfully returns Azure health check errors" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											errorExpected :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedResult :  & backend . CheckHealthResult { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Status :   backend . HealthStatusError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Message :  "One or more health checks failed. See details below." , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												JSONDetails :  [ ] byte ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-21 20:03:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													` { "verboseMessage": "1. Error connecting to Azure Monitor endpoint: health check failed: Get \"https://management.azure.com/subscriptions?api-version=2020-01-01\": not found\n2. Error connecting to Azure Log Analytics endpoint: health check failed: Get \"https://management.azure.com/subscriptions//providers/Microsoft.OperationalInsights/workspaces?api-version=2017-04-26-preview\": not found\n3. Error connecting to Azure Resource Graph endpoint: health check failed: Post \"https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-06-01-preview\": not found" } ` ) , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											customServices :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Monitor" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  failClient ( true ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Log Analytics" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  failClient ( true ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													URL :         testRoutes [ "Azure Resource Graph" ] . URL , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													HTTPClient :  failClient ( true ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									instance  :=  & fakeInstance { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-08 18:42:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										routes :    testRoutes , 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-20 18:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										services :  map [ string ] types . DatasourceService { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										settings :  types . AzureMonitorSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											LogAnalyticsDefaultWorkspace :  "workspace-id" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											instance . services  =  tt . customServices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											s  :=  & Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												im :  instance , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  err  :=  s . CheckHealth ( context . Background ( ) ,  & backend . CheckHealthRequest { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PluginContext :  backend . PluginContext { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													DataSourceInstanceSettings :  & backend . DataSourceInstanceSettings { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  tt . errorExpected  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . Error ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . NoError ( t ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . Equal ( t ,  tt . expectedResult ,  res ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-10-25 20:25:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  Test_QueryData ( t  * testing . T )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tests  :=  [ ] struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										queryType      string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										expectedURL    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Err            require . ErrorAssertionFunc 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ExpectedError  error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Azure Monitor query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    testRoutes [ azureMonitor ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Azure Log Analytics query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      azureLogAnalytics , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Azure Resource Graph query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      azureResourceGraph , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    testRoutes [ azureResourceGraph ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Azure Traces query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      azureTraces , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "traceExemplar query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      traceExemplar , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    testRoutes [ traceExemplar ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . NoError , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  nil , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Deprecated Application Insights query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      "Application Insights" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . Error , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  fmt . Errorf ( "query type: '%s' is no longer supported. Please migrate this query (see https://grafana.com/docs/grafana/v9.0/datasources/azuremonitor/deprecated-application-insights/ for details)" ,  "Application Insights" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :           "Deprecated Insights Analytics query type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											queryType :      "Insights Analytics" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											expectedURL :    "" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Err :            require . Error , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ExpectedError :  fmt . Errorf ( "query type: '%s' is no longer supported. Please migrate this query (see https://grafana.com/docs/grafana/v9.0/datasources/azuremonitor/deprecated-application-insights/ for details)" ,  "Insights Analytics" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									service  :=  & Service { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										im :  & fakeInstance { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											routes :  testRoutes , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											services :  map [ string ] types . DatasourceService { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureMonitor :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													URL :         testRoutes [ azureMonitor ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureLogAnalytics :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													URL :         testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureResourceGraph :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													URL :         testRoutes [ azureResourceGraph ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												azureTraces :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													URL :         testRoutes [ azureTraces ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												traceExemplar :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													URL :         testRoutes [ traceExemplar ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													HTTPClient :  & http . Client { } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										executors :  map [ string ] azDatasourceExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											azureMonitor :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												queryType :    azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												expectedURL :  testRoutes [ azureMonitor ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											azureLogAnalytics :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												queryType :    azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												expectedURL :  testRoutes [ azureLogAnalytics ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											azureResourceGraph :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												queryType :    azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												expectedURL :  testRoutes [ azureResourceGraph ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											azureTraces :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												queryType :    azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												expectedURL :  testRoutes [ azureTraces ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											traceExemplar :  & fakeExecutor { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t :            t , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												queryType :    azureMonitor , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												expectedURL :  testRoutes [ traceExemplar ] . URL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									service . queryMux  =  service . newQueryMux ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  tt  :=  range  tests  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t . Run ( tt . name ,  func ( t  * testing . T )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res ,  _  :=  service . QueryData ( context . Background ( ) ,  & backend . QueryDataRequest { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												PluginContext :  backend . PluginContext { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													DataSourceInstanceSettings :  & backend . DataSourceInstanceSettings { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Name :  "datasource_name" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														UID :   "datasource_UID" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Queries :  [ ] backend . DataQuery { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{ QueryType :  tt . queryType , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														RefID :  "test" } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  res  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												t . Errorf ( "Expecting a response" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  res  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												tt . Err ( t ,  res . Responses [ "test" ] . Error ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  tt . ExpectedError  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . EqualError ( t ,  res . Responses [ "test" ] . Error ,  tt . ExpectedError . Error ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}