from o11ydiagnosis.subtasks.logreporter.task import Task from o11ydiagnosis.subtasks.slowlogconverter.objstore import S3, GCS, AzureBlob class Config: task: Task cluster: str interval_secs: int def __init__(self, task, task_info): self.engine_task = task self.local_path = task.cache_prefix provider: str = task_info["meta"]["provider"].lower() # aws/gcp region: str = task_info["meta"]["region"] # TODO: use env var ? cluster: str = task_info["meta"]["clusterID"] # interval_secs: int = subtask_info["interval"] if provider == "aws": s3 = S3() elif provider == "gcp": s3 = GCS() elif provider == "azure": s3 = AzureBlob() else: raise ValueError("invalid provider: " + provider) drhouse_bucket = drhouse_s3_bucket(region) drhouse_prefix = drhouse_s3_prefix(cluster) drhouse_local_path = self.local_path.rstrip("/") self.task = Task(s3, cluster, drhouse_bucket, drhouse_prefix, drhouse_local_path) self.cluster = cluster # self.interval_secs = interval_secs self.interval_secs = 30 # temp hardcode def is_timing(self, ts: int) -> bool: # utc_time = datetime.utcfromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") # log.info(f"[{self.cluster}] calling is_timing(ts={ts}) (utc time: {utc_time})") return ts % (24 * 3600) == 3600 # UTC: 01:00 def ready(self, ts: int) -> bool: return True def start(self, ts: int): # utc_time = datetime.utcfromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") # log.info(f"[{self.cluster}] calling start(ts={ts}) (utc time: {utc_time})") ts -= ts % (24 * 3600) ts -= 24 * 3600 self.task.prepare(7, ts) self.task.run(7, ts) def close(self, ts: int): # utc_time = datetime.utcfromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") # log.info(f"[{self.cluster}] calling close(ts={ts}) (utc time: {utc_time})") self.task.upload_modified_objects() def drhouse_s3_bucket(region: str) -> str: return f"o11y-prod-shared-{region}" def drhouse_s3_prefix(cluster: str) -> str: return f"diagnosis/data/{cluster}"