Change historical to stream so it can default to false.
Defaulting to non-watch makes it easy to query in a browser and curl.
This commit is contained in:
parent
c0121e15ce
commit
8af583c35e
@ -180,19 +180,19 @@ func getContainerInfoRequest(body io.ReadCloser) (*info.ContainerInfoRequest, er
|
||||
// with any twice defined arguments being assigned the first value.
|
||||
// If the value type for the argument is wrong the field will be assumed to be
|
||||
// unassigned
|
||||
// bools: historical, subcontainers, oom_events, creation_events, deletion_events
|
||||
// bools: stream, subcontainers, oom_events, creation_events, deletion_events
|
||||
// ints: max_events, start_time (unix timestamp), end_time (unix timestamp)
|
||||
// example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&historical=true&max_events=10
|
||||
// example r.URL: http://localhost:8080/api/v1.3/events?oom_events=true&stream=true
|
||||
func getEventRequest(r *http.Request) (*events.Request, bool, error) {
|
||||
query := events.NewRequest()
|
||||
getHistoricalEvents := false
|
||||
stream := false
|
||||
|
||||
urlMap := r.URL.Query()
|
||||
|
||||
if val, ok := urlMap["historical"]; ok {
|
||||
if val, ok := urlMap["stream"]; ok {
|
||||
newBool, err := strconv.ParseBool(val[0])
|
||||
if err == nil {
|
||||
getHistoricalEvents = newBool
|
||||
stream = newBool
|
||||
}
|
||||
}
|
||||
if val, ok := urlMap["subcontainers"]; ok {
|
||||
@ -241,7 +241,7 @@ func getEventRequest(r *http.Request) (*events.Request, bool, error) {
|
||||
glog.V(2).Infof(
|
||||
"%v was returned in api/handler.go:getEventRequest from the url rawQuery %v",
|
||||
query, r.URL.RawQuery)
|
||||
return query, getHistoricalEvents, nil
|
||||
return query, stream, nil
|
||||
}
|
||||
|
||||
func getContainerName(request []string) string {
|
||||
|
@ -268,12 +268,12 @@ func (self *version1_3) HandleRequest(requestType string, request []string, m ma
|
||||
}
|
||||
|
||||
func handleEventRequest(m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||
query, eventsFromAllTime, err := getEventRequest(r)
|
||||
query, stream, err := getEventRequest(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.V(2).Infof("Api - Events(%v)", query)
|
||||
if eventsFromAllTime {
|
||||
if !stream {
|
||||
pastEvents, err := m.GetPastEvents(query)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -34,20 +34,19 @@ func makeHTTPRequest(requestURL string, t *testing.T) *http.Request {
|
||||
}
|
||||
|
||||
func TestGetEventRequestBasicRequest(t *testing.T) {
|
||||
r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?oom_events=true&historical=true&max_events=10", t)
|
||||
expectedQuery := &events.Request{
|
||||
EventType: map[info.EventType]bool{
|
||||
info.EventOom: true,
|
||||
},
|
||||
MaxEventsReturned: 10,
|
||||
r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?oom_events=true&stream=false&max_events=20", t)
|
||||
expectedQuery := events.NewRequest()
|
||||
expectedQuery.EventType = map[info.EventType]bool{
|
||||
info.EventOom: true,
|
||||
}
|
||||
expectedQuery.MaxEventsReturned = 20
|
||||
|
||||
receivedQuery, getHistoricalEvents, err := getEventRequest(r)
|
||||
receivedQuery, stream, err := getEventRequest(r)
|
||||
|
||||
if !reflect.DeepEqual(expectedQuery, receivedQuery) {
|
||||
t.Errorf("expected %v but received %v", expectedQuery, receivedQuery)
|
||||
t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
|
||||
}
|
||||
assert.True(t, getHistoricalEvents)
|
||||
assert.False(t, stream)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@ -55,28 +54,27 @@ func TestGetEventEmptyRequest(t *testing.T) {
|
||||
r := makeHTTPRequest("", t)
|
||||
expectedQuery := events.NewRequest()
|
||||
|
||||
receivedQuery, getHistoricalEvents, err := getEventRequest(r)
|
||||
receivedQuery, stream, err := getEventRequest(r)
|
||||
|
||||
if !reflect.DeepEqual(expectedQuery, receivedQuery) {
|
||||
t.Errorf("expected %v but received %v", expectedQuery, receivedQuery)
|
||||
t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
|
||||
}
|
||||
assert.False(t, getHistoricalEvents)
|
||||
assert.False(t, stream)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestGetEventRequestDoubleArgument(t *testing.T) {
|
||||
r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?historical=true&oom_events=true&oom_events=false", t)
|
||||
expectedQuery := &events.Request{
|
||||
EventType: map[info.EventType]bool{
|
||||
info.EventOom: true,
|
||||
},
|
||||
r := makeHTTPRequest("http://localhost:8080/api/v1.3/events?stream=true&oom_events=true&oom_events=false", t)
|
||||
expectedQuery := events.NewRequest()
|
||||
expectedQuery.EventType = map[info.EventType]bool{
|
||||
info.EventOom: true,
|
||||
}
|
||||
|
||||
receivedQuery, getHistoricalEvents, err := getEventRequest(r)
|
||||
receivedQuery, stream, err := getEventRequest(r)
|
||||
|
||||
if !reflect.DeepEqual(expectedQuery, receivedQuery) {
|
||||
t.Errorf("expected %v but received %v", expectedQuery, receivedQuery)
|
||||
t.Errorf("expected %#v but received %#v", expectedQuery, receivedQuery)
|
||||
}
|
||||
assert.True(t, getHistoricalEvents)
|
||||
assert.True(t, stream)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user