Skip to content

Commit

Permalink
PrometheusProxy: Add support for authorization
Browse files Browse the repository at this point in the history
Now that our Shard model supports an "authorization" field to specify the value
of the HTTP "Authorization" header, we can use it in our PrometheusProxy class.

Note that we have replace "host" with "shard" since the objects obtained by the
'models.Shard.objects.filter(proxy=True)' instruction are shards, not hosts.
  • Loading branch information
vincent-olivert-riera committed Jul 1, 2024
1 parent f43fde0 commit 6a21b8e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions promgen/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PrometheusProxy(View):
proxy_headers = {"HTTP_REFERER": "Referer"}

@property
def headers(self):
def request_headers(self):
# Loop through the headers from our request, and decide which ones
# we should pass through upstream. Currently, our 'Referer' header is
# the main one we are interested in, since this can help us debug which
Expand All @@ -53,12 +53,15 @@ def headers(self):
def proxy(self, request):
futures = []
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
for host in models.Shard.objects.filter(proxy=True):
for shard in models.Shard.objects.filter(proxy=True):
headers = self.request_headers
if shard.authorization:
headers["Authorization"] = shard.authorization
futures.append(
executor.submit(
util.get,
urljoin(host.url, request.get_full_path_info()),
headers=self.headers,
urljoin(shard.url, request.get_full_path_info()),
headers=headers,
)
)
yield from concurrent.futures.as_completed(futures)
Expand Down

0 comments on commit 6a21b8e

Please sign in to comment.