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

added pretty printing json, storing all chains, Chains type, module rename, go bump #28

Merged
merged 4 commits into from
Apr 21, 2021
Merged

added pretty printing json, storing all chains, Chains type, module rename, go bump #28

merged 4 commits into from
Apr 21, 2021

Conversation

RinkiyaKeDad
Copy link
Member

@RinkiyaKeDad RinkiyaKeDad commented Apr 16, 2021

Signed-off-by: RinkiyaKeDad arshsharma461@gmail.com

Fixes #26, prerequisite for #24.

  • Earlier we were only storing the longest chain of a particular length in a map[int][]string but with this PR we will be storing all chains of a particular length in a map[int][][]string. This is needed for create a graph that has all chains containing a specified dependency #24.
  • Added tests for this change.
  • Pretty printing the JSON output which was a part of this commit was not added to the original depstat repo so I've done that too in this PR.
  • Introducing the Chain type which is basically a []string.
  • Fixed module name in go.mod file and import in main.go.
  • Bumped Go version 1.15 -> 1.16

Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 16, 2021
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 16, 2021
@RinkiyaKeDad RinkiyaKeDad requested review from alenkacz and navidshaikh and removed request for dims and navidshaikh April 16, 2021 13:42
Copy link
Contributor

@alenkacz alenkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question which is not directly related to the PR but I think we should try to simplify the types there to make it more obvious for the readers if we absolutely don't need the performance of map there

cmd/cycles.go Outdated
@@ -33,7 +33,7 @@ var cyclesCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
depGraph, _, mainModule := getDepInfo()
var cycleChains [][]string
chains := make(map[int][]string)
chains := make(map[int][][]string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am starting to feel like these types are becoming "too much". Can we introduce some structs at least for one level of the arrays?

Actually I am checking the code now, why are we even storing the chains in map and what is that map used for? Looks like we're only writing to it and never reading from it?

chains[len(longestPath)] = longestPath

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @alenkacz!

Yeah, I totally forgot about using structs 😅 I'll update the PR replacing map[int][][]string with a struct.

To answer your other question I think we will still need maps since once we have the length of the longest chain/s, maps make it easier to retrieve the actual chain/s like done here.

The way to do this without using maps would be to iterate the [][]string and print each []string which has a length equal to "the length of the longest chain/s". Maps felt a bit more convenient to me since now instead of printing a single longest chain we print all the longest chains.

If there is a better way of doing this please let me know 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you only need the longest one you can always have struct like:

type Chains struct {
 chains []Chain

 longestChainsLength int
 longestChains []Chain
}

then we could have something like

type Chain struct {
 length int
 chain []string
}

Just a quick idea. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks perfect! Thanks for this. Will update the PR tomorrow :)

cmd/stats.go Outdated
fmt.Println("Longest chain is: ")
printChain(chains[maxDepth])
fmt.Println("Longest chain/s: ")
for _, chain := range chains[maxDepth] {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alenkacz here's the example where we read all the longest chains from the map.

Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 19, 2021
Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
@RinkiyaKeDad
Copy link
Member Author

@alenkacz looks like you were right. We didn't at all need maps for the chains. I tried converting the code to use the two structs we had discussed but that was unnecessarily introducing complications.
So instead of that I simplified everything by using a simple type Chain []string and some additional functions. PTAL 🙂

Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
@RinkiyaKeDad RinkiyaKeDad changed the title added pretty printing json, storing all chains and updated tests added pretty printing json, storing all chains, Chains type, module rename, go bump Apr 19, 2021
Copy link
Contributor

@alenkacz alenkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alenkacz, RinkiyaKeDad

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [RinkiyaKeDad,alenkacz]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@RinkiyaKeDad RinkiyaKeDad merged commit 269827e into kubernetes-sigs:main Apr 21, 2021
@RinkiyaKeDad RinkiyaKeDad deleted the 26_store_all_cycles branch April 21, 2021 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

store all cycles
3 participants