AzureMonitor: Set timespan in Logs Portal URL link (#71841)

Set timespan in Logs Portal URL link
This commit is contained in:
Andreas Christou 2023-07-19 09:15:14 +01:00 committed by GitHub
parent f75a3d04cf
commit 116e971af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -357,7 +357,7 @@ func (e *AzureLogAnalyticsDatasource) executeQuery(ctx context.Context, logger l
} }
} }
queryUrl, err := getQueryUrl(query.Query, query.Resources, azurePortalBaseUrl) queryUrl, err := getQueryUrl(query.Query, query.Resources, azurePortalBaseUrl, query.TimeRange)
if err != nil { if err != nil {
dataResponse.Error = err dataResponse.Error = err
return dataResponse return dataResponse
@ -493,7 +493,7 @@ type AzureLogAnalyticsURLResource struct {
ResourceID string `json:"resourceId"` ResourceID string `json:"resourceId"`
} }
func getQueryUrl(query string, resources []string, azurePortalUrl string) (string, error) { func getQueryUrl(query string, resources []string, azurePortalUrl string, timeRange backend.TimeRange) (string, error) {
encodedQuery, err := encodeQuery(query) encodedQuery, err := encodeQuery(query)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to encode the query: %s", err) return "", fmt.Errorf("failed to encode the query: %s", err)
@ -517,8 +517,11 @@ func getQueryUrl(query string, resources []string, azurePortalUrl string) (strin
if err != nil { if err != nil {
return "", fmt.Errorf("failed to marshal log analytics resources: %s", err) return "", fmt.Errorf("failed to marshal log analytics resources: %s", err)
} }
from := timeRange.From.Format(time.RFC3339)
to := timeRange.To.Format(time.RFC3339)
timespan := url.QueryEscape(fmt.Sprintf("%s/%s", from, to))
portalUrl += url.QueryEscape(string(resourcesMarshalled)) portalUrl += url.QueryEscape(string(resourcesMarshalled))
portalUrl += "/query/" + url.PathEscape(encodedQuery) + "/isQueryBase64Compressed/true/timespanInIsoFormat/P1D" portalUrl += "/query/" + url.PathEscape(encodedQuery) + "/isQueryBase64Compressed/true/timespan/" + timespan
return portalUrl, nil return portalUrl, nil
} }