-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ELASTIC_APM_SERVER_TIMEOUT config
Defaults to 30s, but can be overridden. If set to a non-positive value, timeout is disabled.
- Loading branch information
Showing
8 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package apmconfig | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// ParseDuration parses value as a duration, appending defaultSuffix if value | ||
// does not have one. | ||
func ParseDuration(value, defaultSuffix string) (time.Duration, error) { | ||
d, err := time.ParseDuration(value) | ||
if err != nil && defaultSuffix != "" { | ||
// We allow the value to have no suffix, in which case we append | ||
// defaultSuffix ("s" for flush interval) for compatibility with | ||
// configuration for other Elastic APM agents. | ||
var err2 error | ||
d, err2 = time.ParseDuration(value + defaultSuffix) | ||
if err2 == nil { | ||
err = nil | ||
} | ||
} | ||
if err != nil { | ||
return 0, err | ||
} | ||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package apmconfig | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// ParseDurationEnv gets the value of the environment variable envKey | ||
// and, if set, parses it as a duration. If the value has no suffix, | ||
// defaultSuffix is appended. If the environment variable is unset, | ||
// defaultDuration is returned. | ||
func ParseDurationEnv(envKey, defaultSuffix string, defaultDuration time.Duration) (time.Duration, error) { | ||
value := os.Getenv(envKey) | ||
if value == "" { | ||
return defaultDuration, nil | ||
} | ||
d, err := ParseDuration(value, defaultSuffix) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "failed to parse %s", envKey) | ||
} | ||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package apmconfig_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/apm-agent-go/internal/apmconfig" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseDurationEnv(t *testing.T) { | ||
const envKey = "ELASTIC_APM_TEST_DURATION" | ||
os.Setenv(envKey, "") | ||
|
||
d, err := apmconfig.ParseDurationEnv(envKey, "s", 42*time.Second) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 42*time.Second, d) | ||
|
||
os.Setenv(envKey, "5") | ||
d, err = apmconfig.ParseDurationEnv(envKey, "s", 42*time.Second) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 5*time.Second, d) | ||
|
||
os.Setenv(envKey, "5ms") | ||
d, err = apmconfig.ParseDurationEnv(envKey, "s", 42*time.Second) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 5*time.Millisecond, d) | ||
|
||
os.Setenv(envKey, "5") | ||
_, err = apmconfig.ParseDurationEnv(envKey, "", 42*time.Second) | ||
assert.EqualError(t, err, "failed to parse ELASTIC_APM_TEST_DURATION: time: missing unit in duration 5") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters