Skip to content

Commit

Permalink
use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
benwaffle committed Jun 1, 2023
1 parent 30f0aeb commit 4a27978
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
22 changes: 15 additions & 7 deletions api/machine_types.go
Expand Up @@ -125,11 +125,11 @@ func (m *Machine) HealthCheckStatus() *HealthCheckStatus {
res.Total = len(m.Checks)
for _, check := range m.Checks {
switch check.Status {
case "passing":
case Passing:
res.Passing += 1
case "warning":
case Warning:
res.Warn += 1
case "critical":
case Critical:
res.Critical += 1
}
}
Expand Down Expand Up @@ -351,11 +351,19 @@ type MachineHTTPHeader struct {
Values []string `json:"values,omitempty"`
}

type ConsulCheckStatus string

const (
Critical ConsulCheckStatus = "critical"
Warning ConsulCheckStatus = "warning"
Passing ConsulCheckStatus = "passing"
)

type MachineCheckStatus struct {
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"` // "critical", "warning", or "passing"
Output string `json:"output,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Name string `json:"name,omitempty"`
Status ConsulCheckStatus `json:"status,omitempty"`
Output string `json:"output,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

type MachinePort struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/checks/list.go
Expand Up @@ -73,7 +73,7 @@ func runMachinesAppCheckList(ctx context.Context, app *api.AppCompact) error {
if nameFilter != "" && nameFilter != check.Name {
continue
}
table.Append([]string{check.Name, check.Status, machine.ID, format.RelativeTime(*check.UpdatedAt), check.Output})
table.Append([]string{check.Name, string(check.Status), machine.ID, format.RelativeTime(*check.UpdatedAt), check.Output})
}
}
table.Render()
Expand Down
2 changes: 1 addition & 1 deletion internal/command/image/update_machines.go
Expand Up @@ -231,7 +231,7 @@ func machineRole(machine *api.Machine) (role string) {

for _, check := range machine.Checks {
if check.Name == "role" {
if check.Status == "passing" {
if check.Status == api.Passing {
role = check.Output
} else {
role = "error"
Expand Down
2 changes: 1 addition & 1 deletion internal/command/postgres/postgres.go
Expand Up @@ -206,7 +206,7 @@ func machineRole(machine *api.Machine) (role string) {

for _, check := range machine.Checks {
if check.Name == "role" {
if check.Status == "passing" {
if check.Status == api.Passing {
role = check.Output
} else {
role = "error"
Expand Down
2 changes: 1 addition & 1 deletion internal/command/ssh/console.go
Expand Up @@ -246,7 +246,7 @@ func addrForMachines(ctx context.Context, app *api.AppCompact, console bool) (ad
role := ""
for _, check := range machine.Checks {
if check.Name == "role" {
if check.Status == "passing" {
if check.Status == api.Passing {
role = check.Output
} else {
role = "error"
Expand Down
2 changes: 1 addition & 1 deletion internal/command/status/machines.go
Expand Up @@ -323,7 +323,7 @@ func renderPGStatus(ctx context.Context, app *api.AppCompact, machines []*api.Ma
role := "unknown"
for _, check := range machine.Checks {
if check.Name == "role" {
if check.Status == "passing" {
if check.Status == api.Passing {
role = check.Output
} else {
role = "error"
Expand Down
6 changes: 3 additions & 3 deletions internal/render/checks.go
Expand Up @@ -38,7 +38,7 @@ func MachineHealthChecksSummary(machines ...*api.Machine) string {

func passingChecks(checks []*api.MachineCheckStatus) (n int) {
for _, check := range checks {
if check.Status == "passing" {
if check.Status == api.Passing {
n++
}
}
Expand All @@ -48,7 +48,7 @@ func passingChecks(checks []*api.MachineCheckStatus) (n int) {

func warnChecks(checks []*api.MachineCheckStatus) (n int) {
for _, check := range checks {
if check.Status == "warning" {
if check.Status == api.Warning {
n++
}
}
Expand All @@ -58,7 +58,7 @@ func warnChecks(checks []*api.MachineCheckStatus) (n int) {

func critChecks(checks []*api.MachineCheckStatus) (n int) {
for _, check := range checks {
if check.Status == "critical" {
if check.Status == api.Critical {
n++
}
}
Expand Down

0 comments on commit 4a27978

Please sign in to comment.