Skip to content
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

Use local timezone when query logs for dedicated deployment #341

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions roboflow/adapters/deploymentapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import urllib

import requests

from roboflow.config import DEDICATED_DEPLOYMENT_URL
Expand Down Expand Up @@ -58,13 +60,14 @@ def list_machine_types(api_key):


def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None, max_entries=-1):
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}"
params = {"api_key": api_key, "deployment_name": deployment_name}
if from_timestamp is not None:
url += f"&from_timestamp={from_timestamp.isoformat()}"
params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign
if to_timestamp is not None:
url += f"&to_timestamp={to_timestamp.isoformat()}"
params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign
if max_entries > 0:
url += f"&max_entries={max_entries}"
params["max_entries"] = max_entries
url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?{urllib.parse.urlencode(params)}"
response = requests.get(url)
if response.status_code != 200:
return response.status_code, response.text
Expand Down
6 changes: 3 additions & 3 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_deployment_log(args):
print("Please provide an api key")
exit(1)

to_timestamp = datetime.now()
to_timestamp = datetime.now().astimezone() # local timezone
from_timestamp = to_timestamp - timedelta(seconds=args.duration)
last_log_timestamp = from_timestamp
log_ids = set() # to avoid duplicate logs
Expand All @@ -183,7 +183,7 @@ def get_deployment_log(args):
exit(status_code)

for log in msg[::-1]: # logs are sorted by reversed timestamp
log_timestamp = datetime.fromisoformat(log["timestamp"]).replace(tzinfo=None)
log_timestamp = datetime.fromisoformat(log["timestamp"]).astimezone() # local timezone
if (log["insert_id"] in log_ids) or (log_timestamp < last_log_timestamp):
continue
log_ids.add(log["insert_id"])
Expand All @@ -195,5 +195,5 @@ def get_deployment_log(args):

time.sleep(10)
from_timestamp = last_log_timestamp
to_timestamp = datetime.now()
to_timestamp = datetime.now().astimezone() # local timezone
max_entries = 300 # only set max_entries for the first request