Implement lab6 observability with OpenTelemetry and Grafana

This commit is contained in:
ferraronp
2026-11-17 19:14:43 +03:00
parent 470d9d6f1e
commit e636d4cc76
68 changed files with 5863 additions and 47 deletions
+35
View File
@@ -0,0 +1,35 @@
"""Idempotently create the private S3 bucket with bootstrap-only credentials."""
import os
import time
import boto3
from botocore.config import Config
from botocore.exceptions import ClientError, BotoCoreError
def main():
bucket = os.environ["S3_BUCKET"]
client = boto3.client("s3", endpoint_url=os.environ["S3_ENDPOINT"],
aws_access_key_id=os.environ["S3_ADMIN_ACCESS_KEY"],
aws_secret_access_key=os.environ["S3_ADMIN_SECRET_KEY"],
region_name="us-east-1",
config=Config(s3={"addressing_style": "path"},
connect_timeout=2, read_timeout=4, retries={"max_attempts": 1}))
for attempt in range(70):
try:
try:
client.head_bucket(Bucket=bucket)
except ClientError as exc:
code = exc.response.get("Error", {}).get("Code", "")
if code not in ("404", "NoSuchBucket", "NotFound"):
raise
client.create_bucket(Bucket=bucket)
# PRIVATE: no public bucket policy, ACL or anonymous identity.
print(f"Private bucket {bucket} ready", flush=True)
return
except (ClientError, BotoCoreError, OSError) as exc:
if attempt == 69:
raise RuntimeError("S3 bootstrap failed; inspect S3 container") from exc
time.sleep(1)
if __name__ == "__main__":
main()