Skip to content

Commit 1d37944

Browse files
committed
[fix] Fixed exporter api and error handling
1 parent ad1b446 commit 1d37944

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cmd/export.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ func remoteExportLogic(report TextReport, granularity string) {
7171
log.Fatalf("An Error Occured %v", err)
7272
}
7373
responseBody := bytes.NewBuffer(postBody)
74-
endPoint := fmt.Sprintf("%s/v1/gh/%s/%s/commit/%s/bench/%s/cpu/%s", codeperfUrl, gitOrg, gitRepo, gitCommit, bench, granularity)
74+
endPoint := fmt.Sprintf("%s/v1/gh/%s/%s/commit/%s/bench/%s/cpu/%s", codeperfApiUrl, gitOrg, gitRepo, gitCommit, bench, granularity)
7575
resp, err := http.Post(endPoint, "application/json", responseBody)
7676
//Handle Error
7777
if err != nil {
7878
log.Fatalf("An Error Occured %v", err)
7979
}
8080
defer resp.Body.Close()
81+
8182
//Read the response body
82-
_, err = ioutil.ReadAll(resp.Body)
83+
reply, err := ioutil.ReadAll(resp.Body)
8384
if err != nil {
8485
log.Fatalln(err)
8586
}
87+
if resp.StatusCode != 200 {
88+
log.Fatalf("An error ocurred while phusing data to remote %s. Status code %d. Reply: %s", codeperfApiUrl, resp.StatusCode, string(reply))
89+
}
8690
}
8791

8892
func localExportLogic(w io.Writer, report TextReport) {

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var gitRepo string
3434
var gitCommit string
3535
var localFilename string
3636
var codeperfUrl string
37+
var codeperfApiUrl string
3738
var local bool
3839
var longDescription = ` __ ____ _
3940
_________ ____/ /__ ____ ___ _____/ __/ (_)___
@@ -92,6 +93,7 @@ func init() {
9293
rootCmd.PersistentFlags().StringVar(&gitCommit, "git-hash", defaultGitCommit, "git commit hash")
9394
rootCmd.PersistentFlags().StringVar(&localFilename, "local-filename", "profile.json", "Local file to export the json to. Only used when the --local flag is set")
9495
rootCmd.PersistentFlags().StringVar(&codeperfUrl, "codeperf-url", "https://codeperf.io", "codeperf URL")
96+
rootCmd.PersistentFlags().StringVar(&codeperfApiUrl, "codeperf-api-url", "https://api.codeperf.io", "codeperf API URL")
9597
rootCmd.MarkPersistentFlagRequired("bench")
9698
}
9799

0 commit comments

Comments
 (0)