Skip to content

proposal: gp prebuild-logs Gitpod cli command #13505

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

Closed
wants to merge 2 commits into from
Closed
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
54 changes: 54 additions & 0 deletions components/gitpod-cli/cmd/prebuild-logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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 (
"fmt"
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/theialib"
Copy link
Member

Choose a reason for hiding this comment

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

We should ditch theialib. The official api is supervisor API, maybe we should think about how enrich it to return task output. We were discussing such API in the past with @geropl that dashboard could as well return output of prebuild task even if some task already finished.

I think it would be in the right direction to make prebuild UX is more reliable. cc @csweichel

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// initCmd represents the init command
var prebuildLogs = &cobra.Command{
Use: "prebuild-logs",
Copy link
Member

@akosyakov akosyakov Oct 4, 2022

Choose a reason for hiding this comment

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

How about gp prebuilds list + gp prebuilds log to list human readable names of tasks and then fetch content.

Although there is only on prebuild. I would think it should somehow resolve around tasks namespace or we need some new log namespace, for example:

> gp tasks list --prebuild

1. npm 
2. gradle

> gp tasks log 2 --prebuild

log output....

but I'm not sure what would the best UX

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently prebuild-logs-X contains lot of things from binary characters to even process completion % (see picture here). That's why I was saying to avoid printing in terminal.

Copy link
Member

@akosyakov akosyakov Oct 4, 2022

Choose a reason for hiding this comment

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

I think they are special characters for shell and should be interpreted properly. We don't write anything else to these files besides what was produced by pty devices for shell.

Short: "Opens logs of Gitpod prebuilds",
Long: `
Opens all logs of Gitpod prebuilds.
Number of logs depends upon the init tasks you have configured.
`,
Run: func(cmd *cobra.Command, args []string) {

const prebuildFilePath = "/workspace/.gitpod/prebuild-log-*"
Copy link
Member

Choose a reason for hiding this comment

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

it is implementation detail of supervisor, i think it should be a secret of supervisor how to store and fetch content. Clients should not rely on it.

See https://en.wikipedia.org/wiki/Information_hiding

err := openPrebuildLogs(prebuildFilePath)

if err != nil {
log.WithError(err)
return
}
},
}

func init() {
rootCmd.AddCommand(prebuildLogs)
}

func openPrebuildLogs(prebuildFilePath string) error {
service, err := theialib.NewServiceFromEnv()
if err != nil {
log.WithError(err)
return err
}

for {
_, err := service.OpenFile(theialib.OpenFileRequest{Path: prebuildFilePath})
if err != nil {
log.WithError(err)
fmt.Println("Prebuild logs not found.\nMake sure you have configured prebuilds.\nLearn more about Prebuilds: https://www.gitpod.io/docs/configure/projects/prebuilds")
return nil
}
}

}