Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Bharadwaj committed Feb 5, 2025
1 parent ff09f97 commit f46e62e
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
//WebV2 debugger using global command line mode.
"name": "webv2",
Expand Down Expand Up @@ -35,6 +36,17 @@
"program": "${workspaceRoot}/main.go",
"args": ["schema-and-data", "-source=XXX", "--target-profile=instance=XXX", "--source-profile=host=XXX,port=XXX,user=XXX,password=XXX,dbName=XXX","--log-level=DEBUG"
]
},
{
//Debugging configuration for schema-and-data command, replace XXX with valid values to start debugging.
"name": "assessment",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/main.go",
"args": ["assessment", "-source=XXX", "--target-profile=instance=XXX", "--source-profile=host=XXX,port=XXX,user=XXX,password=XXX,dbName=XXX","--log-level=DEBUG"
],
"dlvFlags": ["--check-go-version=false"]
}
]
],
}
94 changes: 94 additions & 0 deletions assessment/assessment_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.*/

package assessment

import (
assessment "github.com/GoogleCloudPlatform/spanner-migration-tool/assessment/collectors"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/logger"
)

type AssessmentOutput struct {
costAssessment CostAssessmentOutput
schemaAssessment SchemaAssessmentOutput
appCodeAssessment AppCodeAssessmentOutput
queryAssessment QueryAssessmentOutput
performanceAssessment PerformanceAssessmentOutput
}

type CostAssessmentOutput struct {
//TBD
}

type SchemaAssessmentOutput struct {
//TBD
tableNames []string
}

type AppCodeAssessmentOutput struct {
//TBD
}

type QueryAssessmentOutput struct {
//TBD
}

type PerformanceAssessmentOutput struct {
//TBD
}

type assessmentCollectors struct {
sampleCollector assessment.SampleCollector
}

func PerformAssessment(conv *internal.Conv) (AssessmentOutput, error) {

logger.Log.Info("performing assessment")

output := AssessmentOutput{}
// Initialize collectors
c, err := initializeCollectors()
if err != nil {
logger.Log.Fatal("unable to initiliaze collectors")
return output, err
}

// perform each type of assessment (in parallel) - cost, schema, app code, query, performance
// within each type of assessment (in parallel) - invoke each collector to fetch information from relevant rules
// Iterate over assessment rules and order output by confidence of each element. Merge outputs where required
// Select the highest confidence output for each attribute
// Populate assessment struct

output.schemaAssessment, err = performSchemaAssessment(c)
return output, nil
}

// Initilize collectors. Take a decision here on which collectors are mandatory and which are optional
func initializeCollectors() (assessmentCollectors, error) {
c := assessmentCollectors{}
sampleCollector, err := assessment.CreateSampleCollector()
if err != nil {
return c, err
}
c.sampleCollector = sampleCollector
return c, nil
}

func performSchemaAssessment(collectors assessmentCollectors) (SchemaAssessmentOutput, error) {
schemaOut := SchemaAssessmentOutput{}
tables := collectors.sampleCollector.ListTables()
schemaOut.tableNames = tables
return schemaOut, nil
}
75 changes: 75 additions & 0 deletions assessment/collectors/elements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.*/

package assessment

import "github.com/GoogleCloudPlatform/spanner-migration-tool/schema"

// All the elements that will be a part of the assessment
// If this file becomes too big, or if type specific methods get added, consider splitting this file

// Idenitification of the database which can be referred to in the assessment
type DbIdentifier struct {
databaseName string
namespace string
}

// Information relevant to assessment of tables
type TableAssessment struct {
db DbIdentifier
name string
tableDef schema.Table
columnAssessments []ColumnAssessment[any]
}

// Information relevant to assessment of columns
type ColumnAssessment[T any] struct {
db DbIdentifier
tableDef schema.Table
maxValue T
minValue T
}

// Information relevant to assessment of stored procedures
type StoredProcedureAssessment struct {
db DbIdentifier
name string
linesOfCode int
tablesAffected []string
referecesInCode int
}

// Information relevant to assessment of triggers
type TriggerAssessment struct {
db DbIdentifier
name string
operation string
targetTables []string
}

// Information relevant to assessment of queries
type QueryAssessment struct {
db DbIdentifier
name string
lengthOfQuery string
tablesAffected []string
}

// Information relevant to assessment of queries
type CodeAssessment struct {
fileName string
methodName string
linesOfChange string
relatedDbElements []any //We might need to break this into multiple fields
}
45 changes: 45 additions & 0 deletions assessment/collectors/sample_collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.*/

package assessment

import (
"github.com/GoogleCloudPlatform/spanner-migration-tool/logger"
)

// This is sample implementation to bootstrap.
// Once the collectors are implemented, this can be deleted
type SampleCollector struct {
tables []TableAssessment
}

func CreateSampleCollector() (SampleCollector, error) {
logger.Log.Info("initializing sample collector")
tb := []TableAssessment{
{name: "t1"},
{name: "t2"},
}
return SampleCollector{
tables: tb,
}, nil
}

func (c SampleCollector) ListTables() []string {
var tableArray []string = []string{}

for i := range c.tables {
tableArray = append(tableArray, c.tables[i].name)
}
return tableArray
}
30 changes: 30 additions & 0 deletions assessment/report_generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.*/

package assessment

import (
"fmt"

"github.com/GoogleCloudPlatform/spanner-migration-tool/logger"
)

func GenerateReport(assessmentOutput AssessmentOutput) {
//pull data from assessment output
//Write to report in require format
//publish report locally/on GCS
logger.Log.Info(fmt.Sprintf("%+v", assessmentOutput))
logger.Log.Info("completed publishing sample report")
return
}
Loading

0 comments on commit f46e62e

Please sign in to comment.