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

[bug] pkg/guacanalytics/patchPlanning.go fills in parent field for root nodes #1120

Closed
rmetzman opened this issue Aug 2, 2023 · 7 comments · Fixed by #1131
Closed

[bug] pkg/guacanalytics/patchPlanning.go fills in parent field for root nodes #1120

rmetzman opened this issue Aug 2, 2023 · 7 comments · Fixed by #1131
Assignees
Labels
bug Something isn't working

Comments

@rmetzman
Copy link
Contributor

rmetzman commented Aug 2, 2023

Describe the bug
pkg/guacanalytics/patchPlanning.go for the root/input nodes which should have an empty parents list, the program for some reason populated this field to contain an empty string.

To Reproduce
Steps to reproduce the behavior:

  1. Run the SearchDependenciesFromStartNode func
  2. Run ToposortFromBfsNodeMap on the output (pkg/guacanalytics/toposort.go)
  3. You will notice it doesn't enter the len(parentsList) == 0, even for the root nodes that do not have a parent so it thinks a cycle is detected
  4. Try adding "parentsList[0] == "" && len(parentsList) == 1" to the if statement and you will see it does enter the clause

Expected behavior
len(parentsList) should == 1 for the start nodes inputted

@rmetzman rmetzman added the bug Something isn't working label Aug 2, 2023
@nathannaveen
Copy link
Contributor

Could I work on this?

cc @pxp928

@pxp928
Copy link
Collaborator

pxp928 commented Aug 4, 2023

@rmetzman are you already working to fix this?

@rmetzman
Copy link
Contributor Author

rmetzman commented Aug 4, 2023

Nope, I haven't started working on this yet.

@pxp928
Copy link
Collaborator

pxp928 commented Aug 4, 2023

@nathannaveen assigning to you!

@nathannaveen
Copy link
Contributor

@rmetzman and @pxp928

I assume that the statement in the expected behavior part: "len(parentsList) should == 1 for the start nodes inputted” is a typo and should be: "len(parentsList) should == 0 for the start nodes inputted”. I am using this assumption for the following part of this comment.

I am pretty sure that I have located the issue regarding where the root nodes having non empty parents is located.

If we start inside the function ToposortFromBfsNodeMap at the part of if len(parentsList) == 0 {, we can see that each parentsList is from parentsMap, and parentsMap is equal to copyParents(nodeMap). copyParents just copies the Parents parameter from the BfsNode struct of key in the inputMap. This shows us that we just have to look at where the Parents values of the nodeMap are being edited.

Now we get to SearchDependenciesFromStartNode. Now the only place where q.nodeMap can be edited is:

Line 80:

if len(nodePkg.AllPkgTree.Namespaces[0].Names[0].Versions) == 0 {
// TODO: handle case where there are circular dependencies that introduce more versions to the version list on a node that requires revisiting
err := q.addNodesToQueueFromPackageName(ctx, gqlClient, nodePkg.AllPkgTree.Type, nodePkg.AllPkgTree.Namespaces[0].Namespace, nodePkg.AllPkgTree.Namespaces[0].Names[0].Name, startID)
if err != nil {
return nil, err
}

On line 87 we are also editing q.nodeMap[startID], but that can't be the issue because we are only assigning the Parents with []string{}.

Now we have to go into the function addNodesToQueueFromPackageName. Since q is empty we pretty much pass by all if statements and for loops until we get to:

Line 445:

q.nodeMap[id] = BfsNode{
Parents: []string{q.now},
Depth: q.nowNode.Depth + 1,
Type: PackageName,
nodeVersions: versionsList,
PointOfContact: q.nowNode.PointOfContact,
}

We are setting Parents to []string{q.now}. Since we haven't set q.now it is empty resulting in an empty string being added to the Parents array.

Correct me if I am wrong, but I am pretty sure that this is the only place where Parents is being set to an empty string.

@rmetzman
Copy link
Contributor Author

rmetzman commented Aug 7, 2023

Yes, this makes sense to me, I think that must be causing the issue.

nathannaveen added a commit to nathannaveen/guac that referenced this issue Aug 7, 2023
* In pkg/guacanalytics/patchPlanning.go removed the empty string parents for root nodes. The explanation for this is: guacsec#1120 (comment)
* Changed q.now to a pointer
* Fixes guacsec#1120

Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com>
@nathannaveen
Copy link
Contributor

Yes, this makes sense to me, I think that must be causing the issue.

Thank You!

nathannaveen added a commit to nathannaveen/guac that referenced this issue Aug 7, 2023
* In pkg/guacanalytics/patchPlanning.go removed the empty string parents for root nodes. The explanation for this is: guacsec#1120 (comment)
* Changed q.now to a pointer
* Fixes guacsec#1120

Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com>
@kodiakhq kodiakhq bot closed this as completed in #1131 Aug 15, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 15, 2023
* In pkg/guacanalytics/patchPlanning.go removed the empty string parents for root nodes. The explanation for this is: #1120 (comment)
* Changed q.now to a pointer
* Fixes #1120

Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants