Skip to content

Commit

Permalink
CICD for commit a95a01f4a207db331c7a21544ffc20e5e5916e83
Browse files Browse the repository at this point in the history
  • Loading branch information
cchen-vertica committed Feb 7, 2025
1 parent 142e6c1 commit c68fcc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 66 deletions.
3 changes: 3 additions & 0 deletions local-libs/vcluster/commands/cmd_cluster_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func (c *CmdClusterHealth) Run(vcc vclusterops.ClusterCommands) error {
return fmt.Errorf("failed to marshal the traceback result, details: %w", err)
}

vcc.DisplayInfo("Successfully build the cascade graph for the slow events")

// output the result to console or file
c.writeCmdOutputToFile(globals.file, bytes, vcc.GetLog())
vcc.LogInfo("Slow event traceback: ", "slow events", string(bytes))

Expand Down
19 changes: 11 additions & 8 deletions local-libs/vcluster/vclusterops/cluster_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ func (options *VClusterHealthOptions) buildCascadeGraph(logger vlog.Printer, upH
return err
}

// TODO: remove this debug info when the algorithm is fully implemented
fmt.Println("[DEBUG INFO]: cascade traceback done.")

return err
}

Expand Down Expand Up @@ -248,6 +245,16 @@ func (options *VClusterHealthOptions) recursiveTraceback(logger vlog.Printer,
if callerThreadID == "" {
leaf = true
}

// stop recursive tracing if
// - the caller's thread ID is empty or
// - the caller's thread ID is same as the current event thread ID
if callerThreadID == "" || callerThreadID == threadID {
length := len(options.CascadeStack)
options.CascadeStack[length-1].Leaf = true
return nil
}

options.CascadeStack = append(options.CascadeStack, SlowEventNode{depth, &event,
sessionInfo, transactionInfo, nil, leaf})

Expand Down Expand Up @@ -278,9 +285,7 @@ func analyzeSlowEvent(event *dcSlowEvent) (
const hex = 16
threadIDDec.SetString(threadIDHex, hex)
threadIDStr = threadIDDec.String()
// we keep only the first 26 characters in the timestamp string
// and chop the timezone info to avoid parsing error
end, err := time.Parse(timeLayout, event.Time[:26])
end, err := time.Parse(timeLayout, event.Time)
if err != nil {
return threadIDStr, startTime, endTime, err
}
Expand All @@ -301,8 +306,6 @@ func (options *VClusterHealthOptions) fillLockHoldInfo(logger vlog.Printer, upHo
continue
}

// we keep only the first 26 characters in the timestamp string
// and chop the timezone info to avoid parsing error
end, err := time.Parse(timeLayout, event.Event.Time)
start := end.Add(time.Duration(-event.Event.DurationUs) * time.Microsecond)
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions local-libs/vcluster/vclusterops/https_slow_event_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
package vclusterops

import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strings"
)

Expand Down Expand Up @@ -129,10 +125,6 @@ func (op *httpsSlowEventsOp) prepare(execContext *opEngineExecContext) error {
}

func (op *httpsSlowEventsOp) execute(execContext *opEngineExecContext) error {
if op.debug {
return op.executeOnStub(execContext)
}

if err := op.runExecute(execContext); err != nil {
return err
}
Expand Down Expand Up @@ -185,53 +177,3 @@ func (op *httpsSlowEventsOp) processResult(execContext *opEngineExecContext) err

return allErrs
}

func (op *httpsSlowEventsOp) executeOnStub(execContext *opEngineExecContext) error {
// TODO: we take this location from input, but this place would be fine
// because we can any way write files from outside to the test containers
location := "/opt/vertica/tmp/slow_events_sample.json"
jsonFile, err := os.Open(location)
if err != nil {
return fmt.Errorf("failed to open slow events stub file at %s", location)
}

defer jsonFile.Close()

var slowEventList []dcSlowEvent
bytes, _ := io.ReadAll(jsonFile)
err = json.Unmarshal(bytes, &slowEventList)
if err != nil {
return err
}

var filteredEvents []dcSlowEvent
for idx := range slowEventList {
event := slowEventList[idx]
if op.startTime != "" {
if event.Time < op.startTime {
continue
}
}
if op.endTime != "" {
if event.Time > op.endTime {
continue
}
}
if op.threadID != "" {
if event.ThreadID != op.threadID {
continue
}
}
if op.eventDesc != "" {
if !strings.Contains(event.EventDescription, op.eventDesc) {
continue
}
}
filteredEvents = append(filteredEvents, event)
}

execContext.slowEvents = new(dcSlowEvents)
execContext.slowEvents.SlowEventList = filteredEvents

return nil
}

0 comments on commit c68fcc2

Please sign in to comment.