[v10.0.x] AzureMonitor: Fix logs query multi-resource and timespan values (#67933)
AzureMonitor: Fix logs query multi-resource and timespan values (#67914)
* Update TimeGrain interface methods
- Make them util functions because it's simpler
* Update logs ds to appropiately set resources and timespan
* Set timespan using RCF times
* Update tests
(cherry picked from commit 9d16718acc)
Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
This commit is contained in:
committed by
GitHub
parent
8a8d796c1f
commit
25a9d90d9e
@@ -872,7 +872,7 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
|
||||
if !cmp.Equal(req.Header, expectedHeaders) {
|
||||
t.Errorf("Unexpected HTTP headers: %v", cmp.Diff(req.Header, expectedHeaders))
|
||||
}
|
||||
expectedBody := `{"query":"Perf"}`
|
||||
expectedBody := `{"query":"Perf","timespan":"0001-01-01T00:00:00Z/0001-01-01T00:00:00Z"}`
|
||||
body, err := io.ReadAll(req.Body)
|
||||
require.NoError(t, err)
|
||||
if !cmp.Equal(string(body), expectedBody) {
|
||||
@@ -887,7 +887,28 @@ func TestLogAnalyticsCreateRequest(t *testing.T) {
|
||||
Query: "Perf",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
expectedBody := `{"query":"Perf","resources":["r1","r2"]}`
|
||||
expectedBody := `{"query":"Perf","timespan":"0001-01-01T00:00:00Z/0001-01-01T00:00:00Z","workspaces":["r1","r2"]}`
|
||||
body, err := io.ReadAll(req.Body)
|
||||
require.NoError(t, err)
|
||||
if !cmp.Equal(string(body), expectedBody) {
|
||||
t.Errorf("Unexpected Body: %v", cmp.Diff(string(body), expectedBody))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("creates a request with timerange from query", func(t *testing.T) {
|
||||
ds := AzureLogAnalyticsDatasource{}
|
||||
from := time.Now()
|
||||
to := from.Add(3 * time.Hour)
|
||||
req, err := ds.createRequest(ctx, logger, url, &AzureLogAnalyticsQuery{
|
||||
Resources: []string{"r1", "r2"},
|
||||
Query: "Perf",
|
||||
TimeRange: backend.TimeRange{
|
||||
From: from,
|
||||
To: to,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
expectedBody := fmt.Sprintf(`{"query":"Perf","timespan":"%s/%s","workspaces":["r1","r2"]}`, from.Format(time.RFC3339), to.Format(time.RFC3339))
|
||||
body, err := io.ReadAll(req.Body)
|
||||
require.NoError(t, err)
|
||||
if !cmp.Equal(string(body), expectedBody) {
|
||||
|
||||
Reference in New Issue
Block a user