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

Feat review comments #63

Merged
merged 66 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a920d40
Query performance monitoring
tharun0064 Dec 30, 2024
ad3ad95
Refactor : version specific blocking session annonamization (#35)
tharun0064 Jan 8, 2025
abf2aa8
refactor: resolved review comments (#36)
sjyothi54 Jan 9, 2025
a6c0f33
Feat review comments (#37)
tharun0064 Jan 9, 2025
417846d
Feat review comments (#39)
sjyothi54 Jan 9, 2025
0fabe72
compile issue - resolved
tharun0064 Jan 10, 2025
c00e650
compile issue - resolved
tharun0064 Jan 10, 2025
1321d36
refactor : rename variable
tharun0064 Jan 10, 2025
28483e3
Refactor : nil checks (#40)
tharun0064 Jan 10, 2025
948764b
Feat : resolved review comments (#42)
tharun0064 Jan 15, 2025
ff46541
resolved: review comments
tharun0064 Jan 16, 2025
605de88
refactor: resolved review comments
tharun0064 Jan 16, 2025
a376e6b
feat: rename files
tharun0064 Jan 16, 2025
03a23c0
resolved: review comments
tharun0064 Jan 16, 2025
ce56848
resolved lint issues
tharun0064 Jan 16, 2025
6bd3c87
resolved : review comments- added comments for queries
tharun0064 Jan 16, 2025
0bd997a
resolved : review comments- added comments for queries
tharun0064 Jan 16, 2025
9281474
change comment
tharun0064 Jan 16, 2025
64088e1
update test
tharun0064 Jan 16, 2025
53fe36d
test
tharun0064 Jan 16, 2025
8509bcd
resolved: review comments (#44)
tharun0064 Jan 16, 2025
2797d52
Integration testing (#47)
rahulreddy15 Jan 16, 2025
7ee17d8
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 17, 2025
632ab00
feat: resolved review comments
tharun0064 Jan 17, 2025
985ba06
Feat : resolved review comments (#48)
tharun0064 Jan 17, 2025
ec832ea
change log type
tharun0064 Jan 17, 2025
08b15ef
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 17, 2025
014c1f2
Feat : resolved review comments (#49)
tharun0064 Jan 17, 2025
c1ace34
feat: resolved review comments
tharun0064 Jan 17, 2025
72f0794
feat: resolved review comments
tharun0064 Jan 20, 2025
c9e014d
merge
tharun0064 Jan 20, 2025
f750db9
rename variable
tharun0064 Jan 20, 2025
4852ecd
Feat review comments (#51)
tharun0064 Jan 20, 2025
4a18508
undo k8s sample config changes
tharun0064 Jan 20, 2025
e25fcfc
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 20, 2025
dfd2be9
Feat: resolved review comments (#52)
tharun0064 Jan 20, 2025
921db09
Refactored Integration Tests (#53)
rahulreddy15 Jan 20, 2025
92c0482
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 21, 2025
462d744
change default query response time to 500ms
tharun0064 Jan 21, 2025
57bc323
Feat review comments (#54)
tharun0064 Jan 21, 2025
da29bb5
fix lint issues (#55)
tharun0064 Jan 21, 2025
2db9a52
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 22, 2025
340eac1
added scenerio for unit test cases and changed level logs
tharun0064 Jan 22, 2025
915a2e5
Feat : resolved review comments (#56)
tharun0064 Jan 22, 2025
d92ff36
refactor: refactored review comments
tharun0064 Jan 22, 2025
1665313
refactored: validation test cases
tharun0064 Jan 22, 2025
7e05c8e
refactorL unit test cases
tharun0064 Jan 22, 2025
c0321a7
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 22, 2025
943d70c
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 27, 2025
4ae46d8
resolved : review comments
tharun0064 Jan 27, 2025
a1d6749
undo change
tharun0064 Jan 27, 2025
6ce3715
resolved : review comments
tharun0064 Jan 27, 2025
b35aae1
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 27, 2025
2a07a81
fix: lint issues
tharun0064 Jan 27, 2025
abc2e85
added more scenerios for unit test cases
tharun0064 Jan 27, 2025
1e81c56
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 27, 2025
11ce7b0
refactor: resolved review comments
tharun0064 Jan 27, 2025
58de3fa
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 27, 2025
39cafa6
rename variable
tharun0064 Jan 27, 2025
f7233cf
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 28, 2025
7184a53
resolved : review comments
tharun0064 Jan 28, 2025
2633801
test
tharun0064 Jan 28, 2025
76ae5ed
remove logs
tharun0064 Jan 28, 2025
1e0eff7
resolved : review comments
tharun0064 Jan 28, 2025
a83d26c
Merge branch 'feat_performance_monitoring' into feat-review-comments
tharun0064 Jan 28, 2025
c8a8ef5
remove unused variables
tharun0064 Jan 28, 2025
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
9 changes: 7 additions & 2 deletions src/query-performance-monitoring/common-utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package commonutils

import "errors"

const MaxQueryThreshold = 30
const MaxIndividualQueryThreshold = 10
// The maximum number records that can be fetched in a single metrics
const MaxQueryCountThreshold = 30

// The maximum number of individual queries that can be fetched in a single metrics
const MaxIndividualQueryCountThreshold = 10

// The maximum number of metrics to be published in a single batch
const PublishThreshold = 100
const RandomIntRange = 1000000
const TimeFormat = "20060102150405"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func IngestMetric(metricList []interface{}, eventName string, pgIntegration *int
}

func CreateEntity(pgIntegration *integration.Integration, gv *globalvariables.GlobalVariables) (*integration.Entity, error) {
return pgIntegration.Entity(fmt.Sprintf("%s:%s", gv.Hostname, gv.Port), "pg-instance")
return pgIntegration.Entity(fmt.Sprintf("%s:%s", gv.Arguments.Hostname, gv.Arguments.Port), "pg-instance")
}

func ProcessModel(model interface{}, metricSet *metric.Set) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@ import (
)

type GlobalVariables struct {
QueryResponseTimeThreshold int
QueryCountThreshold int
Version uint64
DatabaseString string
Hostname string
Port string
Arguments args.ArgumentList
Version uint64
DatabaseString string
Arguments args.ArgumentList
}

func SetGlobalVariables(args args.ArgumentList, version uint64, databaseString string) *GlobalVariables {
return &GlobalVariables{
QueryResponseTimeThreshold: args.QueryResponseTimeThreshold,
QueryCountThreshold: args.QueryCountThreshold,
Version: version,
DatabaseString: databaseString,
Hostname: args.Hostname,
Port: args.Port,
Arguments: args,
Version: version,
DatabaseString: databaseString,
Arguments: args,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetBlockingMetrics(conn *performancedbconnection.PGSQLConnection, gv *globa
log.Error("Unsupported postgres version: %v", err)
return nil, err
}
var query = fmt.Sprintf(versionSpecificBlockingQuery, gv.DatabaseString, min(gv.QueryCountThreshold, commonutils.MaxQueryThreshold))
var query = fmt.Sprintf(versionSpecificBlockingQuery, gv.DatabaseString, min(gv.Arguments.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
rows, err := conn.Queryx(query)
if err != nil {
log.Error("Failed to execute query: %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGetBlockingMetrics(t *testing.T) {
gv := global_variables.SetGlobalVariables(args, version, databaseName)

expectedQuery := queries.BlockingQueriesForV12AndV13
query := fmt.Sprintf(expectedQuery, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryThreshold))
query := fmt.Sprintf(expectedQuery, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"newrelic", "blocked_pid", "blocked_query", "blocked_query_id", "blocked_query_start", "database_name",
"blocking_pid", "blocking_query", "blocking_query_id", "blocking_query_start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func GetIndividualQueryMetrics(conn *performancedbconnection.PGSQLConnection, sl
}

func getIndividualQueriesSamples(conn *performancedbconnection.PGSQLConnection, slowRunningQueries datamodels.SlowRunningQueryMetrics, gv *globalvariables.GlobalVariables, anonymizedQueriesByDB map[string]map[string]string, individualQueryMetricsForExecPlanList *[]datamodels.IndividualQueryMetrics, individualQueryMetricsListInterface *[]interface{}, versionSpecificIndividualQuery string) {
query := fmt.Sprintf(versionSpecificIndividualQuery, *slowRunningQueries.QueryID, gv.DatabaseString, gv.QueryResponseTimeThreshold, min(gv.QueryCountThreshold, commonutils.MaxIndividualQueryThreshold))
query := fmt.Sprintf(versionSpecificIndividualQuery, *slowRunningQueries.QueryID, gv.DatabaseString, gv.Arguments.QueryResponseTimeThreshold, min(gv.Arguments.QueryCountThreshold, commonutils.MaxIndividualQueryCountThreshold))
if query == "" {
log.Debug("Error constructing individual query")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetIndividualQueryMetrics(t *testing.T) {
gv := global_variables.SetGlobalVariables(args, version, databaseName)

// Mock the individual query
query := fmt.Sprintf(queries.IndividualQuerySearchV13AndAbove, mockQueryID, databaseName, args.QueryResponseTimeThreshold, min(args.QueryCountThreshold, commonutils.MaxIndividualQueryThreshold))
query := fmt.Sprintf(queries.IndividualQuerySearchV13AndAbove, mockQueryID, databaseName, args.QueryResponseTimeThreshold, min(args.QueryCountThreshold, commonutils.MaxIndividualQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"newrelic", "query", "queryid", "datname", "planid", "avg_cpu_time_ms", "avg_exec_time_ms",
}).AddRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func GetSlowRunningMetrics(conn *performancedbconnection.PGSQLConnection, gv *gl
log.Error("Unsupported postgres version: %v", err)
return nil, nil, err
}
var query = fmt.Sprintf(versionSpecificSlowQuery, gv.DatabaseString, min(gv.QueryCountThreshold, commonutils.MaxQueryThreshold))
var query = fmt.Sprintf(versionSpecificSlowQuery, gv.DatabaseString, min(gv.Arguments.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
rows, err := conn.Queryx(query)
if err != nil {
return nil, nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func runSlowQueryTest(t *testing.T, query string, version uint64, expectedLength
databaseName := "testdb"
gv := global_variables.SetGlobalVariables(args, version, databaseName)

query = fmt.Sprintf(query, "testdb", min(args.QueryCountThreshold, commonutils.MaxQueryThreshold))
query = fmt.Sprintf(query, "testdb", min(args.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"newrelic", "query_id", "query_text", "database_name", "schema_name", "execution_count",
"avg_elapsed_time_ms", "avg_disk_reads", "avg_disk_writes", "statement_type", "collection_timestamp",
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestGetSlowRunningEmptyMetrics(t *testing.T) {
version := uint64(13)
gv := global_variables.SetGlobalVariables(args, version, databaseName)
expectedQuery := queries.SlowQueriesForV13AndAbove
query := fmt.Sprintf(expectedQuery, "testdb", min(args.QueryCountThreshold, commonutils.MaxQueryThreshold))
query := fmt.Sprintf(expectedQuery, "testdb", min(args.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"newrelic", "query_id", "query_text", "database_name", "schema_name", "execution_count",
"avg_elapsed_time_ms", "avg_disk_reads", "avg_disk_writes", "statement_type", "collection_timestamp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func PopulateWaitEventMetrics(conn *performancedbconnection.PGSQLConnection, pgI

func GetWaitEventMetrics(conn *performancedbconnection.PGSQLConnection, gv *globalvariables.GlobalVariables) ([]interface{}, error) {
var waitEventMetricsList []interface{}
var query = fmt.Sprintf(queries.WaitEvents, gv.DatabaseString, min(gv.QueryCountThreshold, commonutils.MaxQueryThreshold))
var query = fmt.Sprintf(queries.WaitEvents, gv.DatabaseString, min(gv.Arguments.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
rows, err := conn.Queryx(query)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGetWaitEventMetrics(t *testing.T) {
databaseName := "testdb"
gv := global_variables.SetGlobalVariables(args, uint64(14), databaseName)

var query = fmt.Sprintf(queries.WaitEvents, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryThreshold))
var query = fmt.Sprintf(queries.WaitEvents, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"wait_event_name", "wait_category", "total_wait_time_ms", "collection_timestamp", "query_id", "query_text", "database_name",
}).AddRow(
Expand All @@ -40,7 +40,7 @@ func TestGetWaitEventEmptyMetrics(t *testing.T) {
databaseName := "testdb"
gv := global_variables.SetGlobalVariables(args, uint64(14), databaseName)

var query = fmt.Sprintf(queries.WaitEvents, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryThreshold))
var query = fmt.Sprintf(queries.WaitEvents, databaseName, min(args.QueryCountThreshold, commonutils.MaxQueryCountThreshold))
mock.ExpectQuery(regexp.QuoteMeta(query)).WillReturnRows(sqlmock.NewRows([]string{
"wait_event_name", "wait_category", "total_wait_time_ms", "collection_timestamp", "query_id", "query_text", "database_name",
}))
Expand Down
Loading