Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Comment changes - Query analysis ohi (#52) - feat: Enhanced query performance monitoring features to track slow queries, examine query execution plans, monitor wait events, and identify blocking sessions #199

Draft
wants to merge 6 commits into
base: epic_db_query_performance_monitoring
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ test:

integration-test:
@echo "=== $(INTEGRATION) === [ test ]: running integration tests..."
@docker compose -f tests/docker-compose.yml pull
@go test -count=1 -v -tags=integration ./tests/. || (ret=$$?; docker compose -f tests/docker-compose.yml down && exit $$ret)
@docker compose -f tests/docker-compose.yml down
@docker compose -f tests/docker-compose.yml up -d
@sleep 120
@go test -v -tags=integration -count 1 ./tests/mssql_test.go -timeout 180s || (ret=$$?; docker compose -f tests/docker-compose.yml down -v && exit $$ret)
@docker compose -f tests/docker-compose.yml down -v

compile:
@echo "=== $(INTEGRATION) === [ compile ]: Building $(BINARY_NAME)..."
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/newrelic/nri-mssql
go 1.23.4

require (
github.com/blang/semver/v4 v4.0.0
github.com/jmoiron/sqlx v1.4.0
github.com/microsoft/go-mssqldb v1.8.0
github.com/newrelic/infra-integrations-sdk/v3 v3.9.1
Expand Down Expand Up @@ -30,4 +31,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: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occ
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0/go.mod h1:bTSOgj05NGRuHHhQwAdPnYr9TOdNmKlZTgGLL6nyAdI=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -53,8 +55,6 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
Expand Down
10 changes: 10 additions & 0 deletions mssql-config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ integrations:
# database_id
# FROM sys.dm_os_buffer_descriptors WITH (nolock)
# GROUP BY database_id
# True is query monitoring should be enabled - defaults to false
# ENABLE_QUERY_MONITORING : "false"

# Threshold in milliseconds for query response time. If response time exceeds this threshold, the query will be considered slow.
# QUERY_RESPONSE_TIME_THRESHOLD : "500"

# Maximum number of queries returned in query analysis results in each FETCH_INTERVAL(max of slow queries can be 20 and for execution plan metrics it can be 30)
# QUERY_COUNT_THRESHOLD : "20"
# Interval in seconds for fetching grouped slow queries; Should always be same as mysql-config interval.
# FETCH_INTERVAL : "15"
interval: 15s
labels:
env: production
Expand Down
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."`
EnableQueryMonitoring bool `default:"false" help:"Enable collection of detailed query performance metrics."`
QueryResponseTimeThreshold int `default:"500" 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."`
sairaj18 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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()
rahulreddy15 marked this conversation as resolved.
Show resolved Hide resolved

if args.EnableQueryMonitoring {
queryanalysis.PopulateQueryPerformanceMetrics(i, args)
}
}
Loading
Loading