Skip to content

Commit

Permalink
agent: only send service with check sync if it is out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanuber committed Jan 14, 2015
1 parent a0f1a67 commit ce77243
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions command/agent/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ func (l *localState) syncService(id string) error {
return err
}

// syncChecks is used to sync checks to the server
// syncChecks is used to sync checks to the server. If a check is associated
// with a service and the service is out of sync, it will piggyback with the
// sync so that it is updated as part of the same transaction.
func (l *localState) syncChecks(checkIDs []string) error {
checkMap := make(map[string]structs.HealthChecks)

Expand All @@ -479,17 +481,21 @@ func (l *localState) syncChecks(checkIDs []string) error {
}

for serviceID, checks := range checkMap {
service := l.services[serviceID]

// Create the sync request
req := structs.RegisterRequest{
Datacenter: l.config.Datacenter,
Node: l.config.NodeName,
Address: l.config.AdvertiseAddr,
Service: service,
WriteRequest: structs.WriteRequest{Token: l.config.ACLToken},
}

// Attach the service if it should also be synced
if service, ok := l.services[serviceID]; ok {
if status, ok := l.serviceStatus[serviceID]; ok && !status.inSync {
req.Service = service
}
}

// Send single Check element for backwards compat with 0.4.x
if len(checks) == 1 {
req.Check = checks[0]
Expand All @@ -513,17 +519,14 @@ func (l *localState) syncChecks(checkIDs []string) error {
}

// Mark the checks and services as synced
if req.Service != nil {
l.serviceStatus[serviceID] = syncStatus{inSync: true}
l.logger.Printf("[INFO] agent: Synced service '%s'", serviceID)
}
for _, check := range checks {
l.checkStatus[check.CheckID] = syncStatus{inSync: true}
l.logger.Printf("[INFO] agent: Synced check '%s'", check.CheckID)
}
if service != nil {
if status, ok := l.serviceStatus[serviceID]; ok && status.inSync {
continue
}
l.serviceStatus[serviceID] = syncStatus{inSync: true}
l.logger.Printf("[INFO] agent: Synced service '%s'", serviceID)
}
}

return nil
Expand Down

0 comments on commit ce77243

Please sign in to comment.