traefik/vendor/github.com/gambol99/go-marathon/health.go

130 lines
4.3 KiB
Go
Raw Normal View History

2017-02-07 21:33:23 +00:00
/*
2017-12-19 15:00:09 +00:00
Copyright 2014 The go-marathon Authors All rights reserved.
2017-02-07 21:33:23 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package marathon
// HealthCheck is the definition for an application health check
type HealthCheck struct {
Command *Command `json:"command,omitempty"`
PortIndex *int `json:"portIndex,omitempty"`
Port *int `json:"port,omitempty"`
Path *string `json:"path,omitempty"`
MaxConsecutiveFailures *int `json:"maxConsecutiveFailures,omitempty"`
Protocol string `json:"protocol,omitempty"`
GracePeriodSeconds int `json:"gracePeriodSeconds,omitempty"`
IntervalSeconds int `json:"intervalSeconds,omitempty"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
IgnoreHTTP1xx *bool `json:"ignoreHttp1xx,omitempty"`
2017-02-07 21:33:23 +00:00
}
2018-07-03 21:42:03 +00:00
// HTTPHealthCheck describes an HTTP based health check
type HTTPHealthCheck struct {
Endpoint string `json:"endpoint,omitempty"`
Path string `json:"path,omitempty"`
Scheme string `json:"scheme,omitempty"`
}
// TCPHealthCheck describes a TCP based health check
type TCPHealthCheck struct {
Endpoint string `json:"endpoint,omitempty"`
}
// CommandHealthCheck describes a shell-based health check
type CommandHealthCheck struct {
Command PodCommand `json:"command,omitempty"`
}
// PodHealthCheck describes how to determine a pod's health
type PodHealthCheck struct {
HTTP *HTTPHealthCheck `json:"http,omitempty"`
TCP *TCPHealthCheck `json:"tcp,omitempty"`
Exec *CommandHealthCheck `json:"exec,omitempty"`
GracePeriodSeconds *int `json:"gracePeriodSeconds,omitempty"`
IntervalSeconds *int `json:"intervalSeconds,omitempty"`
MaxConsecutiveFailures *int `json:"maxConsecutiveFailures,omitempty"`
TimeoutSeconds *int `json:"timeoutSeconds,omitempty"`
DelaySeconds *int `json:"delaySeconds,omitempty"`
}
2017-02-07 21:33:23 +00:00
// SetCommand sets the given command on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetCommand(c Command) *HealthCheck {
2017-02-07 21:33:23 +00:00
h.Command = &c
return h
}
// SetPortIndex sets the given port index on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetPortIndex(i int) *HealthCheck {
2017-02-07 21:33:23 +00:00
h.PortIndex = &i
return h
}
// SetPort sets the given port on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetPort(i int) *HealthCheck {
2017-02-07 21:33:23 +00:00
h.Port = &i
return h
}
// SetPath sets the given path on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetPath(p string) *HealthCheck {
2017-02-07 21:33:23 +00:00
h.Path = &p
return h
}
// SetMaxConsecutiveFailures sets the maximum consecutive failures on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetMaxConsecutiveFailures(i int) *HealthCheck {
2017-02-07 21:33:23 +00:00
h.MaxConsecutiveFailures = &i
return h
}
// SetIgnoreHTTP1xx sets ignore http 1xx on the health check.
2017-12-19 15:00:09 +00:00
func (h *HealthCheck) SetIgnoreHTTP1xx(ignore bool) *HealthCheck {
h.IgnoreHTTP1xx = &ignore
return h
}
2017-02-07 21:33:23 +00:00
// NewDefaultHealthCheck creates a default application health check
func NewDefaultHealthCheck() *HealthCheck {
portIndex := 0
path := ""
maxConsecutiveFailures := 3
return &HealthCheck{
Protocol: "HTTP",
Path: &path,
PortIndex: &portIndex,
MaxConsecutiveFailures: &maxConsecutiveFailures,
GracePeriodSeconds: 30,
IntervalSeconds: 10,
TimeoutSeconds: 5,
}
}
// HealthCheckResult is the health check result
type HealthCheckResult struct {
Alive bool `json:"alive"`
ConsecutiveFailures int `json:"consecutiveFailures"`
FirstSuccess string `json:"firstSuccess"`
LastFailure string `json:"lastFailure"`
LastFailureCause string `json:"lastFailureCause"`
LastSuccess string `json:"lastSuccess"`
TaskID string `json:"taskId"`
}
// Command is the command health check type
type Command struct {
Value string `json:"value"`
}