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

fix: deletion logic in push topology #1444

Merged
merged 2 commits into from
Sep 24, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/flanksource/commons v1.29.10
github.com/flanksource/duty v1.0.673
github.com/flanksource/duty v1.0.675
github.com/flanksource/gomplate/v3 v3.24.32
github.com/flanksource/kopper v1.0.10
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.29.10 h1:T/S95Pl8kASEFvQjQ7fJjTUqeVdhxQXg1vfkULTYFJQ=
github.com/flanksource/commons v1.29.10/go.mod h1:iTbrXOSp3Spv570Nly97D/U9cQjLZoVlmWCXqWzsvRU=
github.com/flanksource/duty v1.0.673 h1:sbqnSbM3lFMfpZlHtgCUhK6X74U59VXmhLEu1HYZphk=
github.com/flanksource/duty v1.0.673/go.mod h1:/dIt7bXnQlVtVikTu1TY1syEcuGCSUBnKyKlxVR5sDw=
github.com/flanksource/duty v1.0.675 h1:HwlZk4NTbQiDMFQaHvkLi1FzZNxyTCB0Sa0eck0eLJY=
github.com/flanksource/duty v1.0.675/go.mod h1:/dIt7bXnQlVtVikTu1TY1syEcuGCSUBnKyKlxVR5sDw=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.32 h1:MILauVcjIqBit4nXB5UCN/LZ2z+fiMb8n1Klwjci1Tg=
github.com/flanksource/gomplate/v3 v3.24.32/go.mod h1:FdQHxnyrBSmT5zNJTDq08oXxD+eOqti4ERanSoDmQAU=
Expand Down
1 change: 1 addition & 0 deletions jobs/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var ReconcileAll = &job.Job{
ctx.History.SuccessCount, ctx.History.ErrorCount = summary.GetSuccessFailure()
if summary.Error() != nil {
ctx.History.AddDetails("errors", summary.Error())
ctx.History.ErrorCount += 1
}

return nil
Expand Down
5 changes: 5 additions & 0 deletions push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ var _ = ginkgo.Describe("Push", ginkgo.Ordered, func() {
tree, err := query.Topology(DefaultContext, query.TopologyOptions{ID: componentLaptop.ID.String(), Depth: 10, NoCache: true})
Expect(err).To(BeNil())

// Mess up ids to ensure pushed IDs do not matter and deletion works correctly
tree.Components[0].ID = uuid.New()
tree.Components[0].Components[0].ID = uuid.New()
tree.Components[0].Components[1].ID = uuid.New()

httpClient := http.NewClient()
endpoint := fmt.Sprintf("http://localhost:%d/push/topology", echoServerPort)
resp, err := httpClient.R(DefaultContext).
Expand Down
7 changes: 3 additions & 4 deletions push/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ func PushTopology(c echo.Context) error {
}

data.AgentID = agentID
compIDs := []uuid.UUID{data.ID}
for _, c := range data.Components.Walk() {
c.AgentID = agentID
c.TopologyID = &topologyObj.ID
compIDs = append(compIDs, c.ID)
}

if err := dutytopology.SaveComponent(ctx, &data); err != nil {
returnedIDs, err := dutytopology.SaveComponent(ctx, &data)
if err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error saving components: %v", dutydb.ErrorDetails(err)))
}

var idsToDelete []string
if err := ctx.DB().Model(&models.Component{}).Select("id").Where("topology_id = ?", data.TopologyID).Where("id NOT IN ?", compIDs).Find(&idsToDelete).Error; err != nil {
if err := ctx.DB().Model(&models.Component{}).Select("id").Where("topology_id = ?", data.TopologyID).Where("id NOT IN ?", returnedIDs).Find(&idsToDelete).Error; err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error querying old components: %v", dutydb.ErrorDetails(err)))
}

Expand Down
Loading