Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #293 from DataDog/lee.avital/dont_hardcode_expvar_…
Browse files Browse the repository at this point in the history
…port

Make process_config.expvar configurable
  • Loading branch information
leeavital authored and sunhay committed Apr 22, 2019
1 parent 9496f1d commit bff06e0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/main_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func runAgent(exit chan bool) {

if opts.info {
// using the debug port to get info to work
url := "http://localhost:6062/debug/vars"
url := fmt.Sprintf("http://localhost:%d/debug/vars", cfg.ProcessExpVarPort)
if err := Info(os.Stdout, cfg, url); err != nil {
os.Exit(1)
}
Expand All @@ -155,7 +155,7 @@ func runAgent(exit chan bool) {

// Run a profile server.
go func() {
http.ListenAndServe("localhost:6062", nil)
http.ListenAndServe(fmt.Sprintf("localhost:%d", cfg.ProcessExpVarPort), nil)
}()

cl, err := NewCollector(cfg)
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type AgentConfig struct {
DDAgentBin string
StatsdHost string
StatsdPort int
ProcessExpVarPort int

// Network collection configuration
EnableNetworkTracing bool
Expand Down Expand Up @@ -154,6 +155,7 @@ func NewDefaultAgentConfig() *AgentConfig {
AllowRealTime: true,
HostName: "",
Transport: NewDefaultTransport(),
ProcessExpVarPort: 6062,

// Statsd for internal instrumentation
StatsdHost: "127.0.0.1",
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func TestDefaultConfig(t *testing.T) {
assert.Equal(os.Getenv("HOST_SYS"), "")
os.Setenv("DOCKER_DD_AGENT", "no")
assert.Equal(containerChecks, agentConfig.EnabledChecks)
assert.Equal(6062, agentConfig.ProcessExpVarPort)

os.Unsetenv("DOCKER_DD_AGENT")
}
Expand Down Expand Up @@ -263,6 +264,7 @@ func TestAgentConfigYamlAndNetworkConfig(t *testing.T) {
assert.Equal(100, agentConfig.Windows.ArgsRefreshInterval)
assert.Equal(false, agentConfig.Windows.AddNewArgs)
assert.Equal(false, agentConfig.Scrubber.Enabled)
assert.Equal(5065, agentConfig.ProcessExpVarPort)

agentConfig, err = NewAgentConfig(
"test",
Expand Down
3 changes: 2 additions & 1 deletion config/testdata/TestDDAgentConfigYamlAndNetworkConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ process_config:
windows:
args_refresh_interval: 100
add_new_args: false
scrub_args: false
scrub_args: false
expvar_port: 5065
9 changes: 9 additions & 0 deletions config/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"github.com/pkg/errors"
"net/url"
"regexp"
"strings"
Expand Down Expand Up @@ -137,6 +138,14 @@ func (a *AgentConfig) loadProcessYamlConfig(path string) error {
}
}

if k := key(ns, "expvar_port"); config.Datadog.IsSet(k) {
port := config.Datadog.GetInt(k)
if port <= 0 {
return errors.Errorf("invalid %s -- %d", k, port)
}
a.ProcessExpVarPort = port
}

// Enable/Disable the DataScrubber to obfuscate process args
if scrubArgsKey := key(ns, "scrub_args"); config.Datadog.IsSet(scrubArgsKey) {
a.Scrubber.Enabled = config.Datadog.GetBool(scrubArgsKey)
Expand Down

0 comments on commit bff06e0

Please sign in to comment.