-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aditya Bharadwaj
committed
Feb 5, 2025
1 parent
ff09f97
commit f46e62e
Showing
7 changed files
with
433 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
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 | ||
} |
This file contains 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
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 | ||
} |
This file contains 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
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 | ||
} |
This file contains 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
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 | ||
} |
Oops, something went wrong.