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
Content-Type negotiation #29
Comments
Looks like it's too http dependent and should be handler by exporters |
Looks like there is no standard way to parse accept header yet (will be in next cowlib, what about elli?). I'll write poor's man parser then. |
This is how I did it. It's not the most performant, but it may give you some ideas. def index(conn, _params) do
accept_headers = get_req_header(conn, "accept")
format = case Enum.any?(accept_headers, &protobuf?/1) do
true ->
Prometheus.Format.Protobuf
_ ->
Prometheus.Format.Text
end
conn
|> put_resp_header("Content-Type", format.content_type)
|> send_resp(200, format.format)
end
defp protobuf?(header) do
String.contains?(header, "protobuf")
end
end |
While this definitely works it's not entirely correct since nothing mandates only two formats. For example, I'm playing with text/html renderer - really helpful for debugging. But! At least I know now that someone else cares about content type negotiation too, so thank you a lot! |
I just use the text for debugging as I'm lazy and just CTRL+F my way through finding the counter I'm looking for. If you have something that does HTML, then I can see how you would want a real accept header parser. I'm also very curious what kind of UI you have for the html display. I'm not sure if I would see the value in shipping it inside the current libraries, but it would be interesting. |
prometheus-plugs now supports content type negotiation using https://github.com/deadtrickster/accept |
This is how Accept header looks currently:
application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,application/json;schema=\"prometheus/telemetry\";version=0.0.2;q=0.2,*/*;q=0.1
.prometheus.erl only supported delimited protobuf and text version 0.0.4
The text was updated successfully, but these errors were encountered: