Skip to content

Commit

Permalink
better logging of request parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Oct 2, 2023
1 parent bbee883 commit 00a64b2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ func (s *Server) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.WriteHeader(http.StatusInternalServerError)
return
}
// prepare body to be read by parseparams
// prepare body to be read by ParseForm
req.Body = io.NopCloser(bytes.NewReader(body))
params, err := s.ParseParams(req)
err = req.ParseForm()
if err != nil {
resp.WriteHeader(http.StatusBadRequest)
fmt.Printf("Failed to parse params: %s\n", err)
fmt.Printf("Failed to parse form: %s", err)
}
params, err := s.ParseParams(req.Form)
if err != nil {
resp.WriteHeader(http.StatusBadRequest)
fmt.Printf("Failed to parse params %+v: %s\n", req.Form, err)
return
}

Expand Down Expand Up @@ -193,22 +198,18 @@ func (s *Server) ParseQuery(query string) (*ParsedQuery, error) {
}

// ParseParams parses all of the information needed from the prometheus request.
func (s *Server) ParseParams(req *http.Request) (*Params, error) {
err := req.ParseForm()
if err != nil {
return nil, err
}
pq, err := s.ParseQuery(req.Form.Get("query"))
func (s *Server) ParseParams(Form url.Values) (*Params, error) {
pq, err := s.ParseQuery(Form.Get("query"))
if err != nil {
return nil, err
}
// fixme: <rfc3339 | unix_timestamp>
// error
start, _ := strconv.ParseInt(req.Form.Get("start"), 10, 64)
end, _ := strconv.ParseInt(req.Form.Get("end"), 10, 64)
start, _ := strconv.ParseInt(Form.Get("start"), 10, 64)
end, _ := strconv.ParseInt(Form.Get("end"), 10, 64)
// fixme: <duration | float>
// error
step, _ := strconv.ParseInt(req.Form.Get("step"), 10, 64)
step, _ := strconv.ParseInt(Form.Get("step"), 10, 64)
return &Params{
Start: start,
End: end,
Expand Down

0 comments on commit 00a64b2

Please sign in to comment.