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

tools/horizon-cmp: Remove unnecessary panics, update temp folder names #1947

Merged
merged 3 commits into from
Nov 21, 2019
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
8 changes: 6 additions & 2 deletions tools/horizon-cmp/internal/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmp
import (
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"os/exec"
"regexp"
Expand Down Expand Up @@ -32,6 +33,7 @@ var removeRegexps = []*regexp.Regexp{
// regexp.MustCompile(`\s*"transaction_count": [0-9]+,`),
// regexp.MustCompile(`\s*"last_modified_ledger": [0-9]+,`),
// regexp.MustCompile(`\s*"public_key": "G.*",`),
// regexp.MustCompile(`,\s*"paging_token": ?""`),
}

type Response struct {
Expand Down Expand Up @@ -80,7 +82,9 @@ func NewResponse(domain, path string, stream bool) *Response {
if resp.StatusCode != http.StatusOK &&
resp.StatusCode != http.StatusNotFound &&
resp.StatusCode != http.StatusNotAcceptable &&
resp.StatusCode != http.StatusBadRequest {
resp.StatusCode != http.StatusBadRequest &&
resp.StatusCode != http.StatusGatewayTimeout &&
resp.StatusCode != http.StatusGone {
panic(resp.StatusCode)
}

Expand All @@ -94,7 +98,7 @@ func NewResponse(domain, path string, stream bool) *Response {
}

if string(body) == "" {
panic("Empty body")
response.Body = fmt.Sprintf("Empty body [%d]", rand.Uint64())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem does the rand in the body help with? Why wouldn't we want just to return an empty body?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing it's for debugging - ties the output to a specific instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to make sure that diff is saved when both, base and test, servers somehow return empty responses (otherwise this case would be ignore). In the future, horizon-cmp should retry in such cases.

}

response.Body = string(body)
Expand Down
4 changes: 3 additions & 1 deletion tools/horizon-cmp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
const maxLevels = 3
const pathsQueueCap = 10000

const timeFormat = "2006-01-02-15-04-05"

// pathAccessLog is a regexp that gets path from ELB access log line. Example:
// 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.000086 0.001048 0.001337 200 200 0 57 "GET https://www.example.com:443/transactions?order=desc HTTP/1.1" "curl/7.38.0" DHE-RSA-AES128-SHA TLSv1.2
var pathAccessLog = regexp.MustCompile(`([A-Z]+) https?://[^/]*(/[^ ]*)`)
Expand Down Expand Up @@ -119,7 +121,7 @@ func run(cmd *cobra.Command) {
if err != nil {
panic(err)
}
outputDir := fmt.Sprintf("%s/horizon-cmp-diff/%d", pwd, time.Now().Unix())
outputDir := fmt.Sprintf("%s/horizon-cmp-diff/%s", pwd, time.Now().Format(timeFormat))

log.WithFields(slog.F{
"base": horizonBase,
Expand Down