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

Refactor log handler #175

Merged
merged 4 commits into from
Feb 7, 2022
Merged

Conversation

Aayyush
Copy link

@Aayyush Aayyush commented Feb 3, 2022

  • Move Job url generation into it's own component to reduce the responsibility on ProjectCommandOuptutHandler
  • Move log streaming source files into server/jobs and refactor out log streaming specific models into its own models package under jobs directory

Line string
OperationComplete bool
}

// AsyncProjectCommandOutputHandler is a handler to transport terraform client
// outputs to the front end.
type AsyncProjectCommandOutputHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this still in a /handlers/ package? doesn't seem like it needs to be now. I don't like the name handler in general because it's very vague as to what the respondibility actually is.

Copy link
Author

Choose a reason for hiding this comment

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

True. I'll remove the handlers directory and move it to the jobs package. Should we rename the struct and the interface as well? From my understanding, there's two key responsibilities of the AsyncProjectCommandOutputHandler: in memory registry for logs and output logs handler. We could just name it registry but that would not account for the handling of logs. Do you have any naming suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably just leave that for now since it existed before (I also don't have great suggestions at this point)

Copy link
Author

Choose a reason for hiding this comment

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

Okay

SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus) error
}

type DefaultJobURLSetter struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment about prepending default to interface names:
../atlantis/internal/team_practices/style_guide.html#interface-naming

Copy link
Author

Choose a reason for hiding this comment

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

Moved the JobURLSetter interface to project_command_runner (where it's being used) and renamed DefaultJobUrlSetter to JobURLSetter.


//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_status_updater.go ProjectStatusUpdater

type ProjectStatusUpdater interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I want us to get away from this practice of exporting interfaces because it creates an unnecessary dependency between packages. Also it's more semantic in go to always return a concrete type and use an interface on the reader side.

Here's an example of this: https://stackoverflow.com/questions/51031116/export-interfaces-instead-of-structs-from-golang-packages

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I like this approach too! I've moved the JobURLSetter to project_command_runner and left the unexported interfaces ProjectJobURLGenerator and ProjectStatusUpdater as it is.

@@ -0,0 +1,25 @@
package models

type OutputBuffer struct {
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 commented about this in the last PR, I don't agree with the concept of using models as a filename or a package name because it just becomes a dumping ground of things eventually. Let's have names that make sense.

In this case the objects are also arbitrarily appended with Context so maybe an overall rethink on naming here is a good idea.

Copy link
Author

Choose a reason for hiding this comment

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

I've moved the structs to project_command_output_handler.go since that's the only place they are being used and I've renamed PullContext and JobContext to PullInfo and JobInfo respectively. Lmk if you have any other naming suggestions 😅

nishkrishnan
nishkrishnan previously approved these changes Feb 5, 2022
@Aayyush Aayyush merged commit ae35ab3 into release-v0.17.3-lyft.1 Feb 7, 2022
@Aayyush Aayyush deleted the aay/refactor_log_handler branch February 7, 2022 19:01
Aayyush added a commit that referenced this pull request Feb 14, 2022
* Add UUID for Log Streaming Job ID (#167)

* Update log handler to close buffered  channels when an operation is complete (#170)

* Add preliminary check before registering new receivers in the log handler (#173)

* Using projectOutputBuffers to check for jobID instead of receiverBuffers (#181)

* Refactor log handler  (#175)

* Reverting go.mod and go.sum

* Fix lint errors

* Fix linting
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.

3 participants