Add generate diff command to create html difference reports#199
Merged
AleksandarSavchev merged 8 commits intogardener:mainfrom Apr 1, 2024
Merged
Conversation
Contributor
|
@dimityrmirchev You have pull request review open invite, please check |
dimityrmirchev
requested changes
Apr 1, 2024
Member
dimityrmirchev
left a comment
There was a problem hiding this comment.
Looks, good. Only some cosmetic suggestions.
| #### Difference | ||
|
|
||
| Diki can generate a json containing the difference between 2 output files of `diki run` executions. This can help to identify improvements (or regressions). | ||
| Diki can generate a json containing the difference between 2 output files of `diki run` executions. This can help to identify improvements (or regressions). A human readable html difference report can also be generated from the json difference reports. |
Member
There was a problem hiding this comment.
Suggested change
| Diki can generate a json containing the difference between 2 output files of `diki run` executions. This can help to identify improvements (or regressions). A human readable html difference report can also be generated from the json difference reports. | |
| Diki can generate a json containing the difference between 2 output files of `diki run` executions. This can help to identify improvements (or regressions). A human readable html difference report can be generated from the difference reports. |
| diki report diff --title=Title --old=output1.json --new=output2.json --output=difference.json | ||
| ``` | ||
|
|
||
| - Generate html difference report from 1 or more json difference reports. |
Member
There was a problem hiding this comment.
Suggested change
| - Generate html difference report from 1 or more json difference reports. | |
| - Combine one or more json difference reports to an html report. |
|
|
||
| - Generate html difference report from 1 or more json difference reports. | ||
| ```bash | ||
| diki report generate diff --unique-attributes=gardener=id --output=difference.html difference1.json difference2.json |
Member
There was a problem hiding this comment.
Suggested change
| diki report generate diff --unique-attributes=gardener=id --output=difference.html difference1.json difference2.json | |
| diki report generate diff --identity-attributes=gardener=id --output=difference.html difference1.json difference2.json |
Comment on lines
+117
to
+118
| Short: "Generate diff converts difference reports to html.", | ||
| Long: "Generate diff converts difference reports to html.", |
Member
There was a problem hiding this comment.
Suggested change
| Short: "Generate diff converts difference reports to html.", | |
| Long: "Generate diff converts difference reports to html.", | |
| Short: "Generate diff combines difference reports into an html report.", | |
| Long: "Generate diff converts difference reports to html.", |
| func addReportDiffFlags(cmd *cobra.Command, opts *diffOptions) { | ||
| cmd.PersistentFlags().StringVar(&opts.oldReport, "old", "", "Old report path.") | ||
| cmd.PersistentFlags().StringVar(&opts.newReport, "new", "", "New report path.") | ||
| cmd.PersistentFlags().StringVar(&opts.title, "title", "", "Title for difference report.") |
Member
There was a problem hiding this comment.
Suggested change
| cmd.PersistentFlags().StringVar(&opts.title, "title", "", "Title for difference report.") | |
| cmd.PersistentFlags().StringVar(&opts.title, "title", "", "The title of a difference report.") |
| } | ||
|
|
||
| func addReportGenerateDiffFlags(cmd *cobra.Command, opts *generateDiffOptions) { | ||
| cmd.PersistentFlags().Var(cliflag.NewMapStringString(&opts.uniqueAttributes), "unique-attributes", "The keys are the IDs for the providers that will be present in the generated difference report and the values are metadata attributes to be used as IDs") |
Member
There was a problem hiding this comment.
Suggested change
| cmd.PersistentFlags().Var(cliflag.NewMapStringString(&opts.uniqueAttributes), "unique-attributes", "The keys are the IDs for the providers that will be present in the generated difference report and the values are metadata attributes to be used as IDs") | |
| cmd.PersistentFlags().Var(cliflag.NewMapStringString(&opts.uniqueAttributes), "identity-attributes", "The keys are the IDs of the providers that will be present in the generated difference report and the values are metadata attributes to be used as identifiers.") |
Comment on lines
+181
to
+184
| htlmRenderer, err := report.NewHTMLRenderer() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to initialize renderer: %w", err) | ||
| } |
Member
There was a problem hiding this comment.
This can be moved closer to its usage.
| } | ||
|
|
||
| type generateDiffOptions struct { | ||
| uniqueAttributes map[string]string |
| // Difference contains the difference between 2 reports. | ||
| type Difference struct { | ||
| // DifferenceReportWrapper wraps DifferenceReports and additional attributes needed for html rendering. | ||
| type DifferenceReportWrapper struct { |
Member
There was a problem hiding this comment.
Suggested change
| type DifferenceReportWrapper struct { | |
| type DifferenceReportsWrapper struct { |
| return template.HTML(summaryBuilder.String()) //nolint:gosec | ||
| } | ||
|
|
||
| func getDiffUniqAttrsText(providerDiff ProviderDifference, key string) string { |
Member
There was a problem hiding this comment.
Suggested change
| func getDiffUniqAttrsText(providerDiff ProviderDifference, key string) string { | |
| func getProviderDiffIDText(providerDiff ProviderDifference, key string) string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
This PR adds a new
diki report generate diffcommand that creates a html difference report with 1 or more json difference reports. The--identity-attributesis required, it's value is a list ofkey=valuepairs, where the keys are the IDs for the providers that will be present in the generated difference report and the values are metadata attributes to be used as IDs.Which issue(s) this PR fixes:
Fixes #159
Special notes for your reviewer:
Release note: