Skip to content

Add Event v2 package #5558

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

Merged
merged 8 commits into from
Mar 31, 2021
Merged

Conversation

MarlonGamez
Copy link
Contributor

@MarlonGamez MarlonGamez commented Mar 16, 2021

Related: #5368 , #5422
Merge After: #5557 - this PR relies on the changes from #5557. The changes actually made in this PR are to

  • pkg/skaffold/event/v2/*.go
  • pkg/skaffold/errors/errors.go

Description
Adds pkg/skaffold/event/v2 package. Almost all of the content is copied from the original pkg/skaffold/event package, with a couple new functions to handle TaskEvent protos (TaskFailed(), TaskInProgress(), and TestTaskFailed()).

I've also updated the pkg/skaffold/errors package to have a new function that returns an actionable error type for v2.

@codecov
Copy link

codecov bot commented Mar 16, 2021

Codecov Report

Merging #5558 (9997b6c) into master (4830337) will decrease coverage by 0.01%.
The diff coverage is 67.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5558      +/-   ##
==========================================
- Coverage   71.05%   71.03%   -0.02%     
==========================================
  Files         402      404       +2     
  Lines       15096    15401     +305     
==========================================
+ Hits        10726    10940     +214     
- Misses       3577     3661      +84     
- Partials      793      800       +7     
Impacted Files Coverage Δ
pkg/skaffold/event/v2/event.go 56.33% <56.33%> (ø)
pkg/skaffold/event/v2/util.go 88.23% <88.23%> (ø)
pkg/skaffold/errors/errors.go 92.72% <100.00%> (+3.36%) ⬆️
pkg/skaffold/util/tar.go 50.66% <0.00%> (-5.34%) ⬇️
pkg/skaffold/schema/validation/validation.go 86.64% <0.00%> (-3.78%) ⬇️
pkg/skaffold/instrumentation/export.go 75.55% <0.00%> (-1.72%) ⬇️
pkg/skaffold/runner/changeset.go 76.47% <0.00%> (-1.31%) ⬇️
pkg/skaffold/event/event.go 91.06% <0.00%> (-0.42%) ⬇️
... and 5 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 4830337...9997b6c. Read the comment docs.

@MarlonGamez MarlonGamez marked this pull request as ready for review March 17, 2021 20:59
@MarlonGamez MarlonGamez requested a review from a team as a code owner March 17, 2021 20:59
@MarlonGamez MarlonGamez marked this pull request as draft March 17, 2021 21:25
@MarlonGamez MarlonGamez marked this pull request as ready for review March 17, 2021 22:19
Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

i'm a little concerned by how much code has been directly copied over from the v1 version of these protos. is there a way we can abstract away some of this logic to be shared across packages? maybe by defining some of these methods on interfaces and having the v1 and v2 versions implement them?

// ActionableErr returns an actionable error message with suggestions
func ActionableErrV2(phase Phase, err error) *protoV2.ActionableErr {
errCode, suggestions := getErrorCodeFromError(phase, err)
suggestionsV2 := make([]*protoV2.Suggestion, len(suggestions))
Copy link
Contributor

Choose a reason for hiding this comment

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

do these need to be pointers? can we pass them by value instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think that's a change we should make for v2? I mostly just did pointers since that's what the existing type uses

@MarlonGamez
Copy link
Contributor Author

@nkubala I'm also concerned about it, I considered the route of creating interfaces for each of the proto types and simply passing them around like that, but I wasn't sure if that would also add unnecessary bloat since we'd need to add an interface for each of the proto types.

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

discussed out of band, and this change should be fine. it's difficult in practice to squeeze to versioned protos into a single interface since the actual methods on the proto structs are autogenerated from the service definitions, and since we're deprecating the v1 version of the API, we'll likely remove the code at some point in the future eliminating the duplication.

@MarlonGamez MarlonGamez merged commit 9d81ce6 into GoogleContainerTools:master Mar 31, 2021
ev.logEvent(event)
}

// SaveEventsToFile saves the current event log to the filepath provided
Copy link
Contributor

Choose a reason for hiding this comment

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

This function can be moved to event/util package and re-used across both v1 and v2 proto


state proto.State
stateLock sync.Mutex
eventChan chan *proto.Event
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to interface? Similar to

type listener struct {
	callback func(interface{} error
	errors   chan error
	closed   bool
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we could try and save duplicate codes for func
ForEachEvent, Handle, logEvent, forEachEvent

We can spend some time seeing and how much code duplication it can save us.

What i am thinking is

  1. We have a broadcaster and a broadcasting channel which does not care about the type ie. v1, v2 proto but only emits whatever is sent to it.
    This might need some complex refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants