Skip to content

[enhancement] export reqeust size metrics #7087

@qdongxu

Description

@qdongxu

There're 2 items related with the http request size.

  1. caddyhttp.computeApproximateRequestSize : cacluates a normal http request from the Content-Lenght header, does not applicable to Transfer-Encoding: chunked bodies or a websocket connection.
  2. Server.logRequest handle the request size in a special way by just logged it as the bytes_read field in the log.

Propose to align the behavior of request size with response size.

  1. add a method in the ResponseRecorder interface.
type ResponseRecorder interface {
	http.ResponseWriter
	Status() int
	Buffer() *bytes.Buffer
	Buffered() bool
	Size() int
	ReqSize() int  // propose to export
	WriteResponse() error
}
  1. export http.request.size as a replacer as well as http.response.size, the latter was exported after the the upstream response received or aborted.

  2. update the synmantic of the prometheus metrics request_size_bytes, by ResponseRecorder.ReqSize() to including all bytes of an http request, e.g. Transfer-Encoding: chunked bodies or a websocket connection.

  3. keep the log field bytes_read unchanged to keep backward compatibility.

If this proposal is accepted I'm happy to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions