-
Notifications
You must be signed in to change notification settings - Fork 29
Repeat curls at equal intervals #2641
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
Open
JoukoVirtanen
wants to merge
5
commits into
master
Choose a base branch
from
jv-repeat-curls-at-equal-intervals
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10ba7e2
X-Smart-Branch-Parent: master
JoukoVirtanen c3c834a
Switched to using schedule-curls.py which has better control over the…
JoukoVirtanen df65384
Added sleep to the end of the script so schedule-curls.py can be run …
JoukoVirtanen 9eb57c1
Not getting the actual output from the server
JoukoVirtanen dcb8376
A minor refactor
JoukoVirtanen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.0.3 | ||
| 2.0.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| FROM alpine:3.8 | ||
|
|
||
| RUN apk add --update curl && \ | ||
| apk add python3 && \ | ||
| rm -rf /var/cache/apk/* | ||
|
|
||
| COPY schedule-curls.sh /usr/bin/schedule-curls.sh | ||
| COPY schedule-curls.py /usr/bin/schedule-curls.py |
63 changes: 63 additions & 0 deletions
63
integration-tests/container/schedule-curls/schedule-curls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import sys | ||
| import time | ||
| import subprocess | ||
|
|
||
| if len(sys.argv) != 6: | ||
| print("Usage: python fixed_interval_curl.py NUM_META_ITER NUM_ITER FIXED_INTERVAL_SEC SLEEP_BETWEEN_META_ITER URL", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| try: | ||
| num_meta_iter = int(sys.argv[1]) | ||
| num_iter = int(sys.argv[2]) | ||
| fixed_interval = float(sys.argv[3]) | ||
| sleep_between_iterations = float(sys.argv[4]) | ||
| url = sys.argv[5] | ||
| except ValueError as e: | ||
| print(f"Error parsing numerical arguments: {e}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def format_timestamp(timestamp: float) -> str: | ||
| time_str = time.strftime("%H:%M:%S", time.localtime(timestamp)) | ||
| milliseconds = f"{timestamp % 1:.3f}"[2:] | ||
| return f"{time_str}.{milliseconds}" | ||
|
|
||
|
|
||
| def run_curl(target_url: str): | ||
| start_time = time.time() | ||
| try: | ||
| subprocess.run(['curl', '-I', '-s', target_url], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"Curl failed with exit code {e.returncode}: {e}", file=sys.stderr) | ||
| sys.exit(e.returncode) | ||
| end_time = time.time() | ||
| duration = end_time - start_time | ||
|
|
||
| print(f"Curl timing: start=[{format_timestamp(start_time)}], end=[{format_timestamp(end_time)}], duration={duration:.3f}s", flush=True) | ||
|
|
||
|
|
||
| i = 0 | ||
| while i < num_meta_iter: | ||
| j = 0 | ||
| start_time = time.time() | ||
| while j < num_iter: | ||
| next_execution_time = start_time + (j * fixed_interval) | ||
| current_time = time.time() | ||
| sleep_duration = next_execution_time - current_time | ||
| if sleep_duration > 0: | ||
| time.sleep(sleep_duration) | ||
| else: | ||
| pass | ||
| execution_time = time.time() | ||
| time_str = time.strftime("%H:%M:%S", time.localtime(execution_time)) | ||
| milliseconds = f"{execution_time % 1:.3f}"[2:] | ||
| print(f"[{time_str}.{milliseconds}] Executing curl (Meta: {i + 1}/{num_meta_iter}, Iter: {j + 1}/{num_iter})") | ||
| run_curl(url) | ||
| j += 1 | ||
| if sleep_between_iterations > 0: | ||
| time.sleep(sleep_between_iterations) | ||
| i += 1 | ||
| print("Script finished successfully.") | ||
| print("Sleeping for an additional 300s") | ||
| time.sleep(300) |
22 changes: 0 additions & 22 deletions
22
integration-tests/container/schedule-curls/schedule-curls.sh
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the container was started with a sleep command. That meant that no logs were obtained. Now that the container is started with the python script, we get logs for the python script.