Skip to content

Commit

Permalink
fix(upgrade): look for version string in logs bottom up (#8926)
Browse files Browse the repository at this point in the history
For in place upgrade, the container remains the same and the logs have
the version string twice, one for the old container and one for the new
container. We want the version string in the logs for the new container.
Hence, we look for the string in the logs bottom up by using
strings.LastIndex instead of strings.Index.
  • Loading branch information
mangalaman93 authored and jbhamra1 committed Aug 17, 2023
1 parent 8cae87a commit 7fc0d93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dgraphtest/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -137,7 +138,7 @@ func getHash(ref string) (string, error) {
if out, err := cmd.CombinedOutput(); err != nil {
return "", errors.Wrapf(err, "error while running rev-parse on [%v]\noutput:%v", ref, string(out))
} else {
return string(out), nil
return strings.TrimSpace(string(out)), nil
}
}

Expand Down
8 changes: 6 additions & 2 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,11 @@ func (c *LocalCluster) checkDgraphVersion(containerID string) error {
if err != nil {
return errors.Wrapf(err, "error during checkDgraphVersion for container [%v]", containerID)
}
index := strings.Index(contLogs, "Commit SHA-1 : ")

// During in-place upgrade, container remains same but logs have version string twice
// once for old version, once for new. Want new version string. Look bottom-up using
// LastIndex to get latest version's string.
index := strings.LastIndex(contLogs, "Commit SHA-1 : ")
running := strings.Fields(contLogs[index : index+70])[3] // 70 is arbitrary
chash, err := getHash(c.GetVersion())
if err != nil {
Expand All @@ -807,7 +811,7 @@ func (c *LocalCluster) checkDgraphVersion(containerID string) error {
return errors.Wrapf(err, "error while getting hash for %v", running)
}
if chash != rhash {
return errors.Errorf("found different dgraph version than expected [%v]", c.GetVersion())
return errors.Errorf("found different dgraph version [%v] than expected [%v]", rhash, chash)
}
return nil
}
Expand Down

0 comments on commit 7fc0d93

Please sign in to comment.