diff --git a/yb-voyager/cmd/assessMigrationCommand.go b/yb-voyager/cmd/assessMigrationCommand.go index 556ddb577..b245ae507 100644 --- a/yb-voyager/cmd/assessMigrationCommand.go +++ b/yb-voyager/cmd/assessMigrationCommand.go @@ -493,7 +493,7 @@ func createMigrationAssessmentCompletedEvent() *cp.MigrationAssessmentCompletedE } assessmentIssues := flattenAssessmentReportToAssessmentIssues(assessmentReport) - + // assessmentReport.SerializationMode = "full" payload := AssessMigrationPayload{ PayloadVersion: ASSESS_MIGRATION_PAYLOAD_VERSION, VoyagerVersion: assessmentReport.VoyagerVersion, @@ -1609,6 +1609,7 @@ func generateAssessmentReportJson(reportDir string) error { } log.Infof("migration complexity explanation: %q", assessmentReport.MigrationComplexityExplanation) + // assessmentReport.SerializationMode = "minimal" strReport, err := json.MarshalIndent(assessmentReport, "", "\t") if err != nil { return fmt.Errorf("failed to marshal the assessment report: %w", err) diff --git a/yb-voyager/cmd/common.go b/yb-voyager/cmd/common.go index ff2f6ffd1..05747f7b2 100644 --- a/yb-voyager/cmd/common.go +++ b/yb-voyager/cmd/common.go @@ -1050,6 +1050,7 @@ func storeTableListInMSR(tableList []sqlname.NameTuple) error { // ===================================================================== // TODO: consider merging all unsupported field with single AssessmentReport struct member as AssessmentIssue +// NOTE: If you add or remove any field, consider updating MarshalJSON() method if required type AssessmentReport struct { VoyagerVersion string `json:"VoyagerVersion"` TargetDBVersion *ybversion.YBVersion `json:"TargetDBVersion"` @@ -1060,7 +1061,7 @@ type AssessmentReport struct { Issues []AssessmentIssue `json:"-"` // disabled in reports till corresponding UI changes are done(json and html reports) TableIndexStats *[]migassessment.TableIndexStats `json:"TableIndexStats"` Notes []string `json:"Notes"` - + SerializationMode string `json:"-"` // field to control serialization of json // fields going to be deprecated UnsupportedDataTypes []utils.TableColumnsDataTypes `json:"UnsupportedDataTypes"` UnsupportedDataTypesDesc string `json:"UnsupportedDataTypesDesc"` @@ -1191,6 +1192,40 @@ func ParseJSONToAssessmentReport(reportPath string) (*AssessmentReport, error) { return &report, nil } +// Implementing json.Marshaler interface by defining MarshalJSON() to have customised serialization +// NOTE: Ensure that AssessmentReport is passed as value in json.Marshal() to invoke custom MarshalJSON logic. +func (ar AssessmentReport) MarshalJSON() ([]byte, error) { + switch ar.SerializationMode { + case "full", "": + type Alias AssessmentReport + return json.Marshal(Alias(ar)) + case "minimal": + return json.Marshal(struct { + VoyagerVersion string `json:"VoyagerVersion"` + TargetDBVersion *ybversion.YBVersion `json:"TargetDBVersion"` + MigrationComplexity string `json:"MigrationComplexity"` + MigrationComplexityExplanation string `json:"MigrationComplexityExplanation"` + SchemaSummary utils.SchemaSummary `json:"SchemaSummary"` + Sizing *migassessment.SizingAssessmentReport `json:"Sizing"` + Issues []AssessmentIssue `json:"AssessmentIssues"` + TableIndexStats *[]migassessment.TableIndexStats `json:"TableIndexStats"` + Notes []string `json:"Notes"` + }{ + VoyagerVersion: ar.VoyagerVersion, + TargetDBVersion: ar.TargetDBVersion, + MigrationComplexity: ar.MigrationComplexity, + MigrationComplexityExplanation: ar.MigrationComplexityExplanation, + SchemaSummary: ar.SchemaSummary, + Sizing: ar.Sizing, + Issues: ar.Issues, + TableIndexStats: ar.TableIndexStats, + Notes: ar.Notes, + }) + default: + return nil, fmt.Errorf("unsupported serialization mode: %s", ar.SerializationMode) + } +} + func (ar *AssessmentReport) AppendIssues(issues ...AssessmentIssue) { ar.Issues = append(ar.Issues, issues...) } diff --git a/yb-voyager/cmd/common_test.go b/yb-voyager/cmd/common_test.go index 9fd9635f3..bfc1a4052 100644 --- a/yb-voyager/cmd/common_test.go +++ b/yb-voyager/cmd/common_test.go @@ -138,6 +138,7 @@ func TestAssessmentReportStructs(t *testing.T) { Issues []AssessmentIssue `json:"-"` TableIndexStats *[]migassessment.TableIndexStats `json:"TableIndexStats"` Notes []string `json:"Notes"` + SerializationMode string `json:"-"` UnsupportedDataTypes []utils.TableColumnsDataTypes `json:"UnsupportedDataTypes"` UnsupportedDataTypesDesc string `json:"UnsupportedDataTypesDesc"` UnsupportedFeatures []UnsupportedFeature `json:"UnsupportedFeatures"`