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
Added functionality for running the same trace request again with the same parameters. #2202
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Dhruv-J for the PR
addTfAction = "traceflow/addTf" | ||
addLiveTfAction = "traceflow/addLiveTf" | ||
showGraphAction = "traceflow/showGraphAction" | ||
runTraceAgain = "traceflow/runTagain" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you name the variable same style as other actions? i.e.
runTraceAgain = "traceflow/runTagain" | |
runTraceAgainAction = "traceflow/runTraceAgain" |
@@ -165,6 +167,7 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error | |||
} | |||
|
|||
updateIPHeader(tf, hasSrcPort, hasDstPort, srcPort, dstPort) | |||
mostRecentTraceflow = tf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semicolon is redundant. https://golang.org/doc/effective_go#semicolons
Idiomatic Go programs have semicolons only in places such as for loop clauses, to separate the initializer, condition, and continuation elements. They are also necessary to separate multiple statements on a line, should you write code that way.
@@ -313,6 +316,14 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error | |||
return nil | |||
} | |||
return nil | |||
case runTraceAgain: | |||
// Get name of new traceflow | |||
mostRecentTraceflow.Name = mostRecentTraceflow.Spec.Source.Pod + "-" + mostRecentTraceflow.Spec.Destination.Pod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for pod to pod only, could you make it more generic?
Maybe extract a name generator function and call it in addTfAction
, addLiveTfAction
, and runTraceAgain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each case sets the different name a different way, but they have the time in common, so wouldn't it make sense to only change the time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that works too. I suggested a common name generator function as this kind of code seems a bit redundant now, but of course not necessary to handle it in this PR. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has the comment been addressed? My point was some traceflow requests' destination may be service or IP, so mostRecentTraceflow.Spec.Destination.Pod
is empty. The new traceflow's name will be weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The earlier way I had done it was to trim 15 characters off the end of the string, because those were guaranteed to have the date and time. I feel like that might be a better solution considering each traceflow name has a date and time. Should I do this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works for me.
mostRecentTraceflow.Name = mostRecentTraceflow.Spec.Source.Pod + "-" + mostRecentTraceflow.Spec.Destination.Pod | ||
mostRecentTraceflow.Name += "-" + time.Now().Format(TIME_FORMAT_YYYYMMDD_HHMMSS) | ||
|
||
log.Printf("Ran traceflow again successfully, Traceflow Results: %+v\n", mostRecentTraceflow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It hasn't run traceflow successfully, right? Maybe just remove this line if it doesn't provide more information than existing logs in createTfCR
|
||
log.Printf("Ran traceflow again successfully, Traceflow Results: %+v\n", mostRecentTraceflow) | ||
p.createTfCR(mostRecentTraceflow, request, context.Background(), mostRecentTraceflow.Name) | ||
return nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
tAgainForm := component.Form{Fields: []component.FormField{ | ||
component.NewFormFieldHidden("action", runTraceAgain), | ||
}} | ||
runTagain := component.Action{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable should be runTAgain
to meet the mixedCaps converntion. But maybe just use a full name here is more clear - runTraceAgain
.
runTagain := component.Action{ | ||
Name: "Run Traceflow Again", | ||
Title: "Run Traceflow Again", | ||
Form: tAgainForm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, could be traceAgainForm
@@ -313,6 +316,14 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error | |||
return nil | |||
} | |||
return nil | |||
case runTraceAgain: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it support rerun a live traceflow too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any feedback on this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it can't since a Live Traceflow doesn't create a Traceflow Request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It creates a Traceflow request:
p.createTfCR(tf, request, context.Background(), tfName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm adding functionality to be able to rerun live traceflows. My mistake, I didn't see that line.
The commit message needs to be formatted:
For example:
|
Codecov Report
@@ Coverage Diff @@
## main #2202 +/- ##
==========================================
- Coverage 61.95% 52.55% -9.41%
==========================================
Files 276 273 -3
Lines 21178 20504 -674
==========================================
- Hits 13120 10775 -2345
- Misses 6699 8372 +1673
+ Partials 1359 1357 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
addLiveTfAction = "traceflow/addLiveTf" | ||
showGraphAction = "traceflow/showGraphAction" | ||
runTraceAgain = "traceflow/runTagain" | ||
mostRecentTraceflow = &crdv1alpha1.Traceflow{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we initialized it to nil
and display an error if someone tries to run a Traceflow again without first running a normal Traceflow?
another question: since this is mutable global state for the plugin, do we need to protect it with a mutex or is it always accessed from a single goroutine? @mengdie-song do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot initialize it to null right there, but I can check if the structure is still empty before returning an error. The variable should only be accessed by traceflow.go .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhruv-J why can't you initialize it to nil
? The following should work:
var mostRecentTraceflow *crdv1alpha1.Traceflow = nil
Actually, the = nil
is optional
8f36c37
to
3ec336d
Compare
case runTraceAgainAction: | ||
// Check if traceflow has been run before | ||
if mostRecentTraceflow == nil { | ||
log.Printf("Failed to run traceflow again: Run a traceflow before attempting to run a traceflow again.\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the log.Printf will only add a log in backend, it's better to return an alert to UI as well so user can learn what's to do first. eg:
alert := action.CreateAlert(action.AlertTypeError,
`Failed to run traceflow again: Use 'START NEW TRACE' or 'START NEW LIVE-TRAFFIC TRACE' to
run a traceflow before attempting to run a traceflow again.`,
action.DefaultAlertExpiration)
request.DashboardClient.SendAlert(request.Context(), request.ClientID, alert)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll add this.
A "RUN TRACE AGAIN" option has been added to the Octant UI. The new graph's label is changed to reflect the time the trace was run again. Fixes antrea-io#2178 Signed-off-by: Dhruv Jain <2dhruv@gmail.com>
Modified name changing scheme for re-running traceflows and added user alert for attempting to re-run traceflow without running a traceflow first. Also added support for running a live traceflow again. Signed-off-by: Dhruv Jain <2dhruv@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dhruv-J I tested the feature and it works great. However, I noticed that we already had a lastTf
field in the antreaOctantPlugin
struct, and it seems that we could just reuse this instead of adding mostRecentTraceflow
?
BTW after clicking on "RUN TRACEFLOW AGAIN" (shouldn't it be "RUN TRACE AGAIN" for consistency?), there is another step required (clicking "SUBMIT"). It's too bad, but after looking at the Octant, looks like there may not be an easy way around it.
I'm still concerned about concurrent access to global plugin state, but that's not limited to this PR, so no need to change anything there, I'll keep thinking about this issue.
Removed mostRecentTraceflow variable. Also modified RUN TRACEFLOW AGAIN button to read RUN TRACE AGAIN button to maintain consistency. Signed-off-by: Dhruv Jain <2dhruv@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This will be very useful. Thanks @Dhruv-J for working on this and for being patient during the review process.
/skip-all |
A "RUN TRACE AGAIN" option has been added to the Octant UI. The new graph's label is changed to reflect the time the trace was run again.
Fixes: #2178
Signed-off-by: Dhruv Jain 2dhruv@gmail.com