(
&self,
payload: &CostRecommendationRequest,
kubeconfig_path: &std::path::Path,
envs: &[(&str, &str)],
)
| 132 | } |
| 133 | |
| 134 | fn run_krr( |
| 135 | &self, |
| 136 | payload: &CostRecommendationRequest, |
| 137 | kubeconfig_path: &std::path::Path, |
| 138 | envs: &[(&str, &str)], |
| 139 | ) -> Result<String, Box<EngineError>> { |
| 140 | let requested_prometheus_url = match &payload.prometheus_url { |
| 141 | Some(url) => url.clone(), |
| 142 | None => self.default_qovery_obs_thanos_query_url()?, |
| 143 | }; |
| 144 | let port_forward_guard = KubernetesServicePortForwardTarget::from_service_url(&requested_prometheus_url) |
| 145 | .map(|target| KubectlPortForward::start(kubeconfig_path, target, envs)) |
| 146 | .transpose() |
| 147 | .map_err(|error| { |
| 148 | Box::new(EngineError::new_unknown( |
| 149 | self.get_event_details(ClusterAnalysisStep::CostRecommendation), |
| 150 | "Cannot open Prometheus port-forward for KRR analysis".to_string(), |
| 151 | Some(error), |
| 152 | None, |
| 153 | None, |
| 154 | )) |
| 155 | })?; |
| 156 | let prometheus_url = match &port_forward_guard { |
| 157 | Some(port_forward) => port_forward.local_url().map_err(|error| { |
| 158 | Box::new(EngineError::new_unknown( |
| 159 | self.get_event_details(ClusterAnalysisStep::CostRecommendation), |
| 160 | "Cannot build Prometheus port-forward URL for KRR analysis".to_string(), |
| 161 | Some(error), |
| 162 | None, |
| 163 | None, |
| 164 | )) |
| 165 | })?, |
| 166 | None => requested_prometheus_url, |
| 167 | }; |
| 168 | let output_file = self.report_file_path(payload.output_format.as_krr_formatter())?; |
| 169 | let options = KrrOptions { |
| 170 | output_format: krr_output_format(payload.output_format), |
| 171 | prometheus_url, |
| 172 | extra_args: payload.cmd_args.clone(), |
| 173 | file_output: Some(output_file), |
| 174 | }; |
| 175 | |
| 176 | Krr::new() |
| 177 | .get_recommendations(kubeconfig_path, &options, envs, self.cancel_checker().as_ref()) |
| 178 | .map_err(|error| { |
| 179 | Box::new(EngineError::new_unknown( |
| 180 | self.get_event_details(ClusterAnalysisStep::CostRecommendation), |
| 181 | "KRR cost recommendation analysis failed".to_string(), |
| 182 | Some(CommandError::new(error.to_string(), Some(format!("{error:?}")), None)), |
| 183 | None, |
| 184 | None, |
| 185 | )) |
| 186 | }) |
| 187 | } |
| 188 | |
| 189 | fn run_deprecated_api_check( |
| 190 | &self, |
no test coverage detected