mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch Logs: Move query response stats to appropriate FrameMeta property (#26732)
* CloudWatch Logs: Move query response stats to appropriate FrameMeta property
This commit is contained in:
parent
96babf1268
commit
a1f90521a0
@ -489,10 +489,19 @@ func TestQuery_GetQueryResults(t *testing.T) {
|
||||
expFrame.Meta = &data.FrameMeta{
|
||||
Custom: map[string]interface{}{
|
||||
"Status": "Complete",
|
||||
"Statistics": cloudwatchlogs.QueryStatistics{
|
||||
BytesScanned: aws.Float64(512),
|
||||
RecordsMatched: aws.Float64(256),
|
||||
RecordsScanned: aws.Float64(1024),
|
||||
},
|
||||
Stats: []data.QueryStat{
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Bytes scanned"},
|
||||
Value: 512,
|
||||
},
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records scanned"},
|
||||
Value: 1024,
|
||||
},
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records matched"},
|
||||
Value: 256,
|
||||
},
|
||||
},
|
||||
PreferredVisualization: "logs",
|
||||
|
@ -12,6 +12,10 @@ import (
|
||||
)
|
||||
|
||||
func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*data.Frame, error) {
|
||||
if response == nil {
|
||||
return nil, fmt.Errorf("response is nil, cannot convert log results to data frames")
|
||||
}
|
||||
|
||||
nonEmptyRows := make([][]*cloudwatchlogs.ResultField, 0)
|
||||
// Sometimes CloudWatch can send empty rows
|
||||
for _, row := range response.Results {
|
||||
@ -94,12 +98,44 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
|
||||
}
|
||||
}
|
||||
|
||||
queryStats := make([]data.QueryStat, 0)
|
||||
if response.Statistics != nil {
|
||||
if response.Statistics.BytesScanned != nil {
|
||||
queryStats = append(queryStats, data.QueryStat{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Bytes scanned"},
|
||||
Value: *response.Statistics.BytesScanned,
|
||||
})
|
||||
}
|
||||
|
||||
if response.Statistics.RecordsScanned != nil {
|
||||
queryStats = append(queryStats, data.QueryStat{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records scanned"},
|
||||
Value: *response.Statistics.RecordsScanned,
|
||||
})
|
||||
}
|
||||
|
||||
if response.Statistics.RecordsMatched != nil {
|
||||
queryStats = append(queryStats, data.QueryStat{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records matched"},
|
||||
Value: *response.Statistics.RecordsMatched,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
frame := data.NewFrame("CloudWatchLogsResponse", newFields...)
|
||||
frame.Meta = &data.FrameMeta{
|
||||
Custom: map[string]interface{}{
|
||||
"Status": *response.Status,
|
||||
"Statistics": *response.Statistics,
|
||||
},
|
||||
Stats: nil,
|
||||
Custom: nil,
|
||||
}
|
||||
|
||||
if len(queryStats) > 0 {
|
||||
frame.Meta.Stats = queryStats
|
||||
}
|
||||
|
||||
if response.Status != nil {
|
||||
frame.Meta.Custom = map[string]interface{}{
|
||||
"Status": *response.Status,
|
||||
}
|
||||
}
|
||||
|
||||
// Results aren't guaranteed to come ordered by time (ascending), so we need to sort
|
||||
|
@ -195,10 +195,19 @@ func TestLogsResultsToDataframes(t *testing.T) {
|
||||
Meta: &data.FrameMeta{
|
||||
Custom: map[string]interface{}{
|
||||
"Status": "ok",
|
||||
"Statistics": cloudwatchlogs.QueryStatistics{
|
||||
BytesScanned: aws.Float64(2000),
|
||||
RecordsMatched: aws.Float64(3),
|
||||
RecordsScanned: aws.Float64(5000),
|
||||
},
|
||||
Stats: []data.QueryStat{
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Bytes scanned"},
|
||||
Value: 2000,
|
||||
},
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records scanned"},
|
||||
Value: 5000,
|
||||
},
|
||||
{
|
||||
FieldConfig: data.FieldConfig{DisplayName: "Records matched"},
|
||||
Value: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -248,7 +248,8 @@ export class CloudWatchDatasource extends DataSourceApi<CloudWatchQuery, CloudWa
|
||||
map(frames => {
|
||||
let moreRecordsMatched = false;
|
||||
for (const frame of frames) {
|
||||
const recordsMatched = frame.meta?.custom?.['Statistics']['RecordsMatched'];
|
||||
const recordsMatched = frame.meta?.stats?.find(stat => stat.displayName === 'Records matched')
|
||||
?.value!;
|
||||
if (recordsMatched > (prevRecordsMatched[frame.refId!] ?? 0)) {
|
||||
moreRecordsMatched = true;
|
||||
}
|
||||
|
@ -167,8 +167,11 @@ describe('CloudWatchDatasource', () => {
|
||||
it('should stop querying when no more data retrieved past max attempts', async () => {
|
||||
const fakeFrames = genMockFrames(10);
|
||||
for (let i = 7; i < fakeFrames.length; i++) {
|
||||
fakeFrames[i].meta!.custom!['Statistics']['RecordsMatched'] = fakeFrames[6].meta!.custom!['Statistics'][
|
||||
'RecordsMatched'
|
||||
fakeFrames[i].meta!.stats = [
|
||||
{
|
||||
displayName: 'Records matched',
|
||||
value: fakeFrames[6].meta!.stats?.find(stat => stat.displayName === 'Records matched')?.value!,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@ -193,6 +196,7 @@ describe('CloudWatchDatasource', () => {
|
||||
...fakeFrames[MAX_ATTEMPTS - 1].meta!.custom,
|
||||
Status: 'Complete',
|
||||
},
|
||||
stats: fakeFrames[MAX_ATTEMPTS - 1].meta!.stats,
|
||||
},
|
||||
},
|
||||
];
|
||||
@ -1101,10 +1105,13 @@ function genMockFrames(numResponses: number): DataFrame[] {
|
||||
meta: {
|
||||
custom: {
|
||||
Status: i === numResponses - 1 ? CloudWatchLogsQueryStatus.Complete : CloudWatchLogsQueryStatus.Running,
|
||||
Statistics: {
|
||||
RecordsMatched: (i + 1) * recordIncrement,
|
||||
},
|
||||
},
|
||||
stats: [
|
||||
{
|
||||
displayName: 'Records matched',
|
||||
value: (i + 1) * recordIncrement,
|
||||
},
|
||||
],
|
||||
},
|
||||
length: 0,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user