Skip to content

Commit

Permalink
Add state to event handler to track logrus output events (GoogleCon…
Browse files Browse the repository at this point in the history
…tainerTools#6272)

* add state to event handler to track logrus output tasks

* linters
  • Loading branch information
MarlonGamez authored and halvards committed Jul 28, 2021
1 parent 227e428 commit 17a03dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/skaffold/event/v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var handler = newHandler()
func newHandler() *eventHandler {
h := &eventHandler{
eventChan: make(chan *proto.Event),
task: constants.DevLoop,
}
go func() {
for {
Expand All @@ -73,6 +74,7 @@ type eventHandler struct {
cfg Config

iteration int
task constants.Phase
state proto.State
stateLock sync.Mutex
eventChan chan *proto.Event
Expand Down Expand Up @@ -303,6 +305,7 @@ func TaskInProgress(task constants.Phase, description string) {
handler.applicationLogs = []proto.Event{}
}

handler.task = task
handler.handleTaskEvent(&proto.TaskEvent{
Id: fmt.Sprintf("%s-%d", task, handler.iteration),
Task: string(task),
Expand All @@ -313,6 +316,7 @@ func TaskInProgress(task constants.Phase, description string) {
}

func TaskFailed(task constants.Phase, err error) {
handler.task = constants.DevLoop
ae := sErrors.ActionableErrV2(handler.cfg, task, err)
handler.handleTaskEvent(&proto.TaskEvent{
Id: fmt.Sprintf("%s-%d", task, handler.iteration),
Expand All @@ -324,6 +328,7 @@ func TaskFailed(task constants.Phase, err error) {
}

func TaskSucceeded(task constants.Phase) {
handler.task = constants.DevLoop
handler.handleTaskEvent(&proto.TaskEvent{
Id: fmt.Sprintf("%s-%d", task, handler.iteration),
Task: string(task),
Expand Down
6 changes: 4 additions & 2 deletions pkg/skaffold/event/v2/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ func (h logHook) Levels() []logrus.Level {
// Fire constructs a SkaffoldLogEvent and sends it to the event channel
func (h logHook) Fire(entry *logrus.Entry) error {
handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{
Level: levelFromEntry(entry),
Message: entry.Message,
TaskId: fmt.Sprintf("%s-%d", handler.task, handler.iteration),
SubtaskId: SubtaskIDNone,
Level: levelFromEntry(entry),
Message: entry.Message,
})
return nil
}
Expand Down

0 comments on commit 17a03dc

Please sign in to comment.