MCPcopy
hub / github.com/cortexlabs/cortex / httpProbe

Method httpProbe

pkg/probe/probe.go:177–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175}
176
177func (p *Probe) httpProbe() error {
178 // to mimic k8s probe functionality
179 targetHost := p.HTTPGet.Host
180 if p.HTTPGet.Host == "" {
181 targetHost = "localhost"
182 }
183
184 targetURL := s.EnsurePrefix(
185 net.JoinHostPort(targetHost, p.HTTPGet.Port.String())+s.EnsurePrefix(p.HTTPGet.Path, "/"),
186 "http://",
187 )
188
189 httpClient := &http.Client{
190 Timeout: time.Duration(p.TimeoutSeconds) * time.Second,
191 }
192 req, err := http.NewRequest(http.MethodGet, targetURL, nil)
193 if err != nil {
194 return err
195 }
196
197 req.Header.Add(consts.UserAgentKey, consts.KubeProbeUserAgentPrefix)
198
199 for _, header := range p.HTTPGet.HTTPHeaders {
200 req.Header.Add(header.Name, header.Value)
201 }
202
203 res, err := httpClient.Do(req)
204 if err != nil {
205 return err
206 }
207
208 defer func() {
209 // Ensure body is both read _and_ closed so it can be reused for keep-alive.
210 // No point handling errors, connection just won't be reused.
211 _, _ = io.Copy(ioutil.Discard, res.Body)
212 _ = res.Body.Close()
213 }()
214
215 // response status code between 200-399 indicates success
216 if !(res.StatusCode >= 200 && res.StatusCode < 400) {
217 return fmt.Errorf("HTTP probe did not respond Ready, got status code: %d", res.StatusCode)
218 }
219
220 return nil
221}
222
223func (p *Probe) tcpProbe() error {
224 // to mimic k8s probe functionality

Callers 1

probeContainerMethod · 0.95

Calls 4

ErrorfMethod · 0.80
StringMethod · 0.45
AddMethod · 0.45
CopyMethod · 0.45

Tested by

no test coverage detected