Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display previous machines versions events #3645

Closed
wants to merge 1 commit into from
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 @@ -10,7 +10,7 @@
"github.com/superfly/graphql"
)

var _ Client = (*fly.Client)(nil)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest-m)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test (macos-latest-xl)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test (windows-latest-l)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents) (typecheck)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)) (typecheck)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)) (typecheck)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)) (typecheck)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)) (typecheck)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test / test (ubuntu-latest-m, ., test)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test / test (macos-latest-xl, ., test)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test / test (windows-latest-l, ., test)

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

Check failure on line 13 in internal/flyutil/client.go

View workflow job for this annotation

GitHub Actions / test_build

cannot use (*fly.Client)(nil) (value of type *fly.Client) as Client value in variable declaration: *fly.Client does not implement Client (missing method GetMachineWithEvents)

type Client interface {
AddCertificate(ctx context.Context, appName, hostname string) (*fly.AppCertificate, *fly.HostnameCheck, error)
Expand Down Expand Up @@ -70,6 +70,7 @@
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
Loading