Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6356,6 +6356,8 @@ A machine state change event
interface MachineEvent {
id: ID!
kind: String!
machineVersion: MachineVersion!
source: String
timestamp: ISO8601DateTime!
}

Expand All @@ -6382,6 +6384,8 @@ type MachineEventConnection {
type MachineEventDestroy implements MachineEvent {
id: ID!
kind: String!
machineVersion: MachineVersion!
source: String
timestamp: ISO8601DateTime!
}

Expand All @@ -6404,21 +6408,27 @@ type MachineEventExit implements MachineEvent {
exitCode: Int!
id: ID!
kind: String!
machineVersion: MachineVersion!
metadata: JSON!
oomKilled: Boolean!
requestedStop: Boolean!
source: String
timestamp: ISO8601DateTime!
}

type MachineEventGeneric implements MachineEvent {
id: ID!
kind: String!
machineVersion: MachineVersion!
source: String
timestamp: ISO8601DateTime!
}

type MachineEventStart implements MachineEvent {
id: ID!
kind: String!
machineVersion: MachineVersion!
source: String
timestamp: ISO8601DateTime!
}

Expand Down Expand Up @@ -6470,6 +6480,10 @@ type MachineIPEdge {
node: MachineIP
}

type MachineVersion implements Node {
id: ID!
}

"""
Autogenerated input type of MigrateVolume
"""
Expand Down
50 changes: 50 additions & 0 deletions internal/command/machine/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (

"github.com/alecthomas/chroma/quick"
"github.com/spf13/cobra"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/format"
"github.com/superfly/flyctl/internal/logger"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
Expand Down Expand Up @@ -160,10 +163,57 @@ func runMachineStatus(ctx context.Context) (err error) {
exitEvent.ExitCode, exitEvent.OOMKilled, exitEvent.RequestedStop))
}

// This is terrible but will inform the users good enough while I build something
// elegant like the ExitEvent above
if event.Type == "launch" && event.Status == "created" && event.Source == "flyd" {
fields = append(fields, "migrated=true")
}

eventLogs = append(eventLogs, fields)
}
_ = render.Table(io.Out, "Event Logs", eventLogs, "State", "Event", "Source", "Timestamp", "Info")

// Get a historical list of events for this machine
apiClient := flyutil.ClientFromContext(ctx)
var gqlMachine *fly.GqlMachine
gqlMachine, err = apiClient.GetMachineWithEvents(ctx, machine.ID)

if err == nil {
allVersionsEventLogs := [][]string{}
for _, event := range gqlMachine.Events.Nodes {

// Only print older versions events
if machine.InstanceID == event.MachineVersion["id"] {
continue
}

fields := []string{
event.Status,
event.Kind,
event.Source,
event.Timestamp.String(),
}

if event.Body != nil && event.Body["exit_event"] != nil {
exitEvent := event.Body["exit_event"].(map[string]interface{})
fields = append(fields, fmt.Sprintf("exit_code=%d,oom_killed=%t,requested_stop=%t",
int(exitEvent["exit_code"].(float64)), exitEvent["oom_killed"], exitEvent["requested_stop"]))
}

// This is STILL terrible but will inform the users good enough while I build something
// elegant like the ExitEvent above
if event.Kind == "launch" && event.Status == "created" && event.Source == "flyd" {
fields = append(fields, "migrated=true")
}

allVersionsEventLogs = append(allVersionsEventLogs, fields)
}
_ = render.Table(io.Out, "Past Event Logs", allVersionsEventLogs, "State", "Event", "Source", "Timestamp", "Info")
} else {
logger := logger.FromContext(ctx)
logger.Debugf("failed to get historical events for machine %s", machine.ID)
}

if flag.GetBool(ctx, "display-config") {
var prettyConfig []byte
prettyConfig, err = json.MarshalIndent(machine.Config, "", " ")
Expand Down
1 change: 1 addition & 0 deletions internal/flyutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Client interface {
GetLatestImageTag(ctx context.Context, repository string, snapshotId *string) (string, error)
GetLoggedCertificates(ctx context.Context, slug string) ([]fly.LoggedCertificate, error)
GetMachine(ctx context.Context, machineId string) (*fly.GqlMachine, error)
GetMachineWithEvents(ctx context.Context, machineId string) (*fly.GqlMachine, error)
GetNearestRegion(ctx context.Context) (*fly.Region, error)
GetOrganizationBySlug(ctx context.Context, slug string) (*fly.Organization, error)
GetOrganizationByApp(ctx context.Context, appName string) (*fly.Organization, error)
Expand Down