| | |
| | | } |
| | | |
| | | AutoTuneAgentService.AutoTuneAgentResult agentResult = null; |
| | | markLastTriggerGuard(intervalMinutes); |
| | | try { |
| | | agentResult = autoTuneAgentService.runAutoTune(AutoTuneTriggerType.AUTO.getCode()); |
| | | writeOperateLog(agentResult); |
| | | markNoChangeGuardIfNeeded(latestSuccessfulJob, agentResult, intervalMinutes); |
| | | safeWriteOperateLog(agentResult); |
| | | return AutoTuneCoordinatorResult.triggered(agentResult); |
| | | } catch (Exception exception) { |
| | | log.error("Auto tune coordinator failed to run agent", exception); |
| | | agentResult = failedAgentResult(exception); |
| | | writeOperateLog(agentResult); |
| | | safeWriteOperateLog(agentResult); |
| | | return AutoTuneCoordinatorResult.triggered(agentResult); |
| | | } finally { |
| | | redisUtil.compareAndDelete(lockKey, lockToken); |
| | |
| | | return System.currentTimeMillis() - latestFinishTime.getTime() >= intervalMillis; |
| | | } |
| | | |
| | | private void markNoChangeGuardIfNeeded(AiAutoTuneJob beforeJob, |
| | | AutoTuneAgentService.AutoTuneAgentResult agentResult, |
| | | int intervalMinutes) { |
| | | if (agentResult == null || !Boolean.TRUE.equals(agentResult.getSuccess())) { |
| | | return; |
| | | } |
| | | AiAutoTuneJob afterJob = latestSuccessfulAutoJob(); |
| | | if (!isSameJob(beforeJob, afterJob)) { |
| | | return; |
| | | } |
| | | private void markLastTriggerGuard(int intervalMinutes) { |
| | | long expireSeconds = intervalMinutes * 60L; |
| | | redisUtil.set(RedisKeyType.AI_AUTO_TUNE_LAST_TRIGGER_GUARD.key, |
| | | String.valueOf(System.currentTimeMillis()), expireSeconds); |
| | | } |
| | | |
| | | private boolean isSameJob(AiAutoTuneJob beforeJob, AiAutoTuneJob afterJob) { |
| | | if (beforeJob == null || afterJob == null) { |
| | | return beforeJob == afterJob; |
| | | } |
| | | return beforeJob.getId() != null && beforeJob.getId().equals(afterJob.getId()); |
| | | } |
| | | |
| | | private AutoTuneAgentService.AutoTuneAgentResult failedAgentResult(Exception exception) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | private void safeWriteOperateLog(AutoTuneAgentService.AutoTuneAgentResult agentResult) { |
| | | try { |
| | | writeOperateLog(agentResult); |
| | | } catch (Exception exception) { |
| | | log.warn("Auto tune coordinator failed to write operate log", exception); |
| | | } |
| | | } |
| | | |
| | | private void writeOperateLog(AutoTuneAgentService.AutoTuneAgentResult agentResult) { |
| | | if (agentResult == null) { |
| | | return; |