Skip to content

Commit

Permalink
s3-sidecar: add lifetime timer
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Feb 6, 2025
1 parent af17b26 commit b8ba6fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions s3_sidecar/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class EnvConfig:
S3_SECRET_KEY: str
S3_BUCKET: str
S3_OBJECT_KEY: str
K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS: int


ENV = from_environment_as_dataclass(EnvConfig)
Expand Down Expand Up @@ -84,13 +85,26 @@ def main() -> None:
args = parser.parse_args()
logging_tools.log_argparse_args(args)

logger_timer = IntervalTimer(5, LOGGER)
housekeeping_timer = IntervalTimer(
5,
logging.getLogger(f"{LOGGER.name}.housekeeping"),
)
lifetime_timer = IntervalTimer(
ENV.K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS,
logging.getLogger(f"{LOGGER.name}.lifetime_timer"),
)

if args.wait_indefinitely:
LOGGER.info("Waiting for file to exist...")
while not args.fpath.exists():
if logger_timer.has_interval_elapsed():
if housekeeping_timer.has_interval_elapsed():
# log
LOGGER.info("still waiting...")
# has it been too long?
if lifetime_timer.has_interval_elapsed():
raise RuntimeError(
f"lifetime timer has expired: {lifetime_timer} seconds"
)
time.sleep(1)

post(args.fpath)
Expand Down
1 change: 1 addition & 0 deletions skydriver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EnvConfig:
K8S_SCANNER_SIDECAR_S3_CPU_LIMIT: float = 0.10
K8S_SCANNER_SIDECAR_S3_MEM_REQUEST: str = K8S_MIN_MEM_REQUEST
K8S_SCANNER_SIDECAR_S3_CPU_REQUEST: float = 0.05
K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS: int = 15 * 60 # 15 mins

# EWMS optional config
EWMS_WORKER_MEMORY__DEFAULT: str = "8GB"
Expand Down
2 changes: 2 additions & 0 deletions skydriver/k8s/scanner_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def _make_job(
value: "{ENV.S3_BUCKET}"
- name: S3_OBJECT_KEY
value: "{s3.make_object_key(scan_id)}"
- name: K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS
value: {ENV.K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS}
resources:
limits:
memory: "{ENV.K8S_SCANNER_SIDECAR_S3_MEM_LIMIT}"
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_rest_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ async def _assert_db_skyscank8sjobs_coll( # noqa: MFL000
"name": "S3_OBJECT_KEY",
"value": f"{post_resp['scan_id']}-s3-object",
},
{
"name": "K8S_SCANNER_SIDECAR_S3_LIFETIME_SECONDS",
"value": 15 * 60,
},
],
"image": os.environ["THIS_IMAGE_WITH_TAG"],
"name": f"sidecar-s3-{post_resp['scan_id']}",
Expand Down

0 comments on commit b8ba6fa

Please sign in to comment.