Skip to content

Commit

Permalink
Add version-info to tablet tags in the topo
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
ajm188 committed Oct 9, 2021
1 parent 8d6e89b commit e524e61
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions go/vt/servenv/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ type versionInfo struct {
version string
}

// ToStringMap returns the version info as a map[string]string, allowing version
// info to be used in things like arbitrary string-tag maps (e.g. tablet tags
// in the topo).
func (v *versionInfo) ToStringMap() map[string]string {
return map[string]string{
"build_host": v.buildHost,
"build_user": v.buildUser,
"build_time": v.buildTimePretty,
"build_git_rev": v.buildGitRev,
"build_git_branch": v.buildGitBranch,
"jenkins_build_number": fmt.Sprintf("%d", v.jenkinsBuildNumber),
"go_version": v.goVersion,
"goos": v.goOS,
"goarch": v.goArch,
"version": v.version,
}
}

func (v *versionInfo) Print() {
fmt.Println(v)
}
Expand Down
20 changes: 19 additions & 1 deletion go/vt/vttablet/tabletmanager/tm_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,28 @@ func BuildTabletFromInput(alias *topodatapb.TabletAlias, port, grpcPort int32) (
KeyRange: keyRange,
Type: tabletType,
DbNameOverride: *initDbNameOverride,
Tags: initTags,
Tags: mergeTags(servenv.AppVersion.ToStringMap(), initTags),
}, nil
}

func mergeTags(a, b map[string]string) map[string]string {
maxCap := len(a)
if x := len(b); x > maxCap {
maxCap = x
}

result := make(map[string]string, maxCap)
for k, v := range a {
result[k] = v
}

for k, v := range b {
result[k] = v
}

return result
}

// Start starts the TabletManager.
func (tm *TabletManager) Start(tablet *topodatapb.Tablet, healthCheckInterval time.Duration) error {
tm.DBConfigs.DBName = topoproto.TabletDbName(tablet)
Expand Down

0 comments on commit e524e61

Please sign in to comment.