Skip to content

Commit

Permalink
CICD for commit 122a0660e3521103eff302fe5af3e16b04071498
Browse files Browse the repository at this point in the history
  • Loading branch information
cchen-vertica committed Feb 7, 2025
1 parent 142e6c1 commit a3c87df
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 108 deletions.
17 changes: 15 additions & 2 deletions local-libs/vcluster/commands/cmd_cluster_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Examples:
// local flags
newCmd.setLocalFlags(cmd)

// Hide this command
cmd.Hidden = true
return cmd
}

Expand All @@ -74,7 +76,7 @@ func (c *CmdClusterHealth) setLocalFlags(cmd *cobra.Command) {
// --end-time : the end time (for all operations)
// --session-id : the session id (for session start and slow event)
// --debug : debug mode (for all operations)
// --threadhold : the threadhold of seconds for slow events (for get_slow_events)
// --threshold : the threadhold of seconds for slow events (for get_slow_events)
// --thread-id : the thread id (for get_slow_events)
// --phase-duration-desc : the phase duration description (for get_slow_events)
// --event-desc : the event description (for get_slow_events)
Expand Down Expand Up @@ -209,7 +211,18 @@ func (c *CmdClusterHealth) Run(vcc vclusterops.ClusterCommands) error {
return err
}

bytes, err := json.MarshalIndent(options.CascadeStack, "", " ")
var bytes []byte
switch c.clusterHealthOptions.Operation {
case "get_slow_events":
bytes, err = json.MarshalIndent(options.SlowEvents, "", " ")
case "get_session_starts":
bytes, err = json.MarshalIndent(options.SessionStarts, "", " ")
case "get_transaction_starts":
bytes, err = json.MarshalIndent(options.TransactionStarts, "", " ")
default: // by default, we will build a cascade graph
bytes, err = json.MarshalIndent(options.CascadeStack, "", " ")
}

if err != nil {
return fmt.Errorf("failed to marshal the traceback result, details: %w", err)
}
Expand Down
16 changes: 9 additions & 7 deletions local-libs/vcluster/vclusterops/cluster_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ type VClusterHealthOptions struct {
Display bool

// hidden option
CascadeStack []SlowEventNode
CascadeStack []SlowEventNode
SessionStarts *dcSessionStarts
TransactionStarts *dcTransactionStarts
SlowEvents *dcSlowEvents
}

type SlowEventNode struct {
Expand Down Expand Up @@ -143,11 +146,11 @@ func (vcc VClusterCommands) VClusterHealth(options *VClusterHealthOptions) error
var runError error
switch operation {
case "get_slow_events":
_, runError = options.getSlowEvents(vcc.Log, vdb.PrimaryUpNodes, options.ThreadID, options.StartTime, options.EndTime)
options.SlowEvents, runError = options.getSlowEvents(vcc.Log, vdb.PrimaryUpNodes, options.ThreadID, options.StartTime, options.EndTime)
case "get_session_starts":
_, runError = options.getSessionStarts(vcc.Log, vdb.PrimaryUpNodes, options.SessionID)
options.SessionStarts, runError = options.getSessionStarts(vcc.Log, vdb.PrimaryUpNodes, options.SessionID)
case "get_transaction_starts":
_, runError = options.getTransactionStarts(vcc.Log, vdb.PrimaryUpNodes, options.TxnID)
options.TransactionStarts, runError = options.getTransactionStarts(vcc.Log, vdb.PrimaryUpNodes, options.TxnID)
default: // by default, we will build a cascade graph
runError = options.buildCascadeGraph(vcc.Log, vdb.PrimaryUpNodes)
}
Expand Down Expand Up @@ -333,7 +336,6 @@ func (options *VClusterHealthOptions) getSlowEvents(logger vlog.Printer, upHosts
if err != nil {
return slowEvents, fmt.Errorf("fail to retrieve database configurations, %w", err)
}

return clusterOpEngine.execContext.slowEvents, nil
}

Expand Down Expand Up @@ -368,7 +370,7 @@ func (options *VClusterHealthOptions) getSessionStarts(logger vlog.Printer, upHo
return sessionStarts, fmt.Errorf("fail to retrieve database configurations, %w", err)
}

return &clusterOpEngine.execContext.dcSessionStarts, nil
return clusterOpEngine.execContext.dcSessionStarts, nil
}

func (options *VClusterHealthOptions) getEventSessionInfo(logger vlog.Printer, upHosts []string,
Expand Down Expand Up @@ -401,7 +403,7 @@ func (options *VClusterHealthOptions) getTransactionStarts(logger vlog.Printer,
return transactionInfo, fmt.Errorf("fail to retrieve database configurations, %w", err)
}

return &clusterOpEngine.execContext.dcTransactionStarts, nil
return clusterOpEngine.execContext.dcTransactionStarts, nil
}

func (options *VClusterHealthOptions) getEventTransactionInfo(logger vlog.Printer, upHosts []string,
Expand Down
4 changes: 2 additions & 2 deletions local-libs/vcluster/vclusterops/cluster_op_engine_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ type opEngineExecContext struct {
slowEvents *dcSlowEvents

// transaction starts
dcTransactionStarts dcTransactionStarts
dcTransactionStarts *dcTransactionStarts

// session starts
dcSessionStarts dcSessionStarts
dcSessionStarts *dcSessionStarts
}

func makeOpEngineExecContext(logger vlog.Printer) opEngineExecContext {
Expand Down
58 changes: 25 additions & 33 deletions local-libs/vcluster/vclusterops/https_session_starts_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ package vclusterops

import (
"errors"
"strconv"
"fmt"
"net/url"
"strings"
)

const (
startTimeParam = "start-time="
endTimeParam = "end-time="
sessionIDParam = "session-id="
txnIDParam = "txn-id="
debugParam = "debug="
)

type httpsSessionStartsOp struct {
opBase

Expand Down Expand Up @@ -57,32 +50,31 @@ const sessionStartsURL = "dc/session-starts"
func (op *httpsSessionStartsOp) setupClusterHTTPRequest(hosts []string) error {
// this op may consume resources of the database,
// thus we only need to send https request to one of the up hosts
url := sessionStartsURL
queryParams := []string{}
if op.sessionID != "" {
queryParams = append(queryParams, sessionIDParam+op.sessionID)
}
if op.debug {
queryParams = append(queryParams, debugParam+strconv.FormatBool(op.debug))
}
if op.startTime != "" {
queryParams = append(queryParams, startTimeParam+op.startTime)
}
if op.endTime != "" {
queryParams = append(queryParams, endTimeParam+op.endTime)
}
for i, param := range queryParams {
// replace " " with "%20" in query params
queryParams[i] = strings.ReplaceAll(param, " ", "%20")
}

if len(queryParams) > 0 {
url += "?" + strings.Join(queryParams, "&")
}
baseURL := sessionStartsURL
for _, host := range hosts[:1] {
httpRequest := hostHTTPRequest{}
httpRequest.Method = GetMethod
httpRequest.buildHTTPSEndpoint(url)
queryParams := make(map[string]string)
if op.sessionID != "" {
queryParams["session-id"] = op.sessionID
}
if op.startTime != "" {
queryParams["start-time"] = op.startTime
}
if op.endTime != "" {
queryParams["end-time"] = op.endTime
}

// Build query string
var queryParts []string
for key, value := range queryParams {
queryParts = append(queryParts, fmt.Sprintf("%s=%s", key, value))
}

// Join query parts to form a query string
queryString := url.PathEscape(strings.Join(queryParts, "&"))
httpRequest.buildHTTPSEndpoint(fmt.Sprintf("%s?%s", baseURL, queryString))

op.clusterHTTPRequest.RequestCollection[host] = httpRequest
}

Expand Down Expand Up @@ -156,7 +148,7 @@ func (op *httpsSessionStartsOp) processResult(execContext *opEngineExecContext)
}

// we only need result from one host
execContext.dcSessionStarts = sessionStarts
execContext.dcSessionStarts = &sessionStarts
return allErrs
}
}
Expand Down
68 changes: 31 additions & 37 deletions local-libs/vcluster/vclusterops/https_slow_event_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"io"
"net/url"
"os"
"strings"
)
Expand Down Expand Up @@ -78,41 +79,40 @@ func (op *httpsSlowEventsOp) setupClusterHTTPRequest(hosts []string) error {
// thus we only need to send https request to one of the up hosts

// compose url from options
url := slowEventsURL
queryParams := []string{}

if op.startTime != "" {
queryParams = append(queryParams, "start-time="+op.startTime)
}
if op.endTime != "" {
queryParams = append(queryParams, "end-time="+op.endTime)
}
if op.debug {
queryParams = append(queryParams, "debug=true")
}
if op.nodeName != "" {
queryParams = append(queryParams, "node-name="+op.nodeName)
}
if op.threadID != "" {
queryParams = append(queryParams, "thread-id="+op.threadID)
}
if op.phaseDuration != "" {
queryParams = append(queryParams, "phases-duration-desc"+op.phaseDuration)
}
if op.eventDesc != "" {
queryParams = append(queryParams, "event-desc="+op.eventDesc)
}

for i, param := range queryParams {
// replace " " with "%20" in query params
queryParams[i] = strings.ReplaceAll(param, " ", "%20")
}
url += "?" + strings.Join(queryParams, "&")
baseURL := slowEventsURL

for _, host := range hosts[:1] {
httpRequest := hostHTTPRequest{}
httpRequest.Method = GetMethod
httpRequest.buildHTTPSEndpoint(url)
queryParams := make(map[string]string)
if op.nodeName != "" {
queryParams["node-name"] = op.nodeName
}
if op.startTime != "" {
queryParams["start-time"] = op.startTime
}
if op.endTime != "" {
queryParams["end-time"] = op.endTime
}
if op.threadID != "" {
queryParams["thread-id"] = op.threadID
}
if op.phaseDuration != "" {
queryParams["phases-duration-desc"] = op.phaseDuration
}
if op.eventDesc != "" {
queryParams["event-desc"] = op.eventDesc
}

// Build query string
var queryParts []string
for key, value := range queryParams {
queryParts = append(queryParts, fmt.Sprintf("%s=%s", key, value))
}

// Join query parts to form a query string
queryString := url.PathEscape(strings.Join(queryParts, "&"))
httpRequest.buildHTTPSEndpoint(fmt.Sprintf("%s?%s", baseURL, queryString))
op.clusterHTTPRequest.RequestCollection[host] = httpRequest
}

Expand Down Expand Up @@ -169,7 +169,6 @@ func (op *httpsSlowEventsOp) processResult(execContext *opEngineExecContext) err
var allErrs error
for host, result := range op.clusterHTTPRequest.ResultCollection {
op.logResponse(host, result)

if result.isPassing() {
var slowEvents dcSlowEvents
err := op.parseAndCheckResponse(host, result.content, &slowEvents)
Expand Down Expand Up @@ -222,11 +221,6 @@ func (op *httpsSlowEventsOp) executeOnStub(execContext *opEngineExecContext) err
continue
}
}
if op.eventDesc != "" {
if !strings.Contains(event.EventDescription, op.eventDesc) {
continue
}
}
filteredEvents = append(filteredEvents, event)
}

Expand Down
53 changes: 26 additions & 27 deletions local-libs/vcluster/vclusterops/https_transaction_starts_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ package vclusterops

import (
"errors"
"strconv"
"fmt"
"net/url"
"strings"
)

Expand Down Expand Up @@ -51,34 +52,32 @@ func makeHTTPSTransactionStartsOp(upHosts []string, transactionID, startTime, en
func (op *httpsTransactionStartsOp) setupClusterHTTPRequest(hosts []string) error {
// this op may consume resources of the database,
// thus we only need to send https request to one of the up hosts

url := transactionStartsURL
queryParams := []string{}
if op.startTime != "" {
queryParams = append(queryParams, startTimeParam+op.startTime)
}
if op.endTime != "" {
queryParams = append(queryParams, endTimeParam+op.endTime)
}
if op.transactionID != "" {
queryParams = append(queryParams, txnIDParam+op.transactionID)
}
if op.debug {
queryParams = append(queryParams, debugParam+strconv.FormatBool(op.debug))
}
for i, param := range queryParams {
// replace " " with "%20" in query params
queryParams[i] = strings.ReplaceAll(param, " ", "%20")
}

if len(queryParams) > 0 {
url += "?" + strings.Join(queryParams, "&")
}

var queryParts []string
baseURL := transactionStartsURL
for _, host := range hosts[:1] {
httpRequest := hostHTTPRequest{}
httpRequest.Method = GetMethod
httpRequest.buildHTTPSEndpoint(url)
queryParams := make(map[string]string)

if op.startTime != "" {
queryParams["start-time"] = op.startTime
}
if op.endTime != "" {
queryParams["end-time"] = op.endTime
}
if op.transactionID != "" {
queryParams["txn-id"] = op.transactionID
}

for key, value := range queryParams {
queryParts = append(queryParts, fmt.Sprintf("%s=%s", key, value))
}

// Join query parts to form a query string
queryString := url.PathEscape(strings.Join(queryParts, "&"))
httpRequest.buildHTTPSEndpoint(fmt.Sprintf("%s?%s", baseURL, queryString))

// Save the request
op.clusterHTTPRequest.RequestCollection[host] = httpRequest
}

Expand Down Expand Up @@ -132,7 +131,7 @@ func (op *httpsTransactionStartsOp) processResult(execContext *opEngineExecConte
}

// we only need result from one host
execContext.dcTransactionStarts = TransactionStarts
execContext.dcTransactionStarts = &TransactionStarts
return allErrs
}
}
Expand Down

0 comments on commit a3c87df

Please sign in to comment.