From 4d341e44bd768033e3aafe4ee9a3055e55f61ef4 Mon Sep 17 00:00:00 2001 From: inspurericzhang Date: Tue, 1 Aug 2023 08:13:31 +0000 Subject: [PATCH] fix detect anomal task bug Change-Id: Ib6a081276bb3665cd1743d375980c5a9111bc9f2 --- venus/modules/anomaly_detect/backends/sql.py | 16 ++++++++-------- venus/task/core/anomaly_detect_task.py | 6 +++--- venus/task/core/delete_anomaly_record_task.py | 4 +++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/venus/modules/anomaly_detect/backends/sql.py b/venus/modules/anomaly_detect/backends/sql.py index 789e0cb..9de953f 100644 --- a/venus/modules/anomaly_detect/backends/sql.py +++ b/venus/modules/anomaly_detect/backends/sql.py @@ -125,13 +125,13 @@ class AnomalyDetectSql(object): session.add(rule) def get_record_list(self, params): - title = params["title"] - module = params["module"] - ltype = params["log_type"] - start_time = params["start_time"] - end_time = params["end_time"] - page_num = int(params["page_num"]) - page_size = int(params["page_size"]) + title = params.get("title", None) + module = params.get("module", None) + ltype = params.get("log_type", None) + start_time = params.get("start_time", None) + end_time = params.get("end_time", None) + page_num = int(params.get("page_num", "1")) + page_size = int(params.get("page_size", "10")) session = get_session() with session.begin(): @@ -152,7 +152,7 @@ class AnomalyDetectSql(object): t = time.strftime('%Y-%m-%d %H:%M:%S', lt) query = query.filter(models.AnomalyRecords.create_time <= t) - query = query.limit(page_size).offset((page_num - 1) * page_num) + query = query.limit(page_size).offset((page_num - 1) * page_size) res = query.all() return res diff --git a/venus/task/core/anomaly_detect_task.py b/venus/task/core/anomaly_detect_task.py index 9b6b905..b00ee1c 100644 --- a/venus/task/core/anomaly_detect_task.py +++ b/venus/task/core/anomaly_detect_task.py @@ -37,10 +37,10 @@ class AnomalyDetectTask(object): last_timestamp = self.config_api.get_config("last_detect_timestamp") if last_timestamp: last_timestamp = int(last_timestamp) - if now_timestamp - last_timestamp > 3000000: - last_timestamp = last_timestamp - 3000000 + if now_timestamp - last_timestamp > 300: + last_timestamp = last_timestamp - 300 else: - last_timestamp = now_timestamp - 6000000 + last_timestamp = now_timestamp - 60 self.anomaly_detect_logs("flog", last_timestamp, now_timestamp) self.anomaly_detect_logs("slog", last_timestamp, now_timestamp) diff --git a/venus/task/core/delete_anomaly_record_task.py b/venus/task/core/delete_anomaly_record_task.py index 3ef2ee4..4d256b1 100644 --- a/venus/task/core/delete_anomaly_record_task.py +++ b/venus/task/core/delete_anomaly_record_task.py @@ -39,7 +39,9 @@ class DeleteAnomalyRecordTask(object): LOG.info(_LI("anomaly record save days: %s"), len_d) try: params = {} - params["start_time"] = str(time.time() - 86400 * int(len_d)) + params["page_num"] = "1" + params["page_size"] = "999999" + params["end_time"] = str(int(time.time()) - 86400 * int(len_d)) records = self.anomaly_api.get_record_list(params) for r in records: self.anomaly_api.delete_record(r.id)