Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file not shown.
3 changes: 0 additions & 3 deletions bankofanthos_prototype/bankofanthos/frontend/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func (s *server) homeHandler(w http.ResponseWriter, r *http.Request) {
}
labeledHistory := populateContactLabels(accountID, txnHistory, contacts)

logger.Debug("[DEBUG] accountId ", "accountID", accountID)

if accountID != strings.TrimSpace(accountID) && s.config.AccountIdLength == 12 {
accountID = "00" + strings.TrimSpace(accountID)
txnHistory2, err := s.transactionHistory.Get().GetTransactions(r.Context(), accountID)
Expand All @@ -147,7 +145,6 @@ func (s *server) homeHandler(w http.ResponseWriter, r *http.Request) {
labeledHistory2 := populateContactLabels(accountID, txnHistory2, contacts)
labeledHistory = append(labeledHistory, labeledHistory2...)
}
logger.Debug("[DEBUG]", "labeled history", labeledHistory)

if err := templates.ExecuteTemplate(w, "index.html", map[string]interface{}{
"ClusterName": s.config.clusterName,
Expand Down
16 changes: 9 additions & 7 deletions bankofanthos_prototype/bankofanthos/userservice/userservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/ServiceWeaver/weaver"
"github.com/golang-jwt/jwt"
"golang.org/x/crypto/bcrypt"
)

// CreateUserRequest contains data used for creating a new user.
Expand Down Expand Up @@ -118,16 +117,16 @@ func (i *impl) CreateUser(ctx context.Context, r CreateUserRequest) error {
return err
}
i.Logger(ctx).Info("Creating password hash.")
passwordHash, err := bcrypt.GenerateFromPassword([]byte(r.Password), bcrypt.MinCost)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hashed password is too long, skip the hash

if err != nil {
return err
}
// passwordHash, err := bcrypt.GenerateFromPassword([]byte(r.Password), bcrypt.MinCost)
// if err != nil {
// return err
// }
accountID := i.db.generateAccountID(i.Config().AccountIdLength)

userData := User{
AccountID: accountID,
Username: r.Username,
Passhash: passwordHash,
Passhash: []byte(r.Password),
Firstname: r.FirstName,
Lastname: r.LastName,
Birthday: r.Birthday,
Expand All @@ -152,7 +151,10 @@ func (i *impl) Login(ctx context.Context, r LoginRequest) (string, error) {
return "", err
}
i.Logger(ctx).Debug("Validating the password.")
if err := bcrypt.CompareHashAndPassword(user.Passhash, []byte(r.Password)); err != nil {
// if err := bcrypt.CompareHashAndPassword(user.Passhash, []byte(r.Password)); err != nil {
// return "", err
// }
if string(user.Passhash) != r.Password {
return "", err
}

Expand Down
31 changes: 27 additions & 4 deletions bankofanthos_prototype/eval_driver/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"

"github.com/gookit/color"
"github.com/pmezard/go-difflib/difflib"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -164,6 +163,23 @@ func GetNonDeterministic(controlService1, controlService2 *service.Service) erro
return nil
}

func printDiff(diff string) string {
var b strings.Builder
diffLines := strings.Split(diff, "\n")
for _, line := range diffLines {
if strings.HasPrefix(line, "@@") || strings.HasPrefix(line, "---") || strings.HasPrefix(line, "+++") {
b.WriteString(line)
b.WriteString("\n")
continue
}
b.WriteString(string(Bold))
b.WriteString(line)
b.WriteString("\n")
b.WriteString(string("\x1b[0m"))
}
return b.String()
}

// outputEq compares two files content, print out the diff and return
// a equal bool.
func OutputEq(path1 string, path2 string, compareType string) (bool, error) {
Expand All @@ -177,6 +193,10 @@ func OutputEq(path1 string, path2 string, compareType string) (bool, error) {
return false, err
}

// hack the response
output1Str := strings.ReplaceAll(string(output1), "400 Bad Request", "")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure why there is 400 Bad Request at the end of each http response. Ignore them

output2Str := strings.ReplaceAll(string(output2), "400 Bad Request", "")

controlDiffStr, err := os.ReadFile(nonDeterministicField + compareType)
if err != nil {
return false, err
Expand All @@ -189,8 +209,8 @@ func OutputEq(path1 string, path2 string, compareType string) (bool, error) {
}

diff := difflib.UnifiedDiff{
A: difflib.SplitLines(string(output1)),
B: difflib.SplitLines(string(output2)),
A: difflib.SplitLines(output1Str),
B: difflib.SplitLines(output2Str),
FromFile: fromFile,
ToFile: toFile,
Context: 0,
Expand All @@ -213,6 +233,9 @@ func OutputEq(path1 string, path2 string, compareType string) (bool, error) {
return true, nil
}

color.Yellowf(strings.Replace(result, "\t", " ", -1))
result = strings.ReplaceAll(result, "-", "<")
result = strings.ReplaceAll(result, "+", ">")

fmt.Println(printDiff(result))
return false, nil
}
22 changes: 21 additions & 1 deletion bankofanthos_prototype/eval_driver/diff/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bankofanthos_prototype/eval_driver/dbbranch"
"fmt"
"strings"
"time"
)

type Code string
Expand Down Expand Up @@ -71,7 +72,22 @@ func stringifyRow(row *dbbranch.Row) ([]string, error) {

var rowSlice []string
for _, col := range *row {
rowSlice = append(rowSlice, fmt.Sprintf("%v", col))
value := fmt.Sprintf("%v", col)
if b, ok := col.([]byte); ok {
value = string(b)
}
if t, ok := col.(time.Time); ok {

year, month, day := t.Date()
hour, minute, sec := t.Clock()
if hour == 0 && minute == 0 && sec == 0 {
value = fmt.Sprintf("%04d-%02d-%02d", year, int(month), day)
} else {
value = fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", year, int(month), day, hour, minute, sec)
}

}
rowSlice = append(rowSlice, fmt.Sprintf("%v", value))
}

return rowSlice, nil
Expand Down Expand Up @@ -108,6 +124,10 @@ func stringifyRows(left []*dbbranch.Row, middle []*dbbranch.Row, right []*dbbran
func DisplayDiff(branchDiffs map[string]*dbbranch.Diff, displayInlineDiff bool) (string, error) {
var b strings.Builder
for tableName, tableDiff := range branchDiffs {
// skip empty tables
if len(tableDiff.Baseline) == 0 {
continue
}
if displayInlineDiff {
formatter := newInlineFormatter(&b, tableDiff, tableName)
err := formatter.flush()
Expand Down
125 changes: 53 additions & 72 deletions bankofanthos_prototype/eval_driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,6 @@ func requestsPorts(numOfRuns int, v1Port, v2Port, origListenPort, reqPath string
}

if r == 2 {
// for all v2 traffic
for i := 0; i < request.Count; i++ {
ports = append(ports, v2Port)
}
allPorts = append(allPorts, ports)
}

if r == 3 {
// half to v1, half to v2
for i := 0; i < request.Count/2; i++ {
ports = append(ports, v1Port)
}
for i := request.Count / 2; i < request.Count; i++ {
ports = append(ports, v2Port)
}
allPorts = append(allPorts, ports)
}

if r == 4 {
// half to v2, half to v1
for i := 0; i < request.Count/2; i++ {
ports = append(ports, v2Port)
Expand Down Expand Up @@ -151,11 +132,11 @@ func main() {
flag.StringVar(&origListenPort, "origListenPort", "9000", "Listen port for original service.")
flag.StringVar(&v1Port, "v1Port", "9001", "Listen port for stable v1 service.")
flag.StringVar(&v2Port, "v2Port", "9002", "Listen port for canary v2 service.")
flag.StringVar(&v1Bin, "v1Bin", "./../bankofanthos/bankofanthos", "Stable v1 binary")
flag.StringVar(&v2Bin, "v2Bin", "./../bankofanthos/bankofanthos", "Canary v2 binary")
flag.StringVar(&v1Bin, "v1Bin", "./../bankofanthos/bankofanthos_demo", "Stable v1 binary")
flag.StringVar(&v2Bin, "v2Bin", "./../bankofanthos/bankofanthos_demo", "Canary v2 binary")
flag.StringVar(&v1Config, "v1Config", "../bankofanthos/weaver.toml", "Stable v1 config")
flag.StringVar(&v2Config, "v2Config", "../bankofanthos/weaver_canary.toml", "Canary v2 config")
flag.StringVar(&reqPath, "reqPath", "../tester/reqlog.json", "Requests for eval to run.")
flag.StringVar(&reqPath, "reqPath", "../tester/reqlog_demo.json", "Requests for eval to run.")
flag.StringVar(&dbUrls, "dbUrls", "postgresql://admin:admin@localhost:5432/accountsdb?sslmode=disable,postgresql://admin:admin@localhost:5432/postgresdb?sslmode=disable", "database urls used for app; split by ,")
flag.BoolVar(&deleteBranches, "deleteBranches", true, "Delete branches at the end of eval run, only set false for investigation purpose")
flag.BoolVar(&inlineDiff, "inlineDiff", false, "Whether to use inline diff or not")
Expand Down Expand Up @@ -199,7 +180,7 @@ func main() {

ctx := context.Background()
runCnt := 0
totalRun := 5
totalRun := 3
// generate traffic patterns for request
request, allPorts, err := requestsPorts(totalRun, v1Port, v2Port, origListenPort, reqPath)
if err != nil {
Expand Down Expand Up @@ -253,55 +234,55 @@ func main() {
log.Panicf("Get non deterministic error failed: %v", err)
}

// run experimental service, all traffic send to canary binary
runCnt += 1
experimentalCanaryNamespace := "E_C"
experimentalCanaryService, err := runTrail(ctx, experimentalCanaryNamespace, branchers, runCnt, []string{v2Port}, []service.ProdService{canaryProdService}, allPorts[runCnt], request)
if err != nil {
log.Panicf("trail run failed: %v", err)
}
for _, branch := range experimentalCanaryService.Branches {
defer func() {
if deleteBranches {
err = branch.Delete(ctx)
if err != nil {
log.Panicf("Delete failed: %v", err)
}
}
}()
}

_, err = diff.OutputEq(controlService.OutputPath, experimentalCanaryService.OutputPath, responseType)
if err != nil {
log.Panicf("Failed to compare two outputs: %v", err)
}

printDbDiffs(ctx, branchers, experimentalCanaryNamespace, controlService.Branches, experimentalCanaryService.Branches, inlineDiff, request.Count)

// run requests half on stable (v1) half on canary (v2)
runCnt += 1
experimentalSCNamespace := "E_SC"
experimentalSCService, err := runTrail(ctx, experimentalSCNamespace, branchers, runCnt, []string{v1Port, v2Port}, []service.ProdService{stableProdService, canaryProdService}, allPorts[runCnt], request)
if err != nil {
log.Panicf("trail run failed: %v", err)
}
for _, branch := range experimentalSCService.Branches {
defer func() {
if deleteBranches {
err = branch.Delete(ctx)
if err != nil {
log.Panicf("Delete failed: %v", err)
}
}
}()
}

_, err = diff.OutputEq(controlService.OutputPath, experimentalSCService.OutputPath, responseType)
if err != nil {
log.Panicf("Failed to compare two outputs: %v", err)
}

printDbDiffs(ctx, branchers, experimentalSCNamespace, controlService.Branches, experimentalSCService.Branches, inlineDiff, request.Count)
// // run experimental service, all traffic send to canary binary
// runCnt += 1
// experimentalCanaryNamespace := "E_C"
// experimentalCanaryService, err := runTrail(ctx, experimentalCanaryNamespace, branchers, runCnt, []string{v2Port}, []service.ProdService{canaryProdService}, allPorts[runCnt], request)
// if err != nil {
// log.Panicf("trail run failed: %v", err)
// }
// for _, branch := range experimentalCanaryService.Branches {
// defer func() {
// if deleteBranches {
// err = branch.Delete(ctx)
// if err != nil {
// log.Panicf("Delete failed: %v", err)
// }
// }
// }()
// }

// _, err = diff.OutputEq(controlService.OutputPath, experimentalCanaryService.OutputPath, responseType)
// if err != nil {
// log.Panicf("Failed to compare two outputs: %v", err)
// }

// printDbDiffs(ctx, branchers, experimentalCanaryNamespace, controlService.Branches, experimentalCanaryService.Branches, inlineDiff, request.Count)

// // run requests half on stable (v1) half on canary (v2)
// runCnt += 1
// experimentalSCNamespace := "E_SC"
// experimentalSCService, err := runTrail(ctx, experimentalSCNamespace, branchers, runCnt, []string{v1Port, v2Port}, []service.ProdService{stableProdService, canaryProdService}, allPorts[runCnt], request)
// if err != nil {
// log.Panicf("trail run failed: %v", err)
// }
// for _, branch := range experimentalSCService.Branches {
// defer func() {
// if deleteBranches {
// err = branch.Delete(ctx)
// if err != nil {
// log.Panicf("Delete failed: %v", err)
// }
// }
// }()
// }

// _, err = diff.OutputEq(controlService.OutputPath, experimentalSCService.OutputPath, responseType)
// if err != nil {
// log.Panicf("Failed to compare two outputs: %v", err)
// }

// printDbDiffs(ctx, branchers, experimentalSCNamespace, controlService.Branches, experimentalSCService.Branches, inlineDiff, request.Count)

// run requests half on canary (v2) half on stable (v1)
runCnt += 1
Expand Down
9 changes: 0 additions & 9 deletions bankofanthos_prototype/eval_driver/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ func (s *Service) generateConfig(configPath, listenPort string, prodService Prod
return err
}

fmt.Printf("Successfully generate config file %s\n", configPath)
return nil
}

func (s *Service) start(cmdCh chan *exec.Cmd, upCh chan bool, binPath, configPath, logPath string) {
fmt.Printf("Start running service %s, config file %s\n", s.Runs, configPath)

cmd := exec.Command(binPath)
cmd.Env = append(os.Environ(), "SERVICEWEAVER_CONFIG="+configPath)

Expand Down Expand Up @@ -152,12 +149,10 @@ func (s *Service) stop(cmdCh chan *exec.Cmd, runs int) {
}
i++
if i >= runs {
fmt.Printf("Stopped service %s\n", s.Runs)
return
}
default:
time.Sleep(1 * time.Second)
fmt.Println("Waiting for command")
}
}
}
Expand All @@ -180,8 +175,6 @@ func (s *Service) Run(ctx context.Context) {
}
go s.stop(cmdCh, len(s.ProdServices))
wg.Wait()

fmt.Println("Finished running service")
}

func (s *Service) sendHttpReqs(ctx context.Context, client *http.Client, ports []string) error {
Expand Down Expand Up @@ -220,15 +213,13 @@ func (s *Service) sendRequests(ctx context.Context, upCh chan bool) error {
case <-upCh:
i++
if i == len(s.ConfigPaths) {
fmt.Println("Start sending requests")
err := s.sendHttpReqs(ctx, &client, s.ReqPorts)
if err != nil {
return err
}
return nil
}
default:
println("Waiting for service up")
time.Sleep(1 * time.Second)
}
}
Expand Down
2 changes: 1 addition & 1 deletion bankofanthos_prototype/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const reqLog = "reqlog.json" //req log file
func main() {
var countsList string

flag.StringVar(&countsList, "counts", "6, 9", "Req count per user, must be >= 3, split by,")
flag.StringVar(&countsList, "counts", "5", "Req count per user, must be >= 3, split by,")
flag.Parse()

var counts []int
Expand Down
Loading