diff --git a/README.md b/README.md index 7c348e73..f4da3ca5 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ JAEGER_REPORTER_MAX_QUEUE_SIZE | The reporter's maximum queue size JAEGER_REPORTER_FLUSH_INTERVAL | The reporter's flush interval, with units, e.g. "500ms" or "2s" ([valid units][timeunits]) JAEGER_SAMPLER_TYPE | The sampler type JAEGER_SAMPLER_PARAM | The sampler parameter (number) -JAEGER_SAMPLER_MANAGER_HOST_PORT | The HTTP endpoint when using the remote sampler, i.e. http://jaeger-agent:5778/sampling +JAEGER_SAMPLER_MANAGER_HOST_PORT | (Deprecated) The HTTP endpoint when using the remote sampler +JAEGER_SAMPLING_ENDPOINT | The url for the remote sampling conf when using sampler type remote. Default is http://127.0.0.1:5778/sampling JAEGER_SAMPLER_MAX_OPERATIONS | The maximum number of operations that the sampler will keep track of JAEGER_SAMPLER_REFRESH_INTERVAL | How often the remotely controlled sampler will poll jaeger-agent for the appropriate sampling strategy, with units, e.g. "1m" or "30s" ([valid units][timeunits]) JAEGER_TAGS | A comma separated list of `name = value` tracer level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:default}`, where the `:default` is optional, and identifies a value to be used if the environment variable cannot be found diff --git a/config/config.go b/config/config.go index 44e93533..ec36c6bc 100644 --- a/config/config.go +++ b/config/config.go @@ -72,12 +72,13 @@ type SamplerConfig struct { // Can be set by exporting an environment variable named JAEGER_SAMPLER_PARAM Param float64 `yaml:"param"` - // SamplingServerURL is the address of jaeger-agent's HTTP sampling server - // Can be set by exporting an environment variable named JAEGER_SAMPLER_MANAGER_HOST_PORT + // SamplingServerURL is the URL of sampling manager that can provide + // sampling strategy to this service. + // Can be set by exporting an environment variable named JAEGER_SAMPLING_ENDPOINT SamplingServerURL string `yaml:"samplingServerURL"` // SamplingRefreshInterval controls how often the remotely controlled sampler will poll - // jaeger-agent for the appropriate sampling strategy. + // sampling manager for the appropriate sampling strategy. // Can be set by exporting an environment variable named JAEGER_SAMPLER_REFRESH_INTERVAL SamplingRefreshInterval time.Duration `yaml:"samplingRefreshInterval"` diff --git a/config/config_env.go b/config/config_env.go index a729bd8f..66d63408 100644 --- a/config/config_env.go +++ b/config/config_env.go @@ -36,7 +36,8 @@ const ( envTags = "JAEGER_TAGS" envSamplerType = "JAEGER_SAMPLER_TYPE" envSamplerParam = "JAEGER_SAMPLER_PARAM" - envSamplerManagerHostPort = "JAEGER_SAMPLER_MANAGER_HOST_PORT" + envSamplerManagerHostPort = "JAEGER_SAMPLER_MANAGER_HOST_PORT" // Deprecated by envSamplingEndpoint + envSamplingEndpoint = "JAEGER_SAMPLING_ENDPOINT" envSamplerMaxOperations = "JAEGER_SAMPLER_MAX_OPERATIONS" envSamplerRefreshInterval = "JAEGER_SAMPLER_REFRESH_INTERVAL" envReporterMaxQueueSize = "JAEGER_REPORTER_MAX_QUEUE_SIZE" @@ -118,7 +119,9 @@ func (sc *SamplerConfig) samplerConfigFromEnv() (*SamplerConfig, error) { } } - if e := os.Getenv(envSamplerManagerHostPort); e != "" { + if e := os.Getenv(envSamplingEndpoint); e != "" { + sc.SamplingServerURL = e + } else if e := os.Getenv(envSamplerManagerHostPort); e != "" { sc.SamplingServerURL = e } else if e := os.Getenv(envAgentHost); e != "" { // Fallback if we know the agent host - try the sampling endpoint there diff --git a/config/config_test.go b/config/config_test.go index d95f6b8b..f5d9e4c4 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -147,7 +147,7 @@ func TestSamplerConfig(t *testing.T) { // prepare setEnv(t, envSamplerType, "const") setEnv(t, envSamplerParam, "1") - setEnv(t, envSamplerManagerHostPort, "http://themaster") + setEnv(t, envSamplingEndpoint, "http://themaster:5778/sampling") setEnv(t, envSamplerMaxOperations, "10") setEnv(t, envSamplerRefreshInterval, "1m1s") // 61 seconds @@ -167,14 +167,14 @@ func TestSamplerConfig(t *testing.T) { // verify assert.Equal(t, "const", cfg.Type) assert.Equal(t, float64(1), cfg.Param) - assert.Equal(t, "http://themaster", cfg.SamplingServerURL) + assert.Equal(t, "http://themaster:5778/sampling", cfg.SamplingServerURL) assert.Equal(t, 10, cfg.MaxOperations) assert.Equal(t, 61000000000, int(cfg.SamplingRefreshInterval)) // cleanup unsetEnv(t, envSamplerType) unsetEnv(t, envSamplerParam) - unsetEnv(t, envSamplerManagerHostPort) + unsetEnv(t, envSamplingEndpoint) unsetEnv(t, envSamplerMaxOperations) unsetEnv(t, envSamplerRefreshInterval) } @@ -301,9 +301,9 @@ func TestNoServiceNameFromEnv(t *testing.T) { func TestSamplerConfigFromEnv(t *testing.T) { // prepare - setEnv(t, envSamplerType, "const") + setEnv(t, envSamplerType, "remote") setEnv(t, envSamplerParam, "1") - setEnv(t, envSamplerManagerHostPort, "http://themaster") + setEnv(t, envSamplingEndpoint, "http://themaster:5778/sampling") setEnv(t, envSamplerMaxOperations, "10") setEnv(t, envSamplerRefreshInterval, "1m1s") // 61 seconds @@ -312,20 +312,35 @@ func TestSamplerConfigFromEnv(t *testing.T) { assert.NoError(t, err) // verify - assert.Equal(t, "const", cfg.Sampler.Type) + assert.Equal(t, "remote", cfg.Sampler.Type) assert.Equal(t, float64(1), cfg.Sampler.Param) - assert.Equal(t, "http://themaster", cfg.Sampler.SamplingServerURL) + assert.Equal(t, "http://themaster:5778/sampling", cfg.Sampler.SamplingServerURL) assert.Equal(t, 10, cfg.Sampler.MaxOperations) assert.Equal(t, 61000000000, int(cfg.Sampler.SamplingRefreshInterval)) // cleanup unsetEnv(t, envSamplerType) unsetEnv(t, envSamplerParam) - unsetEnv(t, envSamplerManagerHostPort) + unsetEnv(t, envSamplingEndpoint) unsetEnv(t, envSamplerMaxOperations) unsetEnv(t, envSamplerRefreshInterval) } +func TestDeprecatedSamplerConfigFromEnv(t *testing.T) { + // prepare + setEnv(t, envSamplerManagerHostPort, "http://themaster") + + // test + cfg, err := FromEnv() + assert.NoError(t, err) + + // verify + assert.Equal(t, "http://themaster", cfg.Sampler.SamplingServerURL) + + // cleanup + unsetEnv(t, envSamplerManagerHostPort) +} + func TestSamplerConfigOnAgentFromEnv(t *testing.T) { // prepare setEnv(t, envAgentHost, "theagent") diff --git a/constants.go b/constants.go index 60e0d44a..e08bd5b2 100644 --- a/constants.go +++ b/constants.go @@ -102,5 +102,5 @@ const ( var ( // DefaultSamplingServerURL is the default url to fetch sampling config from, via http - DefaultSamplingServerURL = fmt.Sprintf("http://localhost:%d/sampling", DefaultSamplingServerPort) + DefaultSamplingServerURL = fmt.Sprintf("http://127.0.0.1:%d/sampling", DefaultSamplingServerPort) )