Skip to content

Commit

Permalink
moving to httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
sekharpanja committed Aug 25, 2023
1 parent 4bcc142 commit 5d315f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion prometheus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN \
chown -R prometheus:prometheus /prometheus && \
apk del .build-deps && \
pip3 install \
lowhaio==0.0.78
httpx==0.24.1

COPY prometheus.yml /etc/prometheus/
COPY fetch_targets.py /
Expand Down
23 changes: 11 additions & 12 deletions prometheus/fetch_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
import json
import logging
import os
import requests
import sys
import urllib.parse

from lowhaio import Pool, buffered
import httpx


async def async_main(logger, target_file, url, username, password):
request, _ = Pool()

while True:
await asyncio.sleep(10)
try:
logger.debug("Fetching from %s", url)
headers = (
(
b"Authorization",
b"Basic " + base64.b64encode(f"{username}:{password}".encode("ascii")),
),
)
code, _, body = await request(b"GET", url, headers=headers)
logger.debug("Code %s", code)
raw_json = await buffered(body)
headers = {
b"Authorization": b"Basic "
+ base64.b64encode(f"{username}:{password}".encode("ascii"))
}
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers)
response.raise_for_status()
logger.debug("Code %s", response.status_code)
raw_json = response.json()
logger.debug("Received %s", raw_json)
applications = json.loads(raw_json)["applications"]
logger.debug("Found %s", applications)
Expand Down

0 comments on commit 5d315f5

Please sign in to comment.