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

Commit

Permalink
config: enable setting "MaxTPS" from environment variable (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon3 authored and gbbr committed Nov 7, 2018
1 parent d7dfcf1 commit 9738c9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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)
}
defer os.Unsetenv("DD_MAX_TPS")

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

0 comments on commit 9738c9e

Please sign in to comment.