-
Notifications
You must be signed in to change notification settings - Fork 85
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
Tail Up #86
Tail Up #86
Conversation
JakeCooper
commented
Apr 7, 2021
- Adds a fetch pointer reset for when status changes
- Calls logtail following up
Co-authored-by: amy null <[email protected]>
…to cooper/deployment-logs
I’ve added a lil loader timeout locally to fix the above |
RE: Last line yea it’s a small big part of the original log fetcher Once I merge the refactor I’ll retest but worked on logstreaming |
😆 Would be amazing to have some tests for this! 🙏🏻 |
controller/logs.go
Outdated
idxMp := make(map[string][]string) | ||
idxMp[deploy.Status] = strings.Split(deploy.DeployLogs, "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually correct? Shouldn't it be giving build or deploy logs depending on what the status is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested locally, and it the formatting stuff seems to be fixed now! Just a few comments on UX and small stuff 🙌🏻
controller/logs.go
Outdated
@@ -68,18 68,26 @@ func (c *Controller) LogsForDeployment(ctx context.Context, req *entity.Deployme | |||
return err | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also check status == "FAILED"
and break out of this
cmd/up.go
Outdated
if detach { | ||
return nil | ||
} | ||
return h.ctrl.GetActiveDeploymentLogs(ctx, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd vote to only see build logs after up
.
My flow is usually to make sure the deploy worked, then go back to writing code. Right now it's difficult to see when it switches from build to deploy then you have to ctrl-C out (which may also not be obvious to less-experienced devs).
One idea might be to detect when the build succeeded and prompt the user to continue streaming the deploy logs or exit.
controller/logs.go
Outdated
// Diff logs using the line numbers as references | ||
logDiff := currLogs[len(prevLogs)-1 : len(currLogs)-1] | ||
idx := int(math.Max(float64(len(idxMp[deploy.Status])-1), 0.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I was happier not knowing that was an emoji.
controller/logs.go
Outdated
// Diff logs using the line numbers as references | ||
logDiff := currLogs[len(prevLogs)-1 : len(currLogs)-1] | ||
idx := int(math.Max(float64(len(idxMp[deploy.Status])-1), 0.0)) | ||
logDiff := currLogs[idx : len(currLogs)-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for len(currLogs) == 0
? If so, this could panic with currLogs[0:-1]
.
controller/logs.go
Outdated
fmt.Println(strings.Join(logLines[int(offset):], "\n")) | ||
if req.NumLines == 0 { | ||
// If no log limit is set, we stream logs | ||
prevLogs := strings.Split(deploy.BuildLogs, "\n") | ||
for { | ||
time.Sleep(time.Second * 2) | ||
deploy, err := c.gtwy.GetDeploymentByID(ctx, &entity.DeploymentByIDRequest{ | ||
DeploymentID: req.DeploymentID, | ||
ProjectID: req.ProjectID, | ||
GQL: query, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
// Current Logs fetched from server | ||
currLogs := strings.Split(deploy.BuildLogs, "\n") | ||
// Diff logs using the line numbers as references | ||
logDiff := currLogs[len(prevLogs)-1 : len(currLogs)-1] | ||
// If no changes we continue | ||
if len(logDiff) == 0 { | ||
continue | ||
} | ||
// Output logs | ||
fmt.Println(strings.Join(logDiff, "\n")) | ||
// Set out walk pointer forward using the newest logs | ||
prevLogs = currLogs | ||
if deploy.Status != entity.STATUS_BUILDING { | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two functions are SO similar and yet I can't seem to figure out a way to abstract the commonalities into something pretty :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the only differences query
, deploy.BuildLogs
and STATUS_BUILDING
references? If so, I'd make a new fn with those as args, then have LogsForBuild
and LogsForDeploy
call into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly, but they also rely on the closure of having prevlogs memory pointer, as well as this for loop which is broken for build logs but not for deployment logs
Will continue a bit but just wanted to mention/get thoughts
Refactored such that we're getting logs for Building and Not Building states. Does a little cutesy 2 state FSM and have unified into "GetLogsForState" functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice lil refactor there 👍🏻
* Deployment Logs in CLI * Deploy Logs in CLI * Live log tail * Remove loggin code * Update main.go Co-authored-by: amy null <[email protected]> * Add detached flag * Don't fetch all deployments everytime * Remove up command * Add line number * Comment * Tail up on deploy * Cant spell FML * Fix flag err * Re add tail detach for up * use latest deploy * Remove println * Remove status indicator * Custom errors * Factor out incorrect errors * Filter out removed * Fix pointer walk * Update main.go Co-authored-by: Gregory Schier <[email protected]> * Flatten root cmd * Remove helper flag * Fix print offset * WTF * As if this section wasn't confusing enough * Use print * Support build log timeouts newlines * Attach to cloud build line * No idxMp * Remove unused function * Move prevwalk up * Remove todo since it's done * Big refactory * Remove unused * Fix NPE * GQL soft error * Handle build failure * Do not export active state * Remove surperfluous build function * Only check logs once * Added lil railway logs fin * Deploy logs Co-authored-by: amy null <[email protected]> Co-authored-by: Gregory Schier <[email protected]>
* Added GQL mutation and finished PoC * Show Teams in Link Command (#81) * Teams in CLI * Team prompts * Fix lint * Only get env variables when updating (#83) * Only get env variables when updating * Update controller/envs.go Co-authored-by: Jake Runzer <[email protected]> Co-authored-by: Jake Runzer <[email protected]> * Warn On Windows (#84) * Warn On Windows * As string * Warning as yello * Newline * Merge * railway logs command (#85) * Deployment Logs in CLI * Fix log polling (#87) * Do not prompt for teams if no teams (#89) * Clean Up Log Controller (#90) * Merge * Remove superfluous fn * Logs * Reference correct slice on project prompt (#91) * GQL Golang Queries (#92) * Merge * Add to lib * Print * Dont print MP * Support nested structs * Remove environment * Update lib/gql/gql.go * Tail Up (#86) * Deployment Logs in CLI * Deploy Logs in CLI * Live log tail * Remove loggin code * Update main.go Co-authored-by: amy null <[email protected]> * Add detached flag * Don't fetch all deployments everytime * Remove up command * Add line number * Comment * Tail up on deploy * Cant spell FML * Fix flag err * Re add tail detach for up * use latest deploy * Remove println * Remove status indicator * Custom errors * Factor out incorrect errors * Filter out removed * Fix pointer walk * Update main.go Co-authored-by: Gregory Schier <[email protected]> * Flatten root cmd * Remove helper flag * Fix print offset * WTF * As if this section wasn't confusing enough * Use print * Support build log timeouts newlines * Attach to cloud build line * No idxMp * Remove unused function * Move prevwalk up * Remove todo since it's done * Big refactory * Remove unused * Fix NPE * GQL soft error * Handle build failure * Do not export active state * Remove surperfluous build function * Only check logs once * Added lil railway logs fin * Deploy logs Co-authored-by: amy null <[email protected]> Co-authored-by: Gregory Schier <[email protected]> * Newline at the end of up * Add some docs * Add redeploy logic and "up" detection * Rename method and print deployment url Co-authored-by: Jake Cooper <[email protected]> Co-authored-by: Jake Runzer <[email protected]> Co-authored-by: amy null <[email protected]>