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

Use the appropriate port when redirecting node-agents to leader #2892

Merged
merged 1 commit into from
Jan 23, 2019
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
3 changes: 2 additions & 1 deletion pkg/clusteragent/clusterchecks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package clusterchecks

import (
"fmt"
"net/http"

"github.com/DataDog/datadog-agent/pkg/clusteragent/clusterchecks/types"
Expand All @@ -28,7 +29,7 @@ func (h *Handler) ShouldHandle() (int, string) {
case leader:
return http.StatusOK, ""
case follower:
return http.StatusFound, h.leaderIP
return http.StatusFound, fmt.Sprintf("%s:%d", h.leaderIP, h.port)
default:
return http.StatusServiceUnavailable, notReadyReason
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/clusteragent/clusterchecks/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
)

func TestShouldHandle(t *testing.T) {
h := &Handler{}
h := &Handler{
port: 5005,
}

// Initial state
code, reason := h.ShouldHandle()
Expand All @@ -33,5 +35,5 @@ func TestShouldHandle(t *testing.T) {
h.leaderIP = "1.2.3.4"
code, reason = h.ShouldHandle()
assert.Equal(t, http.StatusFound, code)
assert.Equal(t, "1.2.3.4", reason)
assert.Equal(t, "1.2.3.4:5005", reason)
}
2 changes: 2 additions & 0 deletions pkg/clusteragent/clusterchecks/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Handler struct {
m sync.RWMutex // Below fields protected by the mutex
state state
leaderIP string
port int
}

// NewHandler returns a populated Handler
Expand All @@ -67,6 +68,7 @@ func NewHandler(ac pluggableAutoConfig) (*Handler, error) {
warmupDuration: config.Datadog.GetDuration("cluster_checks.warmup_duration") * time.Second,
leadershipChan: make(chan state, 1),
dispatcher: newDispatcher(),
port: config.Datadog.GetInt("cluster_agent.cmd_port"),
}

if config.Datadog.GetBool("leader_election") {
Expand Down
5 changes: 3 additions & 2 deletions pkg/clusteragent/clusterchecks/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestHandlerRun(t *testing.T) {
leadershipChan: make(chan state, 1),
dispatcher: newDispatcher(),
leaderStatusCallback: le.get,
port: 5005,
}

//
Expand Down Expand Up @@ -158,7 +159,7 @@ func TestHandlerRun(t *testing.T) {
assertTrueBeforeTimeout(t, 10*time.Millisecond, 250*time.Millisecond, func() bool {
// API redirects to leader
code, reason := h.ShouldHandle()
return code == http.StatusFound && reason == "1.2.3.4"
return code == http.StatusFound && reason == "1.2.3.4:5005"
})

//
Expand Down Expand Up @@ -225,7 +226,7 @@ func TestHandlerRun(t *testing.T) {
assertTrueBeforeTimeout(t, 10*time.Millisecond, 250*time.Millisecond, func() bool {
// API redirects to leader again
code, reason := h.ShouldHandle()
return code == http.StatusFound && reason == "1.2.3.6"
return code == http.StatusFound && reason == "1.2.3.6:5005"
})
assertTrueBeforeTimeout(t, 10*time.Millisecond, 500*time.Millisecond, func() bool {
// RemoveScheduler is called
Expand Down