Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer/option: fixing the struct for info endpoint response data #1803

Closed
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
6 changes: 4 additions & 2 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,18 @@ func (c *config) loadAgentFeatures() {
type infoResponse struct {
Endpoints []string `json:"endpoints"`
ClientDropP0s bool `json:"client_drop_p0s"`
StatsdPort int `json:"statsd_port"`
FeatureFlags []string `json:"feature_flags"`
Config struct {
StatsdPort int `json:"statsd_port"`
} `json:"config"`
}
var info infoResponse
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
log.Error("Decoding features: %v", err)
return
}
c.agent.DropP0s = info.ClientDropP0s
c.agent.StatsdPort = info.StatsdPort
c.agent.StatsdPort = info.Config.StatsdPort
for _, endpoint := range info.Endpoints {
switch endpoint {
case "/v0.6/stats":
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestAutoDetectStatsd(t *testing.T) {
t.Run("agent", func(t *testing.T) {
t.Run("default", func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte(`{"statsd_port":0}`))
w.Write([]byte(`{"endpoints": [], "config": {"statsd_port":0}}`))
}))
defer srv.Close()
cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")))
Expand All @@ -155,7 +155,7 @@ func TestAutoDetectStatsd(t *testing.T) {

t.Run("port", func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte(`{"statsd_port":8999}`))
w.Write([]byte(`{"endpoints": [], "config": {"statsd_port":8999}}`))
}))
defer srv.Close()
cfg := newConfig(WithAgentAddr(strings.TrimPrefix(srv.URL, "http://")))
Expand Down