Skip to content

Metrics server not responding with HTTP 1.1 #927

Open

Description

@cirvladimir

I'm using the default way of starting the server with start_http_server(). I noticed that the server responds with HTTP/1.0 to HTTP/1.1 requests. Is there a flag I need to set to support HTTP/1.1?

Activity

  1. jvperrin commented on Sep 28, 2023

    @jvperrin

    In case anyone else comes across this and wants to change the version, it's coming from wsgiref.handlers in the python stdlib: https://github.com/python/cpython/blob/3.11/Lib/wsgiref/handlers.py#L104

    You can change to using 1.1 by doing this:

    from wsgiref.simple_server import ServerHandler
    
    ServerHandler.http_version = "1.1"
    

    Then later on when you call start_http_server(8000) (or similar) it will use this HTTP version and respond with HTTP/1.1 200 OK in responses.

  2. llamafilm commented on Apr 4, 2025

    @llamafilm

    @jvperrin great find, thank you! This one change makes a huge difference in performance. With my simple test exporter that just exposes 1 metric, scraping from Grafana Alloy, the CPU utilization and network traffic of the Alloy container are both reduced by about 55%. If the exporter returns a large number of metrics then the difference would be less noticeable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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