Skip to content

Commit

Permalink
changes as per feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyamsinghal committed Jan 9, 2025
1 parent bf65641 commit 028c168
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 49 deletions.
11 changes: 6 additions & 5 deletions yb-voyager/cmd/assessMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func assessMigration() (err error) {
}

log.Infof("number of assessment issues detected: %d\n", len(assessmentReport.Issues))

utils.PrintAndLog("Migration assessment completed successfully.")
completedEvent := createMigrationAssessmentCompletedEvent()
controlPlane.MigrationAssessmentCompleted(completedEvent)
Expand Down Expand Up @@ -1604,11 +1605,11 @@ func generateAssessmentReportJson(reportDir string) error {
log.Infof("writing assessment report to file: %s", jsonReportFilePath)

var err error
assessmentReport.MigrationComplexityExplainability, err = buildMigrationComplexityExplainability(assessmentReport, "text")
assessmentReport.MigrationComplexityExplaination, err = buildMigrationComplexityExplaination(source.DBType, assessmentReport, "")
if err != nil {
utils.PrintAndLog("ERROR: unable to build migration complexity explainability for json report: %v", err)
utils.PrintAndLog("ERROR: unable to build migration complexity explanation for json report: %v", err)
}
log.Info(assessmentReport.MigrationComplexityExplainability)
log.Info(assessmentReport.MigrationComplexityExplaination)

strReport, err := json.MarshalIndent(assessmentReport, "", "\t")
if err != nil {
Expand All @@ -1629,9 +1630,9 @@ func generateAssessmentReportHtml(reportDir string) error {
log.Infof("writing assessment report to file: %s", htmlReportFilePath)

var err error
assessmentReport.MigrationComplexityExplainability, err = buildMigrationComplexityExplainability(assessmentReport, "html")
assessmentReport.MigrationComplexityExplaination, err = buildMigrationComplexityExplaination(source.DBType, assessmentReport, "html")
if err != nil {
utils.PrintAndLog("ERROR: unable to build migration complexity explainability for html report: %v", err)
utils.PrintAndLog("ERROR: unable to build migration complexity explanation for html report: %v", err)
}

file, err := os.Create(htmlReportFilePath)
Expand Down
2 changes: 1 addition & 1 deletion yb-voyager/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ type AssessmentReport struct {
VoyagerVersion string `json:"VoyagerVersion"`
TargetDBVersion *ybversion.YBVersion `json:"TargetDBVersion"`
MigrationComplexity string `json:"MigrationComplexity"`
MigrationComplexityExplainability string `json:"MigrationComplexityExplainability"`
MigrationComplexityExplaination string `json:"MigrationComplexityExplaination"`
SchemaSummary utils.SchemaSummary `json:"SchemaSummary"`
Sizing *migassessment.SizingAssessmentReport `json:"Sizing"`
Issues []AssessmentIssue `json:"-"` // disabled in reports till corresponding UI changes are done(json and html reports)
Expand Down
64 changes: 22 additions & 42 deletions yb-voyager/cmd/migration_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func getComplexityForLevel(level string, count int) string {
}
}

// ======================================= Migration Complexity Explainability ==========================================
// ======================================= Migration Complexity Explanation ==========================================

const explainabilityTemplateHTML = `
const explainTemplateHTML = `
<pre>
|--------------------------------|---------|---------|---------|----------|
| Category | Level-1 | Level-2 | Level-3 | Total |
Expand All @@ -223,44 +223,19 @@ const explainabilityTemplateHTML = `
{{- end }}
|--------------------------------|---------|---------|---------|----------|
Level-1 Impact: Resolutions are available with minimal effort.
Level-2 Impact: Resolutions are available requiring moderate effort.
Level-3 Impact: Complex cases where resolutions may not be available or are highly complex.
Final Migration Complexity: {{ .MigrationComplexity }}
Reasoning: {{ .ComplexityRationale }}
</pre>
`

const explainabilityTemplateText = `
Migration Complexity Explainability
Categories and Issues:
{{- range .Summaries }}
Category: {{ .Category }}
Level-1 Issues: {{ index .ImpactCounts "LEVEL_1" }}
Level-2 Issues: {{ index .ImpactCounts "LEVEL_2" }}
Level-3 Issues: {{ index .ImpactCounts "LEVEL_3" }}
Total Issues: {{ .TotalIssueCount }}
{{- end }}
const explainTemplateText = `Reasoning: {{ .ComplexityRationale }}`

Final Migration Complexity: {{ .MigrationComplexity }}
Reasoning: {{ .ComplexityRationale }}
`

/*
{{ range .Summaries }}
---------------------------------------------------------------------
Category: {{ .Category }}
Highest Impact: {{ .HighestImpact }}
{{- if gt (len .HighestImpactIssues) 0 }}
Examples of highest-impact issues ({{ len .HighestImpactIssues }}):
{{- range .HighestImpactIssues }}
- {{ .Name }}
{{- end }}
{{- end }}
{{ end }}
{{ end }}
*/

type ExplainabilityData struct {
type ExplainationData struct {
Summaries []CategorySummary
MigrationComplexity string
ComplexityRationale string // short reasoning or explanation text
Expand All @@ -272,27 +247,31 @@ type CategorySummary struct {
ImpactCounts map[string]int // e.g. {"Level-1": 3, "Level-2": 5, "Level-3": 2}
}

func buildMigrationComplexityExplainability(assessmentReport AssessmentReport, reportFormat string) (string, error) {
var explainability ExplainabilityData
explainability.MigrationComplexity = assessmentReport.MigrationComplexity
explainability.ComplexityRationale = migrationComplexityRationale
func buildMigrationComplexityExplaination(sourceDBType string, assessmentReport AssessmentReport, reportFormat string) (string, error) {
if sourceDBType != POSTGRESQL {
return "", nil
}

var explaination ExplainationData
explaination.MigrationComplexity = assessmentReport.MigrationComplexity
explaination.ComplexityRationale = migrationComplexityRationale

explainability.Summaries = buildCategorySummary(assessmentReport.Issues)
explaination.Summaries = buildCategorySummary(assessmentReport.Issues)

var tmpl *template.Template
var err error
if reportFormat == "html" {
tmpl, err = template.New("Explainability").Parse(explainabilityTemplateHTML)
tmpl, err = template.New("Explain").Parse(explainTemplateHTML)
} else {
tmpl, err = template.New("Explainability").Parse(explainabilityTemplateText)
tmpl, err = template.New("Explain").Parse(explainTemplateText)
}

if err != nil {
return "", fmt.Errorf("failed creating the explainability template: %w", err)
return "", fmt.Errorf("failed creating the explaination template: %w", err)
}

var buf bytes.Buffer
if err := tmpl.Execute(&buf, explainability); err != nil {
if err := tmpl.Execute(&buf, explaination); err != nil {
return "", fmt.Errorf("failed executing the template with data: %w", err)
}
return buf.String(), nil
Expand Down Expand Up @@ -331,6 +310,7 @@ func buildCategorySummary(issues []AssessmentIssue) []CategorySummary {

var result []CategorySummary
for _, summary := range summaryMap {
summary.Category = utils.ToTitleCase(summary.Category)
result = append(result, *summary)
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<!-- Do nothing -->
{{else}}
<p><strong>Migration Complexity:</strong> {{ .MigrationComplexity }}</p>
<p><strong>Migration Complexity Explainability:</strong> {{ .MigrationComplexityExplainability }}</p>
{{end}}

<h2>Database Objects</h2>
Expand Down Expand Up @@ -168,6 +167,10 @@
{{ end }}
{{end}}

{{if ne .MigrationComplexity "NOT AVAILABLE"}}
<p><strong>Migration Complexity Explaination:</strong> {{ .MigrationComplexityExplaination }}</p>
{{end}}

<h2>Unsupported Data Types</h2>
<p>{{.UnsupportedDataTypesDesc}}</p>
{{ if .UnsupportedDataTypes }}
Expand Down
10 changes: 10 additions & 0 deletions yb-voyager/src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,13 @@ func CheckTools(tools ...string) []string {
func BuildObjectName(schemaName, objName string) string {
return lo.Ternary(schemaName != "", schemaName+"."+objName, objName)
}

// ToTitleCase converts a snake_case string to a title case string with spaces.
func ToTitleCase(snake string) string {
words := strings.Split(snake, "_")
for i, word := range words {
words[i] = strings.Title(word)
}

return strings.Join(words, " ")
}

0 comments on commit 028c168

Please sign in to comment.