Skip to content

Commit

Permalink
splitting test name selector
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysied committed Jun 25, 2018
1 parent b0fa5be commit 76d6c19
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
5 changes: 4 additions & 1 deletion perfdash/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ type BuildData struct {
// TODO(random-liu): Use a more complex data structure if we need to support more test in the future.
type TestToBuildData map[string]*BuildData

func (b *TestToBuildData) ServeHTTP(res http.ResponseWriter, req *http.Request) {
// JobToTestData is a map from job name to TestToBuildData
type JobToTestData map[string]TestToBuildData

func (b *JobToTestData) ServeHTTP(res http.ResponseWriter, req *http.Request) {
data, err := json.Marshal(b)
if err != nil {
res.Header().Set("Content-type", "text/html")
Expand Down
19 changes: 10 additions & 9 deletions perfdash/google-gcs-downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func NewGoogleGCSDownloader(builds int) *GoogleGCSDownloader {
}

// TODO(random-liu): Only download and update new data each time.
func (g *GoogleGCSDownloader) getData() (TestToBuildData, error) {
func (g *GoogleGCSDownloader) getData() (JobToTestData, error) {
newJobs, err := getProwConfig()
if err == nil {
TestConfig[utils.KubekinsBucket] = newJobs
} else {
fmt.Fprintf(os.Stderr, "Failed to refresh config: %v", err)
}
fmt.Print("Getting Data from GCS...\n")
result := make(TestToBuildData)
result := make(JobToTestData)
var resultLock sync.Mutex
var wg sync.WaitGroup
wg.Add(len(TestConfig[utils.KubekinsBucket]))
Expand All @@ -59,12 +59,14 @@ func (g *GoogleGCSDownloader) getData() (TestToBuildData, error) {
return result, fmt.Errorf("Invalid empty Prefix for job %s", job)
}
for testLabel := range tests.Descriptions {
testName := tests.Prefix + "-" + testLabel
resultLock.Lock()
if _, found := result[testName]; found {
return result, fmt.Errorf("Duplicate name %s", testName)
if _, found := result[tests.Prefix]; !found {
result[tests.Prefix] = make(TestToBuildData)
}
result[testName] = &BuildData{Job: job, Version: "", Builds: map[string][]perftype.DataItem{}}
if _, found := result[tests.Prefix][testLabel]; found {
return result, fmt.Errorf("Duplicate name %s for %s", testLabel, tests.Prefix)
}
result[tests.Prefix][testLabel] = &BuildData{Job: job, Version: "", Builds: map[string][]perftype.DataItem{}}
resultLock.Unlock()
}
go g.getJobData(&wg, result, &resultLock, job, tests)
Expand All @@ -73,7 +75,7 @@ func (g *GoogleGCSDownloader) getData() (TestToBuildData, error) {
return result, nil
}

func (g *GoogleGCSDownloader) getJobData(wg *sync.WaitGroup, result TestToBuildData, resultLock *sync.Mutex, job string, tests Tests) {
func (g *GoogleGCSDownloader) getJobData(wg *sync.WaitGroup, result JobToTestData, resultLock *sync.Mutex, job string, tests Tests) {
defer wg.Done()
lastBuildNo, err := g.GoogleGCSBucketUtils.GetLastestBuildNumberFromJenkinsGoogleBucket(job)
if err != nil {
Expand Down Expand Up @@ -107,9 +109,8 @@ func (g *GoogleGCSDownloader) getJobData(wg *sync.WaitGroup, result TestToBuildD
fmt.Fprintf(os.Stderr, "Error when reading response Body: %v\n", err)
return
}
testName := tests.Prefix + "-" + testLabel
resultLock.Lock()
buildData := result[testName]
buildData := result[tests.Prefix][testLabel]
resultLock.Unlock()
testDescription.Parser(data, buildNumber, buildData)
}()
Expand Down
2 changes: 1 addition & 1 deletion perfdash/perfdash.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func run() error {
// TODO(random-liu): Add a top layer downloader to download build log from different buckets when we support
// more buckets in the future.
downloader := NewGoogleGCSDownloader(*builds)
result := make(TestToBuildData)
result := make(JobToTestData)
var err error

if !*www {
Expand Down
9 changes: 9 additions & 0 deletions perfdash/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ <h1 class="md-display-2">Performance Dashboard</h1>
</md-toolbar>
<div id="content" class="md-whiteframe-z2" style="padding: 20px">
<div style="width: 200px; display: inline-block;">
<md-input-container>
<md-select placeholder="JobName" ng-model="controller.jobName" ng-change="controller.jobNameChanged()">
<md-option ng-value="jobName" ng-repeat="jobName in controller.jobNames">
{{jobName}}
</md-option>
</md-select>
</md-input-container>
</div>
<div style="width: 200px; display: inline-block;">
<md-input-container>
<md-select placeholder="TestName" ng-model="controller.testName" ng-change="controller.testNameChanged()">
<md-option ng-value="testName" ng-repeat="testName in controller.testNames">
Expand Down
23 changes: 16 additions & 7 deletions perfdash/www/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ PerfDashApp.prototype.onClickInternal_ = function(data, evt, chart) {
PerfDashApp.prototype.refresh = function() {
this.http.get("api")
.success(function(data) {
this.testNames = Object.keys(data);
//init testName only if needed
if (this.testName == undefined || this.testNames.indexOf(this.testName) == -1) {
this.testName = this.testNames[0];
this.jobNames = Object.keys(data);
//init jobName only if needed
if (this.jobName == undefined || this.jobNames.indexOf(this.jobName) == -1) {
this.jobName = this.jobNames[0];
}
this.allData = data;
this.testNameChanged();
this.jobNameChanged();
}.bind(this))
.error(function(data) {
console.log("error fetching result");
Expand Down Expand Up @@ -88,10 +88,19 @@ PerfDashApp.prototype.labelChanged = function() {
this.cap = 0;
};

// Update the data to graph, using the selected jobName
PerfDashApp.prototype.jobNameChanged = function() {
this.testNames = Object.keys(this.allData[this.jobName])
if (this.testName == undefined || this.testNames.indexOf(this.testName) == -1) {
this.testName = this.testNames[0]
}
this.testNameChanged();
};

// Update the data to graph, using the selected testName
PerfDashApp.prototype.testNameChanged = function() {
this.data = this.allData[this.testName].builds;
this.job = this.allData[this.testName].job;
this.data = this.allData[this.jobName][this.testName].builds;
this.job = this.allData[this.jobName][this.testName].job;
this.builds = this.getBuilds();
this.labels = this.getLabels();
this.labelChanged();
Expand Down

0 comments on commit 76d6c19

Please sign in to comment.