forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#609 from deads2k/show-probe
UPSTREAM: <carry>: provide events, messages, and bodies for probe failures of important pods
- Loading branch information
Showing
4 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package prober | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"time" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/klog/v2" | ||
"k8s.io/kubernetes/pkg/probe" | ||
httpprobe "k8s.io/kubernetes/pkg/probe/http" | ||
) | ||
|
||
func (pb *prober) maybeProbeForBody(prober httpprobe.Prober, url *url.URL, headers http.Header, timeout time.Duration, pod *v1.Pod, container v1.Container, probeType probeType) (probe.Result, string, error) { | ||
if !isInterestingPod(pod) { | ||
return prober.Probe(url, headers, timeout) | ||
} | ||
bodyProber, ok := prober.(httpprobe.DetailedProber) | ||
if !ok { | ||
return prober.Probe(url, headers, timeout) | ||
} | ||
result, output, body, probeError := bodyProber.ProbeForBody(url, headers, timeout) | ||
switch result { | ||
case probe.Success: | ||
return result, output, probeError | ||
case probe.Warning, probe.Failure, probe.Unknown: | ||
// these pods are interesting enough to show the body content | ||
klog.Infof("interesting pod/%s container/%s namespace/%s: %s probe status=%v output=%q start-of-body=%s", | ||
pod.Name, container.Name, pod.Namespace, probeType, result, output, body) | ||
|
||
// in fact, they are so interesting we'll try to send events for them | ||
pb.recordContainerEvent(pod, &container, v1.EventTypeWarning, "ProbeError", "%s probe error: %s\nbody: %s\n", probeType, output, body) | ||
return result, output, probeError | ||
default: | ||
return result, output, probeError | ||
} | ||
} | ||
|
||
func isInterestingPod(pod *v1.Pod) bool { | ||
if pod == nil { | ||
return false | ||
} | ||
if strings.HasPrefix(pod.Namespace, "openshift-") { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
||
"k8s.io/kubernetes/pkg/probe" | ||
) | ||
|
||
// Prober is an interface that defines the Probe function for doing HTTP readiness/liveness checks. | ||
type DetailedProber interface { | ||
ProbeForBody(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, string, error) | ||
} | ||
|
||
// ProbeForBody returns a ProbeRunner capable of running an HTTP check. | ||
// returns result, details, body, error | ||
func (pr httpProber) ProbeForBody(url *url.URL, headers http.Header, timeout time.Duration) (probe.Result, string, string, error) { | ||
pr.transport.DisableCompression = true // removes Accept-Encoding header | ||
client := &http.Client{ | ||
Timeout: timeout, | ||
Transport: pr.transport, | ||
CheckRedirect: redirectChecker(pr.followNonLocalRedirects), | ||
} | ||
return DoHTTPProbe(url, headers, client) | ||
} |