()
| 1094 | } |
| 1095 | |
| 1096 | func (a *AgentClient) requestAgentStop() error { |
| 1097 | if a.conf == nil { |
| 1098 | return fmt.Errorf("agent config is nil") |
| 1099 | } |
| 1100 | if a.conf.Agent.AgentURI == "" { |
| 1101 | return fmt.Errorf("agent URI is not configured") |
| 1102 | } |
| 1103 | |
| 1104 | stopCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1105 | defer cancel() |
| 1106 | |
| 1107 | req, err := http.NewRequestWithContext(stopCtx, http.MethodPost, fmt.Sprintf("%s/stop", a.conf.Agent.AgentURI), nil) |
| 1108 | if err != nil { |
| 1109 | return err |
| 1110 | } |
| 1111 | |
| 1112 | res, err := a.client.Do(req) |
| 1113 | if err != nil { |
| 1114 | return err |
| 1115 | } |
| 1116 | defer res.Body.Close() |
| 1117 | |
| 1118 | if res.StatusCode != http.StatusOK { |
| 1119 | body, _ := io.ReadAll(res.Body) |
| 1120 | return fmt.Errorf("agent stop http %d: %s", res.StatusCode, strings.TrimSpace(string(body))) |
| 1121 | } |
| 1122 | |
| 1123 | return nil |
| 1124 | } |
| 1125 | |
| 1126 | // stopAgent stops the agent process gracefully. |
| 1127 | func (a *AgentClient) stopAgent() { |
no test coverage detected