mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
AzureMonitor: Fix bug detecting app insights queries (#88572)
Make regexp case insensitive
This commit is contained in:
parent
0af2931672
commit
f787418e4b
@ -226,7 +226,7 @@ func buildLogAnalyticsQuery(query backend.DataQuery, dsInfo types.DatasourceInfo
|
|||||||
|
|
||||||
func (e *AzureLogAnalyticsDatasource) buildQueries(ctx context.Context, queries []backend.DataQuery, dsInfo types.DatasourceInfo, fromAlert bool) ([]*AzureLogAnalyticsQuery, error) {
|
func (e *AzureLogAnalyticsDatasource) buildQueries(ctx context.Context, queries []backend.DataQuery, dsInfo types.DatasourceInfo, fromAlert bool) ([]*AzureLogAnalyticsQuery, error) {
|
||||||
azureLogAnalyticsQueries := []*AzureLogAnalyticsQuery{}
|
azureLogAnalyticsQueries := []*AzureLogAnalyticsQuery{}
|
||||||
appInsightsRegExp, err := regexp.Compile("providers/Microsoft.Insights/components")
|
appInsightsRegExp, err := regexp.Compile("(?i)providers/microsoft.insights/components")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to compile Application Insights regex")
|
return nil, fmt.Errorf("failed to compile Application Insights regex")
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
appInsightsRegExp, err := regexp.Compile("providers/Microsoft.Insights/components")
|
appInsightsRegExp, err := regexp.Compile("(?i)providers/microsoft.insights/components")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to compile reg: %w", err)
|
t.Error("failed to compile reg: %w", err)
|
||||||
}
|
}
|
||||||
@ -442,6 +442,84 @@ func TestBuildLogAnalyticsQuery(t *testing.T) {
|
|||||||
azureLogAnalyticsQuery: nil,
|
azureLogAnalyticsQuery: nil,
|
||||||
Err: require.Error,
|
Err: require.Error,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Detects App Insights resource queries",
|
||||||
|
fromAlert: false,
|
||||||
|
queryModel: backend.DataQuery{
|
||||||
|
JSON: []byte(fmt.Sprintf(`{
|
||||||
|
"queryType": "Azure Log Analytics",
|
||||||
|
"azureLogAnalytics": {
|
||||||
|
"resources": ["/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.Insights/components/AppInsightsTestDataWorkspace"],
|
||||||
|
"query": "Perf | where $__timeFilter() | where $__contains(Computer, 'comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer",
|
||||||
|
"resultFormat": "%s",
|
||||||
|
"dashboardTime": false
|
||||||
|
}
|
||||||
|
}`, dataquery.ResultFormatTimeSeries)),
|
||||||
|
RefID: "A",
|
||||||
|
TimeRange: timeRange,
|
||||||
|
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
|
||||||
|
},
|
||||||
|
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
|
||||||
|
RefID: "A",
|
||||||
|
ResultFormat: dataquery.ResultFormatTimeSeries,
|
||||||
|
URL: "v1/apps/AppInsightsTestDataWorkspace/query",
|
||||||
|
JSON: []byte(fmt.Sprintf(`{
|
||||||
|
"queryType": "Azure Log Analytics",
|
||||||
|
"azureLogAnalytics": {
|
||||||
|
"resources": ["/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.Insights/components/AppInsightsTestDataWorkspace"],
|
||||||
|
"query": "Perf | where $__timeFilter() | where $__contains(Computer, 'comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer",
|
||||||
|
"resultFormat": "%s",
|
||||||
|
"dashboardTime": false
|
||||||
|
}
|
||||||
|
}`, dataquery.ResultFormatTimeSeries)),
|
||||||
|
Query: "Perf | where ['TimeGenerated'] >= datetime('2018-03-15T13:00:00Z') and ['TimeGenerated'] <= datetime('2018-03-15T13:34:00Z') | where ['Computer'] in ('comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, 34000ms), Computer",
|
||||||
|
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/Microsoft.Insights/components/AppInsightsTestDataWorkspace"},
|
||||||
|
TimeRange: timeRange,
|
||||||
|
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
|
||||||
|
AppInsightsQuery: true,
|
||||||
|
DashboardTime: false,
|
||||||
|
}),
|
||||||
|
Err: require.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Detects App Insights resource queries (case insensitive)",
|
||||||
|
fromAlert: false,
|
||||||
|
queryModel: backend.DataQuery{
|
||||||
|
JSON: []byte(fmt.Sprintf(`{
|
||||||
|
"queryType": "Azure Log Analytics",
|
||||||
|
"azureLogAnalytics": {
|
||||||
|
"resources": ["/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/microsoft.insights/components/AppInsightsTestDataWorkspace"],
|
||||||
|
"query": "Perf | where $__timeFilter() | where $__contains(Computer, 'comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer",
|
||||||
|
"resultFormat": "%s",
|
||||||
|
"dashboardTime": false
|
||||||
|
}
|
||||||
|
}`, dataquery.ResultFormatTimeSeries)),
|
||||||
|
RefID: "A",
|
||||||
|
TimeRange: timeRange,
|
||||||
|
QueryType: string(dataquery.AzureQueryTypeAzureLogAnalytics),
|
||||||
|
},
|
||||||
|
azureLogAnalyticsQuery: makeQueryPointer(AzureLogAnalyticsQuery{
|
||||||
|
RefID: "A",
|
||||||
|
ResultFormat: dataquery.ResultFormatTimeSeries,
|
||||||
|
URL: "v1/apps/AppInsightsTestDataWorkspace/query",
|
||||||
|
JSON: []byte(fmt.Sprintf(`{
|
||||||
|
"queryType": "Azure Log Analytics",
|
||||||
|
"azureLogAnalytics": {
|
||||||
|
"resources": ["/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/microsoft.insights/components/AppInsightsTestDataWorkspace"],
|
||||||
|
"query": "Perf | where $__timeFilter() | where $__contains(Computer, 'comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, $__interval), Computer",
|
||||||
|
"resultFormat": "%s",
|
||||||
|
"dashboardTime": false
|
||||||
|
}
|
||||||
|
}`, dataquery.ResultFormatTimeSeries)),
|
||||||
|
Query: "Perf | where ['TimeGenerated'] >= datetime('2018-03-15T13:00:00Z') and ['TimeGenerated'] <= datetime('2018-03-15T13:34:00Z') | where ['Computer'] in ('comp1','comp2') | summarize avg(CounterValue) by bin(TimeGenerated, 34000ms), Computer",
|
||||||
|
Resources: []string{"/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/cloud-datasources/providers/microsoft.insights/components/AppInsightsTestDataWorkspace"},
|
||||||
|
TimeRange: timeRange,
|
||||||
|
QueryType: dataquery.AzureQueryTypeAzureLogAnalytics,
|
||||||
|
AppInsightsQuery: true,
|
||||||
|
DashboardTime: false,
|
||||||
|
}),
|
||||||
|
Err: require.NoError,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user