Skip to content

Commit

Permalink
sysdump: skip metric/gops collection if container does not exist
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
giorio94 authored and michi-covalent committed May 15, 2024
1 parent 41f2439 commit 9f8496f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,11 @@ func (c *Collector) getGopsPID(ctx context.Context, pod *corev1.Pod, containerNa
func (c *Collector) SubmitGopsSubtasks(pods []*corev1.Pod, containerName string) error {
for _, p := range pods {
p := p

if !podIsRunningAndHasContainer(p, containerName) {
continue
}

for _, g := range gopsStats {
g := g
if err := c.Pool.Submit(fmt.Sprintf("gops-%s-%s", p.Name, g), func(ctx context.Context) error {
Expand Down Expand Up @@ -2657,7 +2662,7 @@ func (c *Collector) submitKVStoreTasks(ctx context.Context, pod *corev1.Pod) err
func (c *Collector) submitMetricsSubtask(pods *corev1.PodList, containerName, portName string) error {
for _, p := range pods.Items {
p := p
if p.Status.Phase != corev1.PodRunning {
if !podIsRunningAndHasContainer(&p, containerName) {
continue
}
err := c.Pool.Submit(fmt.Sprintf("metrics-%s-%s-%s", p.Name, containerName, portName), func(ctx context.Context) error {
Expand Down

0 comments on commit 9f8496f

Please sign in to comment.