Add internal function for telegraf version (#4828)
This commit is contained in:
parent
709eadffc4
commit
7bb219222a
|
@ -326,6 +326,16 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shortVersion := version
|
||||||
|
if shortVersion == "" {
|
||||||
|
shortVersion = "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure version
|
||||||
|
if err := internal.SetVersion(shortVersion); err != nil {
|
||||||
|
log.Println("Telegraf version already configured to: " + internal.Version())
|
||||||
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" && !(*fRunAsConsole) {
|
if runtime.GOOS == "windows" && !(*fRunAsConsole) {
|
||||||
svcConfig := &service.Config{
|
svcConfig := &service.Config{
|
||||||
Name: *fServiceName,
|
Name: *fServiceName,
|
||||||
|
|
|
@ -24,13 +24,32 @@ var (
|
||||||
TimeoutErr = errors.New("Command timed out.")
|
TimeoutErr = errors.New("Command timed out.")
|
||||||
|
|
||||||
NotImplementedError = errors.New("not implemented yet")
|
NotImplementedError = errors.New("not implemented yet")
|
||||||
|
|
||||||
|
VersionAlreadySetError = errors.New("version has already been set")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set via the main module
|
||||||
|
var version string
|
||||||
|
|
||||||
// Duration just wraps time.Duration
|
// Duration just wraps time.Duration
|
||||||
type Duration struct {
|
type Duration struct {
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetVersion sets the telegraf agent version
|
||||||
|
func SetVersion(v string) error {
|
||||||
|
if version != "" {
|
||||||
|
return VersionAlreadySetError
|
||||||
|
}
|
||||||
|
version = v
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns the telegraf agent version
|
||||||
|
func Version() string {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalTOML parses the duration from the TOML config file
|
// UnmarshalTOML parses the duration from the TOML config file
|
||||||
func (d *Duration) UnmarshalTOML(b []byte) error {
|
func (d *Duration) UnmarshalTOML(b []byte) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -182,3 +182,15 @@ func TestCompressWithGzip(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, testData, string(output))
|
assert.Equal(t, testData, string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVersionAlreadySet(t *testing.T) {
|
||||||
|
err := SetVersion("foo")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
err = SetVersion("bar")
|
||||||
|
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
assert.IsType(t, VersionAlreadySetError, err)
|
||||||
|
|
||||||
|
assert.Equal(t, "foo", Version())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue