Skip to content

Commit 9e2e1f5

Browse files
committed
sysdump: skip metric/gops collection if container does not exist
Do not attempt to collect metrics and gops stats if the target pod is not running, or the specified container does not exist. This prevents performing operations that are guaranteed to fail, and output possibly misleading errors. One example being when the clustermesh-apiserver is enabled, but kvstoremesh is not, as all operations targeting the latter will fail. Signed-off-by: Marco Iorio <[email protected]>
1 parent 9833205 commit 9e2e1f5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sysdump/sysdump.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,11 @@ func (c *Collector) SubmitGopsSubtasks(pods []*corev1.Pod, containerName string)
24132413
p := p
24142414
for _, g := range gopsStats {
24152415
g := g
2416+
2417+
if !podIsRunningAndHasContainer(p, containerName) {
2418+
continue
2419+
}
2420+
24162421
if err := c.Pool.Submit(fmt.Sprintf("gops-%s-%s", p.Name, g), func(ctx context.Context) error {
24172422
agentPID, err := c.getGopsPID(ctx, p, containerName)
24182423
if err != nil {
@@ -2657,7 +2662,7 @@ func (c *Collector) submitKVStoreTasks(ctx context.Context, pod *corev1.Pod) err
26572662
func (c *Collector) submitMetricsSubtask(pods *corev1.PodList, containerName, portName string) error {
26582663
for _, p := range pods.Items {
26592664
p := p
2660-
if p.Status.Phase != corev1.PodRunning {
2665+
if !podIsRunningAndHasContainer(&p, containerName) {
26612666
continue
26622667
}
26632668
err := c.Pool.Submit(fmt.Sprintf("metrics-%s-%s-%s", p.Name, containerName, portName), func(ctx context.Context) error {

0 commit comments

Comments
 (0)