Metrics: Not clear about media types (Accept header)

31 views
Skip to first unread message

Tomas Langer

unread,
Oct 17, 2018, 6:08:44 AM10/17/18
to Eclipse MicroProfile
Hi,
 according to spec it seems that if request matches JSON, I should reply with JSON.
So for example this Accept header:
text/plain;version=0.0.4;q=1,*/*;q=0.1
should return JSON format, as */* is supported.

There are no TCK tests related to this (e.g. a combination of accepted types) and the text in spec is not absolutely clear (e.g. what does "matches" mean? is it an exact match? or did I understand it correctly?)

Spec definition:

Data is exposed via REST over HTTP under the /metrics base path in two different data formats for GET requests:

• JSON format - used when the HTTP Accept header matches application/json.
• Prometheus text format - default response format when the HTTP Accept header does not match

any more specific media type like application/json



If we should honor the Accept header as it is designed, I should return Prometheus format any time text/plain has higher q than application/json (and vice versa).


Could somebody from the Metrics spec provide a clear answer to:

Should I honor the order and "q" in Accept header and return JSON only if application/json is preferred over text/plain, or should I return JSON if application/json is supported by the Accept header (supported means that at least one segment of Accept header matches application/json)?




Thanks,

Tomas

Joe Di Pol

unread,
Oct 17, 2018, 12:17:04 PM10/17/18
to Eclipse MicroProfile


I sure hope the answer is "honor the order and "q" in Accept header and return JSON only if application/json is preferred over text/plain"

Because text/plain;version=0.0.4;q=1,*/*;q=0.1 is an Accept header sent by Prometheus and you don't want to send it JSON.

Plus sending JSON in this case seems to violate the intent of the Accept header.


donbo...@gmail.com

unread,
Oct 17, 2018, 4:57:37 PM10/17/18
to Eclipse MicroProfile
Tomas / Joe,

I'm part of the metrics community and I agree that what's specified in section 2.3, related to the Accept header isn't as specific as it ought to be.  The way it's worded in the spec right now isn't right, as illustrated by Joe's example.  

The way we'd intended for it to be interpreted was that if the incoming request accepts text/plain with a higher priority than application/json, then you should use Prometheus format.  If the incoming request accepts application/json with a higher priority than text/plain, then use JSON format.  If the incoming request doesn't accept either of those, then return a 406 status code.

I'll get an issue opened so we can fix the spec.  Thanks for pointing this out!

Regards,
Don

donbo...@gmail.com

unread,
Oct 17, 2018, 5:02:42 PM10/17/18
to Eclipse MicroProfile
Reply all
Reply to author
Forward
0 new messages