Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for generating report from multiple different databases #33

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pkg/cmd/reportcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ func GetReportCommand() cli.Command {
Flags: append([]cli.Flag{testRunNamesFlag}, reportTypeFlags...),
Action: func(c *cli.Context) error {
var scDBs []*store.StorageClassDB
var convertedNames []string
for _, testRun := range testRunNames {
db, name := parseTestRun(testRun)
if db == "" {
db = c.GlobalString("db")
}
log.Info(db, ":", name)

convertedNames = append(convertedNames, name)

pathToDb := fmt.Sprintf("file:%s", db)
DB := store.NewSQLiteStore(pathToDb)
scDBs = append(scDBs, &store.StorageClassDB{
Expand Down Expand Up @@ -127,9 +124,9 @@ func GetReportCommand() cli.Command {

var err error
if len(types) == 0 {
err = reporter.GenerateAllReports(convertedNames, scDBs[0].DB)
err = reporter.GenerateAllReports(scDBs)
} else {
err = reporter.GenerateReports(convertedNames, types, scDBs[0].DB)
err = reporter.GenerateReports(types, scDBs)
}

if err != nil {
Expand Down
25 changes: 16 additions & 9 deletions pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ type MultiReporter interface {
}

// GenerateAllReports generates reports of types HTML and Text
func GenerateAllReports(testRunNames []string, db store.Store) error {
func GenerateAllReports(dbs []*store.StorageClassDB) error {
reportTypes := []ReportType{
HTMLReport,
TextReport,
}
return GenerateReports(testRunNames, reportTypes, db)
return GenerateReports(reportTypes, dbs)
}

// GenerateReportsFromMultipleDBs generates reports from multiple DBs
Expand Down Expand Up @@ -99,28 +99,35 @@ func GenerateReportsFromMultipleDBs(reportTypes []ReportType, scDBs []*store.Sto
}

// GenerateReports generates reports of type HTML and Text
func GenerateReports(testRunNames []string, reportTypes []ReportType, db store.Store) error {
mc := collector.NewMetricsCollector(db)
func GenerateReports(reportTypes []ReportType, dbs []*store.StorageClassDB) error {
funcMap := map[ReportType]Reporter{
HTMLReport: &HTMLReporter{},
TextReport: &TextReporter{},
}
log.Infof("Started generating reports...")

for _, testRun := range testRunNames {
metricsCollection, err := mc.Collect(testRun)
invalidTestRuns := []string{}
// Checking availability of all the test runs in every database
for i := 0; i < len(dbs); i++ {
mc := collector.NewMetricsCollector(dbs[i].DB)
metricsCollection, err := mc.Collect(dbs[i].TestRun.Name)
if err != nil {
return err
log.Warnf("unable to collect metrics for the test run: %s", dbs[i].TestRun.Name)
invalidTestRuns = append(invalidTestRuns, dbs[i].TestRun.Name)
continue
}

generatePlots(testRun, metricsCollection)
generatePlots(dbs[i].TestRun.Name, metricsCollection)

for _, reportType := range reportTypes {
if err := funcMap[reportType].Generate(testRun, metricsCollection); err != nil {
if err := funcMap[reportType].Generate(dbs[i].TestRun.Name, metricsCollection); err != nil {
return err
}
}
}
if len(invalidTestRuns) != 0 {
return fmt.Errorf("test runs: %v not found", invalidTestRuns)
}
return nil
}

Expand Down
81 changes: 43 additions & 38 deletions pkg/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,40 @@ func (sc *StdoutCapture) StopCapture() (string, error) {

type ReporterTestSuite struct {
suite.Suite
db store.Store
runName string
filepath string
db store.Store
runName string
filepath string
noRunIndbs []*store.StorageClassDB
successRunIndbs []*store.StorageClassDB
unsuccessfulRunIndbs []*store.StorageClassDB
}

func (suite *ReporterTestSuite) SetupSuite() {
plotter.FolderPath = "/.cert-csi/tmp/report-tests/"
suite.db = store.NewSQLiteStore("file:testdata/reporter_test.db")

// When the test run is not present in the database
noRunIndbsdbs := &store.StorageClassDB{DB: store.NewSQLiteStore("file:testdata/reporter_test.db")}

// When a test run is present in the database
successRunIndbs := &store.StorageClassDB{
DB: store.NewSQLiteStore("file:testdata/reporter_test.db"),
TestRun: store.TestRun{
Name: "test-run-d6d1f7c8",
},
}

// When unsuccessful test run is found in the database
unsuccessfulRunIndbs := &store.StorageClassDB{
DB: store.NewSQLiteStore("file:testdata/reporter_test.db"),
TestRun: store.TestRun{
Name: "unsuccessful-test-run",
},
}

suite.noRunIndbs = []*store.StorageClassDB{noRunIndbsdbs}
suite.successRunIndbs = []*store.StorageClassDB{successRunIndbs}
suite.unsuccessfulRunIndbs = []*store.StorageClassDB{unsuccessfulRunIndbs}
suite.runName = "test-run-d6d1f7c8"
curUser, err := os.UserHomeDir()
if err != nil {
Expand Down Expand Up @@ -113,74 +139,53 @@ func (suite *ReporterTestSuite) TestGenerateTextReporter() {
func (suite *ReporterTestSuite) TestGenerateAllReports() {

type args struct {
testRunNames []string
db store.Store
dbs []*store.StorageClassDB
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "all nil",
name: "nil dbs",
args: args{
testRunNames: nil,
db: nil,
dbs: nil,
},
wantErr: false,
},
{
name: "nil db",
name: "no run in dbs",
args: args{
testRunNames: []string{"test-run-d6d1f7c8"},
db: nil,
dbs: suite.noRunIndbs,
},
wantErr: true,
},
{
name: "nil name",
name: "successful test run",
args: args{
testRunNames: nil,
db: suite.db,
dbs: suite.successRunIndbs,
},
wantErr: false,
},
{
name: "no run in db",
name: "unsuccessful test run",
args: args{
testRunNames: []string{"non-existent-name"},
db: suite.db,
dbs: suite.unsuccessfulRunIndbs,
},
wantErr: true,
},
{
name: "single successful test run",
args: args{
testRunNames: []string{"test-run-d6d1f7c8"},
db: suite.db,
},
wantErr: false,
},
{
name: "successful and unsuccessful test run",
args: args{
testRunNames: []string{"test-run-d6d1f7c8", "test-run-e47deecc"},
db: suite.db,
},
wantErr: false,
},
}
for _, tt := range tests {
suite.Run(tt.name, func() {
err := GenerateAllReports(tt.args.testRunNames, tt.args.db)
err := GenerateAllReports(tt.args.dbs)
if tt.wantErr {
suite.Error(err)
} else {
suite.NoError(err)
for _, run := range tt.args.testRunNames {
name := fmt.Sprintf("report-%s", run)
htmlPath := fmt.Sprintf(suite.filepath+"/reports/%s/%s.html", run, name)
txtPath := fmt.Sprintf(suite.filepath+"/reports/%s/%s.txt", run, name)
for _, run := range tt.args.dbs {
name := fmt.Sprintf("report-%s", run.TestRun.Name)
htmlPath := fmt.Sprintf(suite.filepath+"/reports/%s/%s.html", run.TestRun.Name, name)
txtPath := fmt.Sprintf(suite.filepath+"/reports/%s/%s.txt", run.TestRun.Name, name)
suite.FileExists(htmlPath)
suite.FileExists(txtPath)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testcore/runner/perf-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (sr *SuiteRunner) Close() {

for _, scDB := range sr.ScDBs {
if sr.NoMetrics == false && sr.noreport == false {
err := reporter.GenerateAllReports([]string{scDB.TestRun.Name}, scDB.DB)
err := reporter.GenerateAllReports(sr.ScDBs)
if err != nil {
logrus.Errorf("Can't generate reports; error=%v", err)
}
Expand Down