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

Forward validation errors to agents #166

Closed
beniwohli opened this issue Sep 13, 2017 · 6 comments
Closed

Forward validation errors to agents #166

beniwohli opened this issue Sep 13, 2017 · 6 comments
Labels

Comments

@beniwohli
Copy link
Contributor

The apm server helpfully spits out great validation error messages if a payload fails the JSON Schema validation:

2017/09/13 09:12:20.138559 server.go:164: INFO Data validation error: Problem validating JSON document against schema: I[#] S[#] doesn't validate with "error#"
  I[#/errors/0/log] S[#/properties/errors/items/properties/log/required] missing properties: "message", code=400

This is great, but all the agent gets back is an empty 400 Bad Request response. It would be great if the validation error message could be returned to the agent, e.g. as a JSON payload.

@watson
Copy link
Contributor

watson commented Sep 13, 2017

We had a discussion about error responses in #6 and we implemented changes in #37, so it should already reply with the validation error. But maybe something broke along the way?

@beniwohli
Copy link
Contributor Author

Weird. Just verified that I get back an empty response. Can you check with the Node agent, @watson?

@watson
Copy link
Contributor

watson commented Sep 13, 2017

@beniwohli I just tested it with curl from the latest master. Here's the results. I think the issue is that the server sends back Content-Type: text/plain; charset=utf-8 even though the body is JSON -
which obviously is wrong.

With curl default (Accept: */*):

$ curl -v -X POST -H 'Content-Type: application/json' -d '{"app":{"name":"foo","agent":{"name":"foo","version":"1"}},"errors":[{"timestamp":"2017-01-01T00:00:00+00:00","log":{"message":"foo"}}]}' localhost:8200/v1/errors
> POST /v1/errors HTTP/1.1
> Host: localhost:8200
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 136
>
< HTTP/1.1 400 Bad Request
< Date: Wed, 13 Sep 2017 11:09:06 GMT
< Content-Length: 325
< Content-Type: text/plain; charset=utf-8
<
{"error":"Data Validation error: Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"error#\"\n  I[#/errors/0/timestamp] S[#/properties/errors/items/properties/timestamp/pattern] does not match pattern \"^(\\\\d{4})-(\\\\d{2})-(\\\\d{2})T(\\\\d{2}):(\\\\d{2}):(\\\\d{2})(\\\\.\\\\d{1,6})?Z$\""}%

With curl and the header Accept: application/json:

$ curl -v -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"app":{"name":"foo","agent":{"name":"foo","version":"1"}},"errors":[{"timestamp":"2017-01-01T00:00:00+00:00","log":{"message":"foo"}}]}' localhost:8200/v1/errors
> POST /v1/errors HTTP/1.1
> Host: localhost:8200
> User-Agent: curl/7.54.0
> Content-Type: application/json
> Accept: application/json
> Content-Length: 136
>
< HTTP/1.1 400 Bad Request
< Date: Wed, 13 Sep 2017 11:09:30 GMT
< Content-Length: 325
< Content-Type: text/plain; charset=utf-8
<
{"error":"Data Validation error: Problem validating JSON document against schema: I[#] S[#] doesn't validate with \"error#\"\n  I[#/errors/0/timestamp] S[#/properties/errors/items/properties/timestamp/pattern] does not match pattern \"^(\\\\d{4})-(\\\\d{2})-(\\\\d{2})T(\\\\d{2}):(\\\\d{2}):(\\\\d{2})(\\\\.\\\\d{1,6})?Z$\""}%

@watson watson added bug and removed enhancement labels Sep 13, 2017
@watson
Copy link
Contributor

watson commented Sep 13, 2017

I changed this to a bug as it's not working as intended

@beniwohli
Copy link
Contributor Author

OK, turns out I was using urllib3 wrong :( (in my defense, there are several stackoverflow questions and urllib3 bug reports that are similarly confused)

@watson should we close this and open another issue specific to the buggy content-type?

@watson
Copy link
Contributor

watson commented Sep 13, 2017

@beniwohli good idea

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

No branches or pull requests

2 participants