Skip to content

Commit

Permalink
Revert "Move structs.CheckID to a new top-level package, types."
Browse files Browse the repository at this point in the history
This reverts commit 2bbd52e3b44ff1b60939a8400264d534662d6d51.
  • Loading branch information
sean- committed Jun 7, 2016
1 parent cbb945e commit 63adcbd
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 124 deletions.
39 changes: 20 additions & 19 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/consul/consul/state"
"github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/types"
"github.com/hashicorp/serf/coordinate"
"github.com/hashicorp/serf/serf"
)
Expand Down Expand Up @@ -74,19 +75,19 @@ type Agent struct {
state localState

// checkMonitors maps the check ID to an associated monitor
checkMonitors map[structs.CheckID]*CheckMonitor
checkMonitors map[types.CheckID]*CheckMonitor

// checkHTTPs maps the check ID to an associated HTTP check
checkHTTPs map[structs.CheckID]*CheckHTTP
checkHTTPs map[types.CheckID]*CheckHTTP

// checkTCPs maps the check ID to an associated TCP check
checkTCPs map[structs.CheckID]*CheckTCP
checkTCPs map[types.CheckID]*CheckTCP

// checkTTLs maps the check ID to an associated check TTL
checkTTLs map[structs.CheckID]*CheckTTL
checkTTLs map[types.CheckID]*CheckTTL

// checkDockers maps the check ID to an associated Docker Exec based check
checkDockers map[structs.CheckID]*CheckDocker
checkDockers map[types.CheckID]*CheckDocker

// checkLock protects updates to the check* maps
checkLock sync.Mutex
Expand Down Expand Up @@ -176,11 +177,11 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
config: config,
logger: log.New(logOutput, "", log.LstdFlags),
logOutput: logOutput,
checkMonitors: make(map[structs.CheckID]*CheckMonitor),
checkTTLs: make(map[structs.CheckID]*CheckTTL),
checkHTTPs: make(map[structs.CheckID]*CheckHTTP),
checkTCPs: make(map[structs.CheckID]*CheckTCP),
checkDockers: make(map[structs.CheckID]*CheckDocker),
checkMonitors: make(map[types.CheckID]*CheckMonitor),
checkTTLs: make(map[types.CheckID]*CheckTTL),
checkHTTPs: make(map[types.CheckID]*CheckHTTP),
checkTCPs: make(map[types.CheckID]*CheckTCP),
checkDockers: make(map[types.CheckID]*CheckDocker),
eventCh: make(chan serf.UserEvent, 1024),
eventBuf: make([]*UserEvent, 256),
shutdownCh: make(chan struct{}),
Expand Down Expand Up @@ -724,7 +725,7 @@ func (a *Agent) persistCheck(check *structs.HealthCheck, chkType *CheckType) err
}

// purgeCheck removes a persisted check definition file from the data dir
func (a *Agent) purgeCheck(checkID structs.CheckID) error {
func (a *Agent) purgeCheck(checkID types.CheckID) error {
checkPath := filepath.Join(a.config.DataDir, checksDir, checkIDHash(checkID))
if _, err := os.Stat(checkPath); err == nil {
return os.Remove(checkPath)
Expand Down Expand Up @@ -791,7 +792,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe
}
check := &structs.HealthCheck{
Node: a.config.NodeName,
CheckID: structs.CheckID(checkID),
CheckID: types.CheckID(checkID),
Name: fmt.Sprintf("Service '%s' check", service.Service),
Status: structs.HealthCritical,
Notes: chkType.Notes,
Expand Down Expand Up @@ -998,7 +999,7 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist

// RemoveCheck is used to remove a health check.
// The agent will make a best effort to ensure it is deregistered
func (a *Agent) RemoveCheck(checkID structs.CheckID, persist bool) error {
func (a *Agent) RemoveCheck(checkID types.CheckID, persist bool) error {
// Validate CheckID
if checkID == "" {
return fmt.Errorf("CheckID missing")
Expand Down Expand Up @@ -1041,7 +1042,7 @@ func (a *Agent) RemoveCheck(checkID structs.CheckID, persist bool) error {

// UpdateCheck is used to update the status of a check.
// This can only be used with checks of the TTL type.
func (a *Agent) UpdateCheck(checkID structs.CheckID, status, output string) error {
func (a *Agent) UpdateCheck(checkID types.CheckID, status, output string) error {
a.checkLock.Lock()
defer a.checkLock.Unlock()

Expand Down Expand Up @@ -1129,7 +1130,7 @@ func (a *Agent) loadCheckState(check *structs.HealthCheck) error {
}

// purgeCheckState is used to purge the state of a check from the data dir
func (a *Agent) purgeCheckState(checkID structs.CheckID) error {
func (a *Agent) purgeCheckState(checkID types.CheckID) error {
file := filepath.Join(a.config.DataDir, checkStateDir, checkIDHash(checkID))
err := os.Remove(file)
if os.IsNotExist(err) {
Expand Down Expand Up @@ -1393,22 +1394,22 @@ func (a *Agent) unloadChecks() error {
// snapshotCheckState is used to snapshot the current state of the health
// checks. This is done before we reload our checks, so that we can properly
// restore into the same state.
func (a *Agent) snapshotCheckState() map[structs.CheckID]*structs.HealthCheck {
func (a *Agent) snapshotCheckState() map[types.CheckID]*structs.HealthCheck {
return a.state.Checks()
}

// restoreCheckState is used to reset the health state based on a snapshot.
// This is done after we finish the reload to avoid any unnecessary flaps
// in health state and potential session invalidations.
func (a *Agent) restoreCheckState(snap map[structs.CheckID]*structs.HealthCheck) {
func (a *Agent) restoreCheckState(snap map[types.CheckID]*structs.HealthCheck) {
for id, check := range snap {
a.state.UpdateCheck(id, check.Status, check.Output)
}
}

// serviceMaintCheckID returns the ID of a given service's maintenance check
func serviceMaintCheckID(serviceID string) structs.CheckID {
return structs.CheckID(fmt.Sprintf("%s:%s", serviceMaintCheckPrefix, serviceID))
func serviceMaintCheckID(serviceID string) types.CheckID {
return types.CheckID(fmt.Sprintf("%s:%s", serviceMaintCheckPrefix, serviceID))
}

// EnableServiceMaintenance will register a false health check against the given
Expand Down
11 changes: 6 additions & 5 deletions command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/consul/types"
"github.com/hashicorp/serf/coordinate"
"github.com/hashicorp/serf/serf"
)
Expand Down Expand Up @@ -130,7 +131,7 @@ func (s *HTTPServer) AgentRegisterCheck(resp http.ResponseWriter, req *http.Requ
}

func (s *HTTPServer) AgentDeregisterCheck(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
checkID := structs.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/deregister/"))
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/deregister/"))
if err := s.agent.RemoveCheck(checkID, true); err != nil {
return nil, err
}
Expand All @@ -139,7 +140,7 @@ func (s *HTTPServer) AgentDeregisterCheck(resp http.ResponseWriter, req *http.Re
}

func (s *HTTPServer) AgentCheckPass(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
checkID := structs.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/pass/"))
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/pass/"))
note := req.URL.Query().Get("note")
if err := s.agent.UpdateCheck(checkID, structs.HealthPassing, note); err != nil {
return nil, err
Expand All @@ -149,7 +150,7 @@ func (s *HTTPServer) AgentCheckPass(resp http.ResponseWriter, req *http.Request)
}

func (s *HTTPServer) AgentCheckWarn(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
checkID := structs.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/warn/"))
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/warn/"))
note := req.URL.Query().Get("note")
if err := s.agent.UpdateCheck(checkID, structs.HealthWarning, note); err != nil {
return nil, err
Expand All @@ -159,7 +160,7 @@ func (s *HTTPServer) AgentCheckWarn(resp http.ResponseWriter, req *http.Request)
}

func (s *HTTPServer) AgentCheckFail(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
checkID := structs.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/fail/"))
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/fail/"))
note := req.URL.Query().Get("note")
if err := s.agent.UpdateCheck(checkID, structs.HealthCritical, note); err != nil {
return nil, err
Expand Down Expand Up @@ -212,7 +213,7 @@ func (s *HTTPServer) AgentCheckUpdate(resp http.ResponseWriter, req *http.Reques
update.Output[:CheckBufSize], CheckBufSize, total)
}

checkID := structs.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/update/"))
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/update/"))
if err := s.agent.UpdateCheck(checkID, update.Status, update.Output); err != nil {
return nil, err
}
Expand Down
15 changes: 8 additions & 7 deletions command/agent/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
docker "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/types"
"github.com/hashicorp/go-cleanhttp"
)

Expand Down Expand Up @@ -90,15 +91,15 @@ func (c *CheckType) IsDocker() bool {
// to notify when a check has a status update. The update
// should take care to be idempotent.
type CheckNotifier interface {
UpdateCheck(checkID structs.CheckID, status, output string)
UpdateCheck(checkID types.CheckID, status, output string)
}

// CheckMonitor is used to periodically invoke a script to
// determine the health of a given check. It is compatible with
// nagios plugins and expects the output in the same format.
type CheckMonitor struct {
Notify CheckNotifier
CheckID structs.CheckID
CheckID types.CheckID
Script string
Interval time.Duration
Timeout time.Duration
Expand Down Expand Up @@ -231,7 +232,7 @@ func (c *CheckMonitor) check() {
// automatically set to critical.
type CheckTTL struct {
Notify CheckNotifier
CheckID structs.CheckID
CheckID types.CheckID
TTL time.Duration
Logger *log.Logger

Expand Down Expand Up @@ -322,7 +323,7 @@ type persistedCheck struct {
// expiration timestamp which is used to determine staleness on later
// agent restarts.
type persistedCheckState struct {
CheckID structs.CheckID
CheckID types.CheckID
Output string
Status string
Expires int64
Expand All @@ -336,7 +337,7 @@ type persistedCheckState struct {
// or if the request returns an error
type CheckHTTP struct {
Notify CheckNotifier
CheckID structs.CheckID
CheckID types.CheckID
HTTP string
Interval time.Duration
Timeout time.Duration
Expand Down Expand Up @@ -462,7 +463,7 @@ func (c *CheckHTTP) check() {
// The check is critical if the connection returns an error
type CheckTCP struct {
Notify CheckNotifier
CheckID structs.CheckID
CheckID types.CheckID
TCP string
Interval time.Duration
Timeout time.Duration
Expand Down Expand Up @@ -553,7 +554,7 @@ type DockerClient interface {
// with nagios plugins and expects the output in the same format.
type CheckDocker struct {
Notify CheckNotifier
CheckID structs.CheckID
CheckID types.CheckID
Script string
DockerContainerID string
Shell string
Expand Down
Loading

0 comments on commit 63adcbd

Please sign in to comment.