Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep monitor list elements unique #150

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions utils/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,7 @@ func HealthCheck(files []string, podServices map[string]bool, out chan<- string)
logger.Debugf("list of containers are launched : %v", containers)
time.Sleep(interval)
}
MonitorContainerList = make([]types.SvcContainer, len(containers))
copy(MonitorContainerList, containers)
MonitorContainerList = CopySvcContainers(MonitorContainerList, containers)
for _, c := range MonitorContainerList {
logger.Infof("service : %s, containerid: %s, pid: %s", c.ServiceName, c.ContainerId, c.Pid)
}
Expand Down Expand Up @@ -1294,7 +1293,7 @@ healthCheck:
}

UpdateHealthCheckStatus(StepMetrics)
copy(MonitorContainerList, containers)
MonitorContainerList = CopySvcContainers(MonitorContainerList, containers)

logger.Printf("Health Check List: %v", HealthCheckListId)
logger.Printf("Pod Monitor List: %v", MonitorContainerList)
Expand Down
8 changes: 8 additions & 0 deletions utils/pod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ func UpdateHealthCheckStatus(stepData map[string][]*types.StepData) {
}
}
}

func CopySvcContainers(to []types.SvcContainer, from []types.SvcContainer) []types.SvcContainer {
to = make([]types.SvcContainer, len(from))
for i, c := range from {
to[i] = c
}
return to
}
72 changes: 72 additions & 0 deletions utils/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pod

import (
"errors"
"fmt"
"testing"

"github.com/paypal/dce-go/types"
Expand Down Expand Up @@ -65,3 +66,74 @@ func TestSetStepData(t *testing.T) {
}
}
}

func TestAddSvcContainers(t *testing.T) {
t.Run("base container list is empty", func(t *testing.T) {
var to []types.SvcContainer
to = []types.SvcContainer{
{
ServiceName: "test1",
},
{
ServiceName: "test2",
},
}
res := CopySvcContainers(to, []types.SvcContainer{})
assert.Equal(t, 0, len(res))
fmt.Println(res)
})
t.Run("from container list is empty", func(t *testing.T) {
var to []types.SvcContainer
to = make([]types.SvcContainer, 3)
res := CopySvcContainers(to, []types.SvcContainer{{ServiceName: "test1"}})
assert.Equal(t, 1, len(res))
fmt.Println(res)
})
t.Run("copy duplicates to base container list", func(t *testing.T) {
var to []types.SvcContainer
to = []types.SvcContainer{
{
ServiceName: "test1",
},
{
ServiceName: "test2",
},
}
res := CopySvcContainers(to, []types.SvcContainer{{ServiceName: "test2"}})
assert.Equal(t, 1, len(res))
assert.Equal(t, "test2", res[0].ServiceName)
fmt.Println(res)
})
t.Run("copy non-duplicates to base container list", func(t *testing.T) {
var to []types.SvcContainer
to = []types.SvcContainer{
{
ServiceName: "test1",
},
{
ServiceName: "test2",
},
}
res := CopySvcContainers(to, []types.SvcContainer{{ServiceName: "test3"}})
assert.Equal(t, 1, len(res))
assert.Equal(t, "test3", res[0].ServiceName)
fmt.Println(res)
})
t.Run("copy duplicates & non-duplicates to base container list", func(t *testing.T) {
var to []types.SvcContainer
to = []types.SvcContainer{
{
ServiceName: "test1",
},
{
ServiceName: "test2",
},
}
res := CopySvcContainers(to, []types.SvcContainer{{ServiceName: "test2"}, {ServiceName: "test3"}, {ServiceName: "test4"}})
assert.Equal(t, 3, len(res))
assert.Equal(t, "test2", res[0].ServiceName)
assert.Equal(t, "test3", res[1].ServiceName)
assert.Equal(t, "test4", res[2].ServiceName)
fmt.Println(res)
})
}
Loading