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

Add instance id to logs #202

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Add warning when accessing logs of a deployment with skipped build.
- https://github.com/koyeb/koyeb-cli/pull/201
* Add instance ID to `koyeb service logs`, `koyeb deployment logs` and `koyeb instance logs`
- https://github.com/koyeb/koyeb-cli/pull/202

## v3.10.0

Expand Down
1 change: 1 addition & 0 deletions pkg/koyeb/deployments_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (h *DeploymentHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []str
"",
deploymentDetail.Deployment.GetId(),
"",
GetBoolFlags(cmd, "full"),
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/koyeb/instances_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (h *InstanceHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []strin
"",
"",
instanceDetail.Instance.GetId(),
GetBoolFlags(cmd, "full"),
)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions pkg/koyeb/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gorilla/websocket"
"github.com/koyeb/koyeb-cli/pkg/koyeb/errors"
"github.com/koyeb/koyeb-cli/pkg/koyeb/renderer"
)

type LogsAPIClient struct {
Expand Down Expand Up @@ -48,16 +49,18 @@ type WatchLogsQuery struct {
instanceId string
conn *websocket.Conn
ticker *time.Ticker
full bool // Whether to display full IDs
}

func (client *LogsAPIClient) NewWatchLogsQuery(
logType string, serviceId string, deploymentId string, instanceId string,
logType string, serviceId string, deploymentId string, instanceId string, full bool,
) (*WatchLogsQuery, error) {
query := &WatchLogsQuery{
client: client,
serviceId: serviceId,
deploymentId: deploymentId,
instanceId: instanceId,
full: full,
}
switch logType {
case "build", "runtime", "":
Expand Down Expand Up @@ -102,6 +105,7 @@ type WatchLogsEntry struct {
Stream string
Msg string
Err error
Labels LogLineResultLabels
}

// ParseTime parses a time string contained in the field result.created_at of
Expand Down Expand Up @@ -167,6 +171,7 @@ func (query *WatchLogsQuery) Execute() (chan WatchLogsEntry, error) {
Stream: msg.Result.Labels.Stream,
Msg: msg.Result.Msg,
Date: query.ParseTime(msg.Result.CreatedAt),
Labels: msg.Result.Labels,
}
}
}
Expand Down Expand Up @@ -221,7 +226,7 @@ func (query *WatchLogsQuery) PrintAll() error {
layout := "2006-01-02 15:04:05"
date := log.Date.Format(layout)
zone, _ := log.Date.Zone()
fmt.Printf("[%s %s] %6s - %s\n", date, zone, log.Stream, log.Msg)
fmt.Printf("[%s %s] %s %6s - %s\n", date, zone, renderer.FormatID(log.Labels.InstanceID, query.full), log.Stream, log.Msg)
}
return nil
}
1 change: 1 addition & 0 deletions pkg/koyeb/services_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (h *ServiceHandler) Logs(ctx *CLIContext, cmd *cobra.Command, args []string
serviceId,
deploymentId,
instanceId,
GetBoolFlags(cmd, "full"),
)
if err != nil {
return err
Expand Down
Loading