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

Set version to unknown if not set #4521

Merged
merged 1 commit into from
Aug 12, 2018
Merged
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
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