Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

config: enable to set "MaxTPS" from environment variable #519

Merged
merged 4 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions config/merge_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
envLogLevel = "DD_LOG_LEVEL" // logging level
envAnalyzedSpans = "DD_APM_ANALYZED_SPANS" // spans to analyze for transactions
envConnectionLimit = "DD_CONNECTION_LIMIT" // (deprecated) limit of unique connections
envMaxTPS = "DD_MAX_TPS" // maximum limit to the total number of traces per second to sample (MaxTPS)
)

// loadEnv applies overrides from environment variables to the trace agent configuration
Expand Down Expand Up @@ -122,6 +123,16 @@ func (c *AgentConfig) loadEnv() {
}
}
}

if v := os.Getenv(envMaxTPS); v != "" {
maxTPS, err := strconv.ParseFloat(v, 64)
if err != nil {
log.Errorf("Failed to parse %s: it should be a float number", envMaxTPS)
} else {
c.MaxTPS = maxTPS
}
}

}

func parseNameAndRate(token string) (string, float64, error) {
Expand Down
22 changes: 22 additions & 0 deletions config/merge_env_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -45,3 +46,24 @@ func TestAnalyzedSpansEnvConfigParsing(t *testing.T) {
assert.NotNil(err)
})
}

func TestLoadEnvMaxTPS(t *testing.T) {
assert := assert.New(t)

t.Run("default", func(t *testing.T) {
ac := New()
ac.loadEnv()
assert.EqualValues(10.0, ac.MaxTPS)
})

t.Run("env", func(t *testing.T) {
if err := os.Setenv("DD_MAX_TPS", "123.4"); err != nil {
t.Fatal(err)
}
dragon3 marked this conversation as resolved.
Show resolved Hide resolved
defer os.Unsetenv("DD_MAX_TPS")

ac := New()
ac.loadEnv()
assert.EqualValues(123.4, ac.MaxTPS)
})
}