Skip to content

Commit

Permalink
PR Comment changes - Query analysis ohi (#52)
Browse files Browse the repository at this point in the history
feature[DNM]: Query Performance monitoring for NRI-MSSQL providing Enhanced query performance monitoring features to track the following new event Types:

SlowQueryAnalysis
WaitTimeAnalysis
ExecutionPlanAnalysis
BlockedSessionAnalysis

In Progress:
- Integration tests
- Unit test cases
---------
Co-authored-by: Anitha Vadla <[email protected]>
Co-authored-by: tangural <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent ec941c5 commit cac17a6
Show file tree
Hide file tree
Showing 34 changed files with 2,352 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ require (
// Before go 1.23 these certificates where accepted, now the corresponding go debug variable is needed
// to restore the previous behavior
// <https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/crypto/x509/parser.go;l=1019>
godebug x509negativeserial=1
godebug x509negativeserial=1
4 changes: 4 additions & 0 deletions src/args/argument_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type ArgumentList struct {
ShowVersion bool `default:"false" help:"Print build information and exit"`
ExtraConnectionURLArgs string `default:"" help:"Appends additional parameters to connection url. Ex. 'applicationintent=readonly&foo=bar'"`
EnableDiskMetricsInBytes bool `default:"true" help:"Enable collection of instance.diskInBytes."`
EnableQueryPerformance bool `default:"false" help:"Enable collection of detailed query performance metrics."`
QueryResponseTimeThreshold int `default:"0" help:"Threshold in milliseconds for query response time. If response time exceeds this threshold, the query will be considered slow."`
QueryCountThreshold int `default:"20" help:"Maximum number of queries returned in query analysis results."`
FetchInterval int `default:"15" help:"Interval in seconds for fetching grouped slow queries; Should always be same as mysql-config interval."`
}

// Validate validates SQL specific arguments
Expand Down
5 changes: 4 additions & 1 deletion src/connection/sql_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package connection

import (
"errors"
"fmt"
"testing"

"github.com/newrelic/nri-mssql/src/args"
"gopkg.in/DATA-DOG/go-sqlmock.v1"
)

var ErrConnectionFailure = errors.New("something went wrong while trying to create the SQL connection")

func Test_SQLConnection_Close(t *testing.T) {
conn, mock := CreateMockSQL(t)

mock.ExpectClose().WillReturnError(errors.New("error"))
mock.ExpectClose().WillReturnError(fmt.Errorf("critical operation failed: %w", ErrConnectionFailure))
conn.Close()

if err := mock.ExpectationsWereMet(); err != nil {
Expand Down
9 changes: 8 additions & 1 deletion src/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (

"github.com/newrelic/infra-integrations-sdk/v3/integration"
"github.com/newrelic/infra-integrations-sdk/v3/log"

"github.com/newrelic/nri-mssql/src/args"
"github.com/newrelic/nri-mssql/src/connection"
"github.com/newrelic/nri-mssql/src/instance"
"github.com/newrelic/nri-mssql/src/inventory"
"github.com/newrelic/nri-mssql/src/metrics"
"github.com/newrelic/nri-mssql/src/queryanalysis"
)

const (
Expand Down Expand Up @@ -89,6 +91,11 @@ func main() {

if err = i.Publish(); err != nil {
log.Error(err.Error())
os.Exit(1)
return
}
i.Clear()

if args.EnableQueryPerformance {
queryanalysis.QueryPerformanceMain(i, args)
}
}
Loading

0 comments on commit cac17a6

Please sign in to comment.