@@ -12,6 +12,10 @@ import (
12
12
)
13
13
14
14
func logsResultsToDataframes (response * cloudwatchlogs.GetQueryResultsOutput ) (* data.Frame , error ) {
15
+ if response == nil {
16
+ return nil , fmt .Errorf ("response is nil, cannot convert log results to data frames" )
17
+ }
18
+
15
19
nonEmptyRows := make ([][]* cloudwatchlogs.ResultField , 0 )
16
20
// Sometimes CloudWatch can send empty rows
17
21
for _ , row := range response .Results {
@@ -94,12 +98,44 @@ func logsResultsToDataframes(response *cloudwatchlogs.GetQueryResultsOutput) (*d
94
98
}
95
99
}
96
100
101
+ queryStats := make ([]data.QueryStat , 0 )
102
+ if response .Statistics != nil {
103
+ if response .Statistics .BytesScanned != nil {
104
+ queryStats = append (queryStats , data.QueryStat {
105
+ FieldConfig : data.FieldConfig {DisplayName : "Bytes scanned" },
106
+ Value : * response .Statistics .BytesScanned ,
107
+ })
108
+ }
109
+
110
+ if response .Statistics .RecordsScanned != nil {
111
+ queryStats = append (queryStats , data.QueryStat {
112
+ FieldConfig : data.FieldConfig {DisplayName : "Records scanned" },
113
+ Value : * response .Statistics .RecordsScanned ,
114
+ })
115
+ }
116
+
117
+ if response .Statistics .RecordsMatched != nil {
118
+ queryStats = append (queryStats , data.QueryStat {
119
+ FieldConfig : data.FieldConfig {DisplayName : "Records matched" },
120
+ Value : * response .Statistics .RecordsMatched ,
121
+ })
122
+ }
123
+ }
124
+
97
125
frame := data .NewFrame ("CloudWatchLogsResponse" , newFields ... )
98
126
frame .Meta = & data.FrameMeta {
99
- Custom : map [string ]interface {}{
100
- "Status" : * response .Status ,
101
- "Statistics" : * response .Statistics ,
102
- },
127
+ Stats : nil ,
128
+ Custom : nil ,
129
+ }
130
+
131
+ if len (queryStats ) > 0 {
132
+ frame .Meta .Stats = queryStats
133
+ }
134
+
135
+ if response .Status != nil {
136
+ frame .Meta .Custom = map [string ]interface {}{
137
+ "Status" : * response .Status ,
138
+ }
103
139
}
104
140
105
141
// Results aren't guaranteed to come ordered by time (ascending), so we need to sort
0 commit comments