Beispiel #1
0
func (h *HTTPHandler) handleAdd(rw http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	var (
		messages common.TieredSmapMessage
		err      error
	)
	defer req.Body.Close()

	if messages, err = handleJSON(req.Body); err != nil {
		log.Errorf("Error handling JSON: %v", err)
		rw.WriteHeader(400)
		rw.Write([]byte(err.Error()))
		return
	}

	messages.CollapseToTimeseries()
	for _, msg := range messages {
		if addErr := h.a.AddData(msg); addErr != nil {
			rw.WriteHeader(500)
			rw.Write([]byte(addErr.Error()))
			return
		}
	}

	rw.WriteHeader(200)
}
Beispiel #2
0
func (tcp *TCPJSONHandler) handleAdd(conn net.Conn) {
	var (
		messages common.TieredSmapMessage
		err      error
	)
	if messages, err = handleJSON(conn); err != nil {
		log.Errorf("Error handling JSON: %v", err)
		tcp.errors <- err
		return
	}
	messages.CollapseToTimeseries()
	for _, msg := range messages {
		if addErr := tcp.a.AddData(msg); addErr != nil {
			log.Errorf("Error handling JSON: %v", err)
			tcp.errors <- err
			conn.Close()
			return
		}
	}

}