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

Tail Up #86

Merged
merged 54 commits into from
Apr 10, 2021
Merged

Tail Up #86

merged 54 commits into from
Apr 10, 2021

Conversation

JakeCooper
Copy link
Contributor

  • Adds a fetch pointer reset for when status changes
  • Calls logtail following up

controller/logs.go Outdated Show resolved Hide resolved
controller/logs.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@JakeCooper
Copy link
Contributor Author

I’ve added a lil loader timeout locally to fix the above

@JakeCooper
Copy link
Contributor Author

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

@gschier
Copy link
Contributor

gschier commented Apr 8, 2021

RE: Last line yea it’s a small big part of the original log fetcher

😆

Would be amazing to have some tests for this! 🙏🏻

Comment on lines 58 to 59
idxMp := make(map[string][]string)
idxMp[deploy.Status] = strings.Split(deploy.DeployLogs, "\n")
Copy link
Contributor

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?

Copy link
Contributor

@gschier gschier left a 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 🙌🏻

@@ -68,18 68,26 @@ func (c *Controller) LogsForDeployment(ctx context.Context, req *entity.Deployme
return err
}
Copy link
Contributor

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)
Copy link
Contributor

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.

// 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))
Copy link
Contributor

Choose a reason for hiding this comment

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

:neckbeard:

Copy link
Contributor

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.

// 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]
Copy link
Contributor

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].

Comment on lines 132 to 160
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
}
Copy link
Contributor Author

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 :(

Copy link
Contributor

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.

Copy link
Contributor Author

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

@JakeCooper
Copy link
Contributor Author

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

Copy link
Contributor

@gschier gschier left a 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 👍🏻

@JakeCooper JakeCooper merged commit 0c8a4ce into master Apr 10, 2021
@JakeCooper JakeCooper deleted the cooper/tail-up branch April 10, 2021 00:50
gschier added a commit that referenced this pull request Apr 12, 2021
* 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]>
gschier added a commit that referenced this pull request Apr 14, 2021
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants