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

feat: Add streaming endpoint for workspace history #157

Merged
merged 8 commits into from
Feb 4, 2022
Merged

Conversation

kylecarbs
Copy link
Member

Enables a buildlog-like flow for reading job output.

@kylecarbs kylecarbs self-assigned this Feb 3, 2022
@codecov
Copy link

codecov bot commented Feb 3, 2022

Codecov Report

Merging #157 (8904dc5) into main (430341b) will decrease coverage by 0.53%.
The diff coverage is 44.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #157      +/-   ##
==========================================
- Coverage   66.55%   66.02%   -0.54%     
==========================================
  Files         104      105       +1     
  Lines        5221     5501     +280     
  Branches       68       68              
==========================================
+ Hits         3475     3632     +157     
- Misses       1423     1524     +101     
- Partials      323      345      +22     
Flag Coverage Δ
unittest-go-macos-latest 63.45% <44.09%> (-0.23%) ⬇️
unittest-go-ubuntu-latest 65.23% <42.70%> (-0.54%) ⬇️
unittest-go-windows-latest 63.25% <44.09%> (-0.24%) ⬇️
unittest-js 64.21% <ø> (ø)
Impacted Files Coverage Δ
coderd/parameters.go 45.45% <ø> (ø)
codersdk/workspaces.go 48.36% <0.00%> (-26.39%) ⬇️
provisionerd/provisionerd.go 67.95% <0.00%> (-1.00%) ⬇️
coderd/workspacehistorylogs.go 52.44% <52.44%> (ø)
codersdk/projects.go 63.10% <54.54%> (-1.03%) ⬇️
coderd/projecthistory.go 61.14% <57.57%> (-4.08%) ⬇️
coderd/coderd.go 93.50% <100.00%> (+0.17%) ⬆️
coderd/provisionerdaemons.go 53.78% <100.00%> (+9.11%) ⬆️
coderd/workspacehistory.go 53.72% <100.00%> (-0.25%) ⬇️
peer/conn.go 76.66% <0.00%> (-2.06%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 430341b...8904dc5. Read the comment docs.

Base automatically changed from parameters to main February 4, 2022 18:11
@kylecarbs kylecarbs force-pushed the jobstreaming branch 2 times, most recently from 0da0d10 to d5eafa5 Compare February 4, 2022 18:24
@@ -96,6 +97,7 @@ func New(options *Options) http.Handler {
r.Route("/{workspacehistory}", func(r chi.Router) {
r.Use(httpmw.ExtractWorkspaceHistoryParam(options.Database))
r.Get("/", api.workspaceHistoryByName)
r.Get("/logs", api.workspaceHistoryLogsByName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Comment on lines +149 to +150
// The Go stdlib JSON encoder appends a newline character after message write.
encoder := json.NewEncoder(rw)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the comment here, and above, for the ndjson spec

Copy link
Contributor

Choose a reason for hiding this comment

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

lol is ndjson another format similar to https://jsonlines.org/ ??

They even forked it from that one, which seems functionally equivalent... why?!

Copy link
Member Author

Choose a reason for hiding this comment

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

lmao no idea, I thought ndlines was the only one

Copy link
Contributor

Choose a reason for hiding this comment

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

ah the answer was on the jsonlines site:

image

Comment on lines +78 to +79
logChan, err := server.Client.FollowWorkspaceHistoryLogsAfter(context.Background(), "", workspace.Name, workspaceHistory.Name, now)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to the follow case - it would be nice to have a few other cases:

  • before + follow -> should return error
  • after + follow -> should stream logs, but just after the current time
  • before + after, no follow -> should return a subset of logs, unstreamed
  • no args -> should return all the logs, unstreamed

Copy link
Contributor

Choose a reason for hiding this comment

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

(non-blocking, just thinking about it).

This could actually be a nice good-first-issue for someone we're bringing on to help with workspaces v2, to get them familiar with the model and the streaming strategy we're using - adding tests is a great way to get to know the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a bit strange to test before + follow, because the codersdk shouldn't support it, but we should technically test it. I'll noodle on how we should test those cases!

Copy link
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

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

Exciting to have this piece available!

@bryphe-coder
Copy link
Contributor

bryphe-coder commented Feb 4, 2022

✅ for the test run on first try, happy times 😎

@kylecarbs kylecarbs enabled auto-merge (squash) February 4, 2022 19:33
@kylecarbs kylecarbs merged commit 65de6ee into main Feb 4, 2022
@kylecarbs kylecarbs deleted the jobstreaming branch February 4, 2022 19:36
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.

None yet

3 participants