Skip to content

Commit

Permalink
Support running the same trace request again with the same parameters
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dhruv Jain committed May 25, 2021
1 parent c21592c commit 3ec336d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/octant/cmd/antrea-octant-plugin/main.go
Expand Up @@ -73,7 +73,7 @@ func main() {
a := newAntreaOctantPlugin()

capabilities := &plugin.Capabilities{
ActionNames: []string{addTfAction, addLiveTfAction, showGraphAction},
ActionNames: []string{addTfAction, addLiveTfAction, showGraphAction, runTraceAgainAction},
IsModule: true,
}

Expand Down
35 changes: 31 additions & 4 deletions plugins/octant/cmd/antrea-octant-plugin/traceflow.go
Expand Up @@ -36,9 +36,11 @@ import (
)

var (
addTfAction = "traceflow/addTf"
addLiveTfAction = "traceflow/addLiveTf"
showGraphAction = "traceflow/showGraphAction"
addTfAction = "traceflow/addTf"
addLiveTfAction = "traceflow/addLiveTf"
showGraphAction = "traceflow/showGraphAction"
runTraceAgainAction = "traceflow/runTraceAgain"
mostRecentTraceflow *crdv1alpha1.Traceflow
)

const (
Expand Down Expand Up @@ -95,7 +97,7 @@ func getDstType(tf *crdv1alpha1.Traceflow) string {
return ""
}

// actionHandler handlers clicks and actions from "Start New Trace", "Start New Live-traffic Trace" and "Generate Trace Graph" buttons.
// actionHandler handlers clicks and actions from "Start New Trace", "Start New Live-traffic Trace", "Generate Trace Graph", and "Run Trace Again" buttons
func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error {
actionName, err := request.Payload.String("action")
if err != nil {
Expand Down Expand Up @@ -165,6 +167,7 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
}

updateIPHeader(tf, hasSrcPort, hasDstPort, srcPort, dstPort)
mostRecentTraceflow = tf
p.createTfCR(tf, request, context.Background(), tfName)
return nil
case addLiveTfAction:
Expand Down Expand Up @@ -313,6 +316,19 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
return nil
}
return nil
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")
return nil
}

// Get name of new traceflow
mostRecentTraceflow.Name = mostRecentTraceflow.Spec.Source.Pod + "-" + mostRecentTraceflow.Spec.Destination.Pod
mostRecentTraceflow.Name += "-" + time.Now().Format(TIME_FORMAT_YYYYMMDD_HHMMSS)

p.createTfCR(mostRecentTraceflow, request, context.Background(), mostRecentTraceflow.Name)
return nil
default:
log.Fatalf("Failed to find defined handler after receiving action request for %s\n", pluginName)
return nil
Expand Down Expand Up @@ -702,10 +718,21 @@ func (p *antreaOctantPlugin) traceflowHandler(request service.Request) (componen
Title: "Generate Trace Graph",
Form: graphForm,
}

// Run the previous traceflow again.
traceAgainForm := component.Form{Fields: []component.FormField{
component.NewFormFieldHidden("action", runTraceAgainAction),
}}
runTraceAgain := component.Action{
Name: "Run Traceflow Again",
Title: "Run Traceflow Again",
Form: traceAgainForm,
}
card.SetBody(component.NewText(""))
card.AddAction(addTf)
card.AddAction(addLiveTf)
card.AddAction(genGraph)
card.AddAction(runTraceAgain)

graphCard := component.NewCard(component.TitleFromString("Antrea Traceflow Graph"))
if p.lastTf.Name != "" {
Expand Down

0 comments on commit 3ec336d

Please sign in to comment.