|
|
|
|
@ -3,21 +3,23 @@ package worker
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"math/rand"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/servers"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/daemon/worker/common"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/daemon/worker/session"
|
|
|
|
|
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/observability/event"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/servers"
|
|
|
|
|
"github.com/hashicorp/go-secure-stdlib/strutil"
|
|
|
|
|
"google.golang.org/grpc/resolver"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type LastStatusInformation struct {
|
|
|
|
|
*pbs.StatusResponse
|
|
|
|
|
StatusTime time.Time
|
|
|
|
|
StatusTime time.Time
|
|
|
|
|
LastCalculatedUpstreams []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *Worker) startStatusTicking(cancelCtx context.Context) {
|
|
|
|
|
@ -199,14 +201,26 @@ func (w *Worker) sendWorkerStatus(cancelCtx context.Context) {
|
|
|
|
|
} else {
|
|
|
|
|
w.updateTags.Store(false)
|
|
|
|
|
// This may be nil if we are in a multiple hop scenario
|
|
|
|
|
var addrs []resolver.Address
|
|
|
|
|
var newUpstreams []string
|
|
|
|
|
if len(result.CalculatedUpstreams) > 0 {
|
|
|
|
|
addrs := make([]resolver.Address, 0, len(result.CalculatedUpstreams))
|
|
|
|
|
addrs = make([]resolver.Address, 0, len(result.CalculatedUpstreams))
|
|
|
|
|
for _, v := range result.CalculatedUpstreams {
|
|
|
|
|
addrs = append(addrs, resolver.Address{Addr: v.Address})
|
|
|
|
|
newUpstreams = append(newUpstreams, v.Address)
|
|
|
|
|
}
|
|
|
|
|
lastStatus := w.lastStatusSuccess.Load().(*LastStatusInformation)
|
|
|
|
|
// Compare upstreams; update resolver if there is a difference, and emit an event with old and new addresses
|
|
|
|
|
if lastStatus != nil && !strutil.EquivalentSlices(lastStatus.LastCalculatedUpstreams, newUpstreams) {
|
|
|
|
|
upstreamsMessage := fmt.Sprintf("Upstreams has changed; old upstreams were: %s, new upstreams are: %s", lastStatus.LastCalculatedUpstreams, newUpstreams)
|
|
|
|
|
event.WriteSysEvent(context.TODO(), op, upstreamsMessage)
|
|
|
|
|
w.Resolver().UpdateState(resolver.State{Addresses: addrs})
|
|
|
|
|
} else if lastStatus == nil {
|
|
|
|
|
w.Resolver().UpdateState(resolver.State{Addresses: addrs})
|
|
|
|
|
event.WriteSysEvent(context.TODO(), op, fmt.Sprintf("Upstreams after first status set to: %s", newUpstreams))
|
|
|
|
|
}
|
|
|
|
|
w.Resolver().UpdateState(resolver.State{Addresses: addrs})
|
|
|
|
|
}
|
|
|
|
|
w.lastStatusSuccess.Store(&LastStatusInformation{StatusResponse: result, StatusTime: time.Now()})
|
|
|
|
|
w.lastStatusSuccess.Store(&LastStatusInformation{StatusResponse: result, StatusTime: time.Now(), LastCalculatedUpstreams: newUpstreams})
|
|
|
|
|
|
|
|
|
|
for _, request := range result.GetJobsRequests() {
|
|
|
|
|
switch request.GetRequestType() {
|
|
|
|
|
|