@@ -23,10 +23,12 @@ import (
2323 "path"
2424 "regexp"
2525 "sort"
26+ "strconv"
2627 "strings"
2728 "time"
2829
2930 "github.com/golang/glog"
31+ "github.com/google/cadvisor/events"
3032 "github.com/google/cadvisor/info"
3133 "github.com/google/cadvisor/manager"
3234)
@@ -125,6 +127,7 @@ func writeResult(res interface{}, w http.ResponseWriter) error {
125127 w .Header ().Set ("Content-Type" , "application/json" )
126128 w .Write (out )
127129 return nil
130+
128131}
129132
130133func getContainerInfoRequest (body io.ReadCloser ) (* info.ContainerInfoRequest , error ) {
@@ -142,6 +145,74 @@ func getContainerInfoRequest(body io.ReadCloser) (*info.ContainerInfoRequest, er
142145 return & query , nil
143146}
144147
148+ // The user can set any or none of the following arguments in any order
149+ // with any twice defined arguments being assigned the first value.
150+ // If the value type for the argument is wrong the field will be assumed to be
151+ // unassigned
152+ // bools: historical, subcontainers, oom_events, creation_events, deletion_events
153+ // ints: max_events, start_time (unix timestamp), end_time (unix timestamp)
154+ // example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&historical=true&max_events=10
155+ func getEventRequest (r * http.Request ) (* events.Request , bool , error ) {
156+ query := events .NewRequest ()
157+ getHistoricalEvents := false
158+
159+ urlMap := r .URL .Query ()
160+
161+ if val , ok := urlMap ["historical" ]; ok {
162+ newBool , err := strconv .ParseBool (val [0 ])
163+ if err == nil {
164+ getHistoricalEvents = newBool
165+ }
166+ }
167+ if val , ok := urlMap ["subcontainers" ]; ok {
168+ newBool , err := strconv .ParseBool (val [0 ])
169+ if err == nil {
170+ query .IncludeSubcontainers = newBool
171+ }
172+ }
173+ if val , ok := urlMap ["oom_events" ]; ok {
174+ newBool , err := strconv .ParseBool (val [0 ])
175+ if err == nil {
176+ query .EventType [events .TypeOom ] = newBool
177+ }
178+ }
179+ if val , ok := urlMap ["creation_events" ]; ok {
180+ newBool , err := strconv .ParseBool (val [0 ])
181+ if err == nil {
182+ query .EventType [events .TypeContainerCreation ] = newBool
183+ }
184+ }
185+ if val , ok := urlMap ["deletion_events" ]; ok {
186+ newBool , err := strconv .ParseBool (val [0 ])
187+ if err == nil {
188+ query .EventType [events .TypeContainerDeletion ] = newBool
189+ }
190+ }
191+ if val , ok := urlMap ["max_events" ]; ok {
192+ newInt , err := strconv .Atoi (val [0 ])
193+ if err == nil {
194+ query .MaxEventsReturned = int (newInt )
195+ }
196+ }
197+ if val , ok := urlMap ["start_time" ]; ok {
198+ newTime , err := time .Parse (time .RFC3339 , val [0 ])
199+ if err == nil {
200+ query .StartTime = newTime
201+ }
202+ }
203+ if val , ok := urlMap ["end_time" ]; ok {
204+ newTime , err := time .Parse (time .RFC3339 , val [0 ])
205+ if err == nil {
206+ query .EndTime = newTime
207+ }
208+ }
209+
210+ glog .V (2 ).Infof (
211+ "%v was returned in api/handler.go:getEventRequest from the url rawQuery %v" ,
212+ query , r .URL .RawQuery )
213+ return query , getHistoricalEvents , nil
214+ }
215+
145216func getContainerName (request []string ) string {
146217 return path .Join ("/" , strings .Join (request , "/" ))
147218}
0 commit comments