forked from mtusi2026/mtusi2026lab6
Implement lab6 observability with OpenTelemetry and Grafana
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Run in Linux worker: actual decoder failures and configured resource ceilings."""
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from src.core.settings import settings
|
||||
|
||||
|
||||
def main():
|
||||
with TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
source = root / 'input'
|
||||
def process(data, max_pixels=40000000, memory=768):
|
||||
source.write_bytes(data)
|
||||
return subprocess.run([sys.executable,'-m','src.pipeline.images',str(source),str(root),
|
||||
str(max_pixels),str(memory),'5'],capture_output=True,timeout=10,
|
||||
env=dict(os.environ, PIPELINE_TEST_IMAGE_DELAY='0')).returncode
|
||||
buffer = io.BytesIO()
|
||||
Image.new('RGB',(1000,1000),'red').save(buffer,'PNG')
|
||||
data = buffer.getvalue()
|
||||
assert process(b'not an image') == 2
|
||||
assert process(data[:33]) == 2
|
||||
assert process(data, max_pixels=100) == 2
|
||||
assert process(data, memory=1) != 0
|
||||
assert process(data) == 0
|
||||
# Non-square integer-ratio rounding and independent process are exercised
|
||||
# by HTTP tests. These values prove the actual stand configuration too.
|
||||
assert settings.worker_memory_mb == 768
|
||||
assert settings.worker_concurrency == 1
|
||||
print(json.dumps(dict(result='PASS', invalid_image_rejected=True,
|
||||
truncated_image_rejected=True, decoded_pixel_limit=True,
|
||||
address_space_limit=True, subprocess_memory_mb=settings.worker_memory_mb,
|
||||
wall_timeout_seconds=settings.job_timeout_seconds,
|
||||
concurrency=settings.worker_concurrency, prefetch_per_consumer=1)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user