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

Move event messages logic into task_runner #3486

Merged
merged 9 commits into from
Nov 3, 2017
Merged

Conversation

preetapan
Copy link
Contributor

@preetapan preetapan commented Nov 2, 2017

This fixes #3399

@@ -149,6 +149,8 @@ func (s *Server) applyPlan(plan *structs.Plan, result *structs.PlanResult, snap
for _, alloc := range req.Alloc {
if alloc.CreateTime == 0 {
alloc.CreateTime = now
} else {
alloc.ModifyTime = now
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unexpected, I must have messed something up rebasing b-nomad-0.7.1 yesterday, will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@preetapan preetapan changed the title F event messages api Move event messages logic into task_runner Nov 2, 2017
case api.TaskTerminated:
var parts []string
parts = append(parts, fmt.Sprintf("Exit Code: %d", event.ExitCode))
if event.DisplayMessage != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

The only difference between the if and the else is the formattedDisplayMessage. Should we instead do:

msg := event.DisplayMessage
if msg == "" {
  msg = buildDisplayMessage(event)
}
formattedTime := formatUnixNanoTime(event.Time)
formattedDisplayMsg := fmt.Sprintf("%s|%s|%s", formattedTime, event.Type, msg)
events[size-i] = formattedDisplayMsg

@@ -73,6 +73,9 @@ const (
ACLTokenUpsertRequestType
ACLTokenDeleteRequestType
ACLTokenBootstrapRequestType

// Constant for restart events that are within policy
ReasonWithinPolicy = "Restart within policy"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this maybe to be next to the RestartPolicy struct. We try to group vars/consts logically together. Also is there a need to duplicate this? Why not just use the client version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got an import cycle when using client.ReasonWithinPolicy so I duplicated. Didn't seem worth it to try to break the import cycle since this is one constant.

@@ -3817,6 +3820,129 @@ type TaskEvent struct {

// GenericSource is the source of a message.
GenericSource string

// DisplayMessage is a human friendly message about the event
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind making a deprecation notice about the other fields explaining we are transitioning to just these two.


func (event *TaskEvent) PopulateEventDisplayMessage() {
// Build up the description based on the event type.
if event == nil { //TODO PA needs investigation alloc_runner's Run method sends a nil event when sigterming nomad. Why?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you format TODO(preetha). Easier grepping if consistent.

// Build up the description based on the event type.
if event == nil { //TODO PA needs investigation alloc_runner's Run method sends a nil event when sigterming nomad. Why?
return
}
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 break if event.DisplayMessage != ""

desc = event.DriverMessage
case TaskLeaderDead:
desc = "Leader Task in Group dead"
case TaskGenericMessage:
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 we may be able to deprecate this one. We can have the callers just set the type and the DisplayMessage.

api/tasks.go Outdated
@@ -614,4 +614,6 @@ type TaskEvent struct {
TaskSignalReason string
TaskSignal string
GenericSource string
DisplayMessage string
Copy link
Contributor

Choose a reason for hiding this comment

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

Should put a deprecation notice here as well.

@@ -542,6 +542,7 @@ func (r *TaskRunner) DestroyState() error {

// setState is used to update the state of the task runner
func (r *TaskRunner) setState(state string, event *structs.TaskEvent, lazySync bool) {
event.PopulateEventDisplayMessage()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put a blank line between.

@dadgar
Copy link
Contributor

dadgar commented Nov 3, 2017

@preetapan preetapan merged commit 657747e into master Nov 3, 2017
@preetapan preetapan deleted the f-event-messages-api branch November 3, 2017 18:15
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move task event message logic into the API
2 participants