Skip to content

[gpctl] add command to get last heartbeat time of workspace #11230

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

Merged
merged 1 commit into from
Jul 8, 2022
Merged
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
47 changes: 47 additions & 0 deletions dev/gpctl/cmd/workspaces-last-heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/ws-manager/api"
)

// workspacesLastHeartbeatCmd get workspace last heartbeat time
var workspacesLastHeartbeatCmd = &cobra.Command{
Use: "last-heartbeat <instanceID>",
Short: "get workspace last heartbeat time",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

conn, client, err := getWorkspacesClient(ctx)
if err != nil {
log.WithError(err).Fatal("cannot connect")
}
defer conn.Close()

instanceID := args[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about receiving get multiple instances IDs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That probably can be done as a separate PR. But good suggestion.

Copy link
Contributor Author

@mustard-mh mustard-mh Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to create a follow-up PR to support multiple instance ids since our commands like snapshot stop backup all only works for one instance.

We can do mutiple-ify it like

cat backup-pods.txt | xargs -n1 -I{} gpctl workspaces backup {}

Or put make commands support multiple instances in our plan?


resp, err := client.DescribeWorkspace(ctx, &api.DescribeWorkspaceRequest{
Id: instanceID,
})
if err != nil {
log.WithError(err).Fatal("error during RPC call")
}

fmt.Println(resp.LastActivity)
},
}

func init() {
workspacesCmd.AddCommand(workspacesLastHeartbeatCmd)
}