func (h *HTTPSink) drainEvents(events []EventData) {
	h.bodyBuf.Truncate(0)
	var written int64
	for _, evt := range events {
		w, err := evt.WriteRFC5424(h.bodyBuf)
		written += w
		if err != nil {
			glog.Warningf("Could not write to event request body (wrote %v) bytes: %v", written, err)
			return
		}
		h.bodyBuf.Write([]byte{'\n'})
		written++
	}
	req, err := http.NewRequest("POST", h.SinkURL, h.bodyBuf)
	if err != nil {
		glog.Warningf(err.Error())
		return
	}
	resp, err := h.httpClient.Do(req)
	if err != nil {
		glog.Warningf(err.Error())
		return
	}
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		glog.Warningf("Got HTTP code %v from %v", resp.StatusCode, h.SinkURL)
	}
}
drainEvents takes an array of event data and sends it to the receiving HTTP
server. This function is *NOT* re-entrant: it re-uses the same body buffer
for each call, truncating it each time to avoid extra memory allocations.
package sinks
import (
	"bytes"
	"net/http"
	"github.com/eapache/channels"
	"github.com/golang/glog"
	"github.com/sethgrid/pester"
	"k8s.io/api/core/v1"
)
type HTTPSink struct {
	SinkURL string
	eventCh    channels.Channel
	httpClient *pester.Client
	bodyBuf    *bytes.Buffer
}
func NewHTTPSink(sinkURL string, overflow bool, bufferSize int) *HTTPSink {
	h := &HTTPSink{
		SinkURL: sinkURL,
	}
	if overflow {
		h.eventCh = channels.NewOverflowingChannel(channels.BufferCap(bufferSize))
	} else {
		h.eventCh = channels.NewNativeChannel(channels.BufferCap(bufferSize))
	}
	h.httpClient = pester.New()
	h.httpClient.Backoff = pester.ExponentialJitterBackoff
	h.httpClient.MaxRetries = 10
	h.bodyBuf = bytes.NewBuffer(make([]byte, 0, 4096))
	return h
}
func (h *HTTPSink) UpdateEvents(eNew *v1.Event, eOld *v1.Event) {
	h.eventCh.In() <- NewEventData(eNew, eOld)
}
func (h *HTTPSink) Run(stopCh <-chan bool) {
loop:
	for {
		select {
		case e := <-h.eventCh.Out():
			var evt EventData
			var ok bool
			if evt, ok = e.(EventData); !ok {
				glog.Warningf("Invalid type sent through event channel: %T", e)
				continue loop
			}
			arr := []EventData{evt}
			numEvents := h.eventCh.Len()
			for i := 0; i < numEvents; i++ {
				e := <-h.eventCh.Out()
				if evt, ok = e.(EventData); ok {
					arr = append(arr, evt)
				} else {
					glog.Warningf("Invalid type sent through event channel: %T", e)
				}
			}
			h.drainEvents(arr)
		case <-stopCh:
			break loop
		}
	}
}