Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model/modeldecoder: stop extracting "user.user-agent" from metadata fields #3885

Closed
axw opened this issue Jun 15, 2020 · 1 comment
Closed
Assignees

Comments

@axw
Copy link
Member

axw commented Jun 15, 2020

In beater/middleware (in request_metadata_middleware.go) we record metadata fields related to the HTTP request received. When we process stream metadata, we first create a map based on the request metadata, and then layer on top the stream metadata.

One of the keys set by the middleware is user.user-agent, which is not part of the JSON Schema. In theory agents could send this field and the server would parse it.

I propose we have the middleware record information into a struct, and then when decoding stream metadata we initialise the metadata struct with those fields explicitly. i.e. something like

func UserMetadataMiddleware() Middleware {
        return func(h request.Handler) (request.Handler, error) {
                return func(c *request.Context) {
                        dec := utility.ManualDecoder{}
                        c.RequestMetadata.UserAgent = dec.UserAgentHeader(c.Request.Header)
                        c.RequestMetadata.User.IP = utility.ExtractIP(c.Request)
                        h(c)
                }, nil
        }
}
metadata := c.RequestMetadata
err := modeldecoder.DecodeMetadata(input, &metadata)
...
@zube zube bot added the [zube]: Backlog label Jun 17, 2020
@simitt simitt self-assigned this Jul 3, 2020
@zube zube bot unassigned simitt Jul 3, 2020
@simitt simitt self-assigned this Jul 3, 2020
simitt added a commit to simitt/apm-server that referenced this issue Jul 3, 2020
Decode request metadata into struct instead of a map and pass metadata struct
into decoder function.

implements elastic#3885
simitt added a commit to simitt/apm-server that referenced this issue Jul 3, 2020
Decode request metadata into struct instead of a map and pass metadata struct
into decoder function. The refactoring automatically fixes a bug where client.ip
and user_agent was not set for v3 RUM events.

implements elastic#3885
fixes elastic#3942
simitt added a commit that referenced this issue Jul 6, 2020
Decode request metadata into a struct instead of a map and pass the metadata struct
into a decoder function. The refactoring automatically fixes a bug where the `client.ip`
and `user_agent` were not set for v3 RUM events.

implements #3885
fixes #3942
simitt added a commit to simitt/apm-server that referenced this issue Jul 6, 2020
Decode request metadata into a struct instead of a map and pass the metadata struct
into a decoder function. The refactoring automatically fixes a bug where the `client.ip`
and `user_agent` were not set for v3 RUM events.

implements elastic#3885
fixes elastic#3942
simitt added a commit to simitt/apm-server that referenced this issue Jul 6, 2020
Decode request metadata into a struct instead of a map and pass the metadata struct
into a decoder function. The refactoring automatically fixes a bug where the `client.ip`
and `user_agent` were not set for v3 RUM events.

implements elastic#3885
fixes elastic#3942
simitt added a commit that referenced this issue Jul 6, 2020
Decode request metadata into a struct instead of a map and pass the metadata struct
into a decoder function. The refactoring automatically fixes a bug where the `client.ip`
and `user_agent` were not set for v3 RUM events.

implements #3885
fixes #3942
@axw
Copy link
Member Author

axw commented Jul 14, 2020

Closed by #3943

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants