-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from abhinav1602/queryAnalysis-OHI
Query analysis ohi
- Loading branch information
Showing
15 changed files
with
294 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/queryanalysis/models/blocking_session_query_details.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package models | ||
|
||
type BlockingSessionQueryDetails struct { | ||
BlockingSPID *int64 `db:"blocking_spid"` | ||
BlockingStatus *string `db:"blocking_status"` | ||
BlockedSPID *int64 `db:"blocked_spid"` | ||
BlockedStatus *string `db:"blocked_status"` | ||
WaitType *string `db:"wait_type"` | ||
WaitTimeInSeconds *float64 `db:"wait_time_in_seconds"` | ||
CommandType *string `db:"command_type"` | ||
DatabaseName *string `db:"database_name"` | ||
BlockingQueryText *string `db:"blocking_query_text"` | ||
BlockedQueryText *string `db:"blocked_query_text"` | ||
BlockedQueryStartTime *string `db:"blocked_query_start_time"` | ||
BlockingSPID *int64 `db:"blocking_spid" metric_name:"blocking_spid" sourceType:"gauge"` | ||
BlockingStatus *string `db:"blocking_status" metric_name:"blocking_status" sourceType:"attribute"` | ||
BlockedSPID *int64 `db:"blocked_spid" metric_name:"blocked_spid" sourceType:"gauge"` | ||
BlockedStatus *string `db:"blocked_status" metric_name:"blocked_status" sourceType:"attribute"` | ||
WaitType *string `db:"wait_type" metric_name:"wait_type" sourceType:"attribute"` | ||
WaitTimeInSeconds *float64 `db:"wait_time_in_seconds" metric_name:"wait_time_in_seconds" sourceType:"gauge"` | ||
CommandType *string `db:"command_type" metric_name:"command_type" sourceType:"attribute"` | ||
DatabaseName *string `db:"database_name" metric_name:"database_name" sourceType:"attribute"` | ||
BlockingQueryText *string `db:"blocking_query_text" metric_name:"blocking_query_text" sourceType:"attribute"` | ||
BlockedQueryText *string `db:"blocked_query_text" metric_name:"blocked_query_text" sourceType:"attribute"` | ||
BlockedQueryStartTime *string `db:"blocked_query_start_time" metric_name:"blocked_query_start_time" sourceType:"attribute"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func runScanTests(t *testing.T, tests []struct { | ||
name string | ||
input interface{} | ||
want string | ||
wantErr error | ||
}, scanFunc func(interface{}) (string, error)) { | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := scanFunc(tt.input) | ||
|
||
if tt.wantErr != nil { | ||
if err == nil || err.Error() != tt.wantErr.Error() { | ||
t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
} else { | ||
if err != nil { | ||
t.Errorf("Scan() unexpected error = %v", err) | ||
} | ||
if got != tt.want { | ||
t.Errorf("Scan() = %v, want %v", got, tt.want) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestHexString_Scan(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input interface{} | ||
want string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "valid byte slice", | ||
input: []uint8{0x12, 0x34, 0xab, 0xcd}, | ||
want: "0x1234abcd", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "empty byte slice", | ||
input: []uint8{}, | ||
want: "0x", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "invalid type", | ||
input: "not a byte slice", | ||
want: "", | ||
wantErr: fmt.Errorf("%w, got %T", ErrExpectedUint8Slice, "not a byte slice"), | ||
}, | ||
{ | ||
name: "nil input", | ||
input: nil, | ||
want: "", | ||
wantErr: fmt.Errorf("%w, got %T", ErrExpectedUint8Slice, nil), | ||
}, | ||
} | ||
|
||
runScanTests(t, tests, func(input interface{}) (string, error) { | ||
var hex HexString | ||
err := hex.Scan(input) | ||
return string(hex), err | ||
}) | ||
} | ||
|
||
func TestVarBinary64_Scan(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input interface{} | ||
want string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "VarBinary64: valid byte slice", | ||
input: []byte{0x12, 0x34, 0xab, 0xcd}, | ||
want: "0x1234abcd", | ||
wantErr: nil, | ||
}, | ||
|
||
{ | ||
name: "input value is nil", | ||
input: nil, | ||
want: "", | ||
wantErr: fmt.Errorf("%w, got %T", ErrExpectedByteSlice, nil), | ||
}, | ||
} | ||
|
||
runScanTests(t, tests, func(input interface{}) (string, error) { | ||
var vb VarBinary64 | ||
err := vb.Scan(input) | ||
return string(vb), err | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
package models | ||
|
||
type ExecutionPlanResult struct { | ||
SQLText *string `db:"sql_text"` | ||
QueryID *HexString `db:"query_id"` | ||
QueryPlanID *HexString `db:"query_plan_id"` | ||
NodeID *int `db:"NodeId"` | ||
PhysicalOp *string `db:"PhysicalOp"` | ||
LogicalOp *string `db:"LogicalOp"` | ||
EstimateRows *float64 `db:"EstimateRows"` | ||
EstimateIO *float64 `db:"EstimateIO"` | ||
EstimateCPU *float64 `db:"EstimateCPU"` | ||
AvgRowSize *float64 `db:"AvgRowSize"` | ||
TotalSubtreeCost *float64 `db:"TotalSubtreeCost"` | ||
EstimatedOperatorCost *float64 `db:"EstimatedOperatorCost"` | ||
EstimatedExecutionMode *string `db:"EstimatedExecutionMode"` | ||
GrantedMemoryKb *int `db:"GrantedMemoryKb"` | ||
SpillOccurred *bool `db:"SpillOccurred"` | ||
NoJoinPredicate *bool `db:"NoJoinPredicate"` | ||
TotalWorkerTime *int64 `db:"total_worker_time"` | ||
TotalElapsedTime *int64 `db:"total_elapsed_time"` | ||
TotalLogicalReads *int64 `db:"total_logical_reads"` | ||
TotalLogicalWrites *int64 `db:"total_logical_writes"` | ||
ExecutionCount *int64 `db:"execution_count"` | ||
PlanHandle *VarBinary64 `db:"plan_handle"` | ||
AvgElapsedTimeMs *float64 `db:"avg_elapsed_time_ms"` | ||
SQLText *string `db:"sql_text" metric_name:"sql_text" sourceType:"attribute"` | ||
QueryID *HexString `db:"query_id" metric_name:"query_id" sourceType:"attribute"` | ||
QueryPlanID *HexString `db:"query_plan_id" metric_name:"query_plan_id" sourceType:"attribute"` | ||
NodeID *int `db:"NodeId" metric_name:"NodeId" sourceType:"gauge"` | ||
PhysicalOp *string `db:"PhysicalOp" metric_name:"PhysicalOp" sourceType:"attribute"` | ||
LogicalOp *string `db:"LogicalOp" metric_name:"LogicalOp" sourceType:"attribute"` | ||
EstimateRows *float64 `db:"EstimateRows" metric_name:"EstimateRows" sourceType:"gauge"` | ||
EstimateIO *float64 `db:"EstimateIO" metric_name:"EstimateIO" sourceType:"gauge"` | ||
EstimateCPU *float64 `db:"EstimateCPU" metric_name:"EstimateCPU" sourceType:"gauge"` | ||
AvgRowSize *float64 `db:"AvgRowSize" metric_name:"AvgRowSize" sourceType:"gauge"` | ||
TotalSubtreeCost *float64 `db:"TotalSubtreeCost" metric_name:"TotalSubtreeCost" sourceType:"gauge"` | ||
EstimatedOperatorCost *float64 `db:"EstimatedOperatorCost" metric_name:"EstimatedOperatorCost" sourceType:"gauge"` | ||
EstimatedExecutionMode *string `db:"EstimatedExecutionMode" metric_name:"EstimatedExecutionMode" sourceType:"attribute"` | ||
GrantedMemoryKb *int `db:"GrantedMemoryKb" metric_name:"GrantedMemoryKb" sourceType:"gauge"` | ||
SpillOccurred *bool `db:"SpillOccurred" metric_name:"SpillOccurred" sourceType:"attribute"` | ||
NoJoinPredicate *bool `db:"NoJoinPredicate" metric_name:"NoJoinPredicate" sourceType:"attribute"` | ||
TotalWorkerTime *int64 `db:"total_worker_time" metric_name:"total_worker_time" sourceType:"gauge"` | ||
TotalElapsedTime *int64 `db:"total_elapsed_time" metric_name:"total_elapsed_time" sourceType:"gauge"` | ||
TotalLogicalReads *int64 `db:"total_logical_reads" metric_name:"total_logical_reads" sourceType:"gauge"` | ||
TotalLogicalWrites *int64 `db:"total_logical_writes" metric_name:"total_logical_writes" sourceType:"gauge"` | ||
ExecutionCount *int64 `db:"execution_count" metric_name:"execution_count" sourceType:"gauge"` | ||
PlanHandle *VarBinary64 `db:"plan_handle" metric_name:"plan_handle" sourceType:"attribute"` | ||
AvgElapsedTimeMs *float64 `db:"avg_elapsed_time_ms" metric_name:"avg_elapsed_time_ms" sourceType:"gauge"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package models | ||
|
||
type TopNSlowQueryDetails struct { | ||
QueryID *HexString `db:"query_id"` | ||
QueryText *string `db:"query_text"` | ||
DatabaseName *string `db:"database_name"` | ||
SchemaName *string `db:"schema_name"` | ||
LastExecutionTimestamp *string `db:"last_execution_timestamp"` | ||
ExecutionCount *int64 `db:"execution_count"` | ||
AvgCPUTimeMS *float64 `db:"avg_cpu_time_ms"` | ||
AvgElapsedTimeMS *float64 `db:"avg_elapsed_time_ms"` | ||
AvgDiskReads *float64 `db:"avg_disk_reads"` | ||
AvgDiskWrites *float64 `db:"avg_disk_writes"` | ||
StatementType *string `db:"statement_type"` | ||
CollectionTimestamp *string `db:"collection_timestamp"` | ||
QueryID *HexString `db:"query_id" metric_name:"query_id" sourceType:"attribute"` | ||
QueryText *string `db:"query_text" metric_name:"query_text" sourceType:"attribute"` | ||
DatabaseName *string `db:"database_name" metric_name:"database_name" sourceType:"attribute"` | ||
SchemaName *string `db:"schema_name" metric_name:"schema_name" sourceType:"attribute"` | ||
LastExecutionTimestamp *string `db:"last_execution_timestamp" metric_name:"last_execution_timestamp" sourceType:"attribute"` | ||
ExecutionCount *int64 `db:"execution_count" metric_name:"execution_count" sourceType:"gauge"` | ||
AvgCPUTimeMS *float64 `db:"avg_cpu_time_ms" metric_name:"avg_cpu_time_ms" sourceType:"gauge"` | ||
AvgElapsedTimeMS *float64 `db:"avg_elapsed_time_ms" metric_name:"avg_elapsed_time_ms" sourceType:"gauge"` | ||
AvgDiskReads *float64 `db:"avg_disk_reads" metric_name:"avg_disk_reads" sourceType:"gauge"` | ||
AvgDiskWrites *float64 `db:"avg_disk_writes" metric_name:"avg_disk_writes" sourceType:"gauge"` | ||
StatementType *string `db:"statement_type" metric_name:"statement_type" sourceType:"attribute"` | ||
CollectionTimestamp *string `db:"collection_timestamp" metric_name:"collection_timestamp" sourceType:"attribute"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.