Skip to content

Commit

Permalink
Set version to unknown if not set (influxdata#4521)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and rgitzel committed Oct 17, 2018
1 parent b3ec5aa commit a880f0b
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,11 @@ var fService = flag.String("service", "",
var fRunAsConsole = flag.Bool("console", false, "run as console application (windows only)")

var (
nextVersion = "1.8.0"
version string
commit string
branch string
version string
commit string
branch string
)

func init() {
// If commit or branch are not set, make that clear.
if commit == "" {
commit = "unknown"
}
if branch == "" {
branch = "unknown"
}
}

var stop chan struct{}

func reloadLoop(
Expand Down Expand Up @@ -165,7 +154,7 @@ func reloadLoop(
}
}()

log.Printf("I! Starting Telegraf %s\n", displayVersion())
log.Printf("I! Starting Telegraf %s\n", version)
log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
log.Printf("I! Loaded aggregators: %s", strings.Join(c.AggregatorNames(), " "))
log.Printf("I! Loaded processors: %s", strings.Join(c.ProcessorNames(), " "))
Expand Down Expand Up @@ -225,11 +214,27 @@ func (p *program) Stop(s service.Service) error {
return nil
}

func displayVersion() string {
if version == "" {
return fmt.Sprintf("v%s~%s", nextVersion, commit)
func formatFullVersion() string {
var parts = []string{"Telegraf"}

if version != "" {
parts = append(parts, version)
} else {
parts = append(parts, "unknown")
}
return "v" + version

if branch != "" || commit != "" {
if branch == "" {
branch = "unknown"
}
if commit == "" {
commit = "unknown"
}
git := fmt.Sprintf("(git: %s %s)", branch, commit)
parts = append(parts, git)
}

return strings.Join(parts, " ")
}

func main() {
Expand Down Expand Up @@ -273,7 +278,7 @@ func main() {
if len(args) > 0 {
switch args[0] {
case "version":
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
fmt.Println(formatFullVersion())
return
case "config":
config.PrintSampleConfig(
Expand Down Expand Up @@ -301,7 +306,7 @@ func main() {
}
return
case *fVersion:
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
fmt.Println(formatFullVersion())
return
case *fSampleConfig:
config.PrintSampleConfig(
Expand Down

0 comments on commit a880f0b

Please sign in to comment.