Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions agent/agents/postgres/pgstatmonitor/pgstatmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const (
pgStatMonitorVersion10PG12
pgStatMonitorVersion10PG13
pgStatMonitorVersion10PG14
pgStatMonitorVersion11PG12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
pgStatMonitorVersion11PG12 is unused (deadcode)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

pgStatMonitorVersion11PG13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
pgStatMonitorVersion11PG13 is unused (deadcode)

pgStatMonitorVersion11PG14
)

const (
Expand Down
17 changes: 3 additions & 14 deletions agent/agents/postgres/pgstatmonitor/pgstatmonitor_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

var (
v10 = version.Must(version.NewVersion("1.0.0-beta-2"))
v10 = version.Must(version.NewVersion("1.0.0"))
v09 = version.Must(version.NewVersion("0.9"))
v08 = version.Must(version.NewVersion("0.8"))
)
Expand Down Expand Up @@ -82,13 +82,6 @@ type pgStatMonitor struct {
WalRecords int64
WalFpi int64
WalBytes int64
// state_code = 0 state 'PARSING'
// state_code = 1 state 'PLANNING'
// state_code = 2 state 'ACTIVE'
// state_code = 3 state 'FINISHED'
// state_code = 4 state 'FINISHED WITH ERROR'
StateCode int64
State string

// < pg0.6

Expand Down Expand Up @@ -179,9 +172,7 @@ func NewPgStatMonitorStructs(v pgStatMonitorVersion) (*pgStatMonitor, reform.Vie
field{info: parse.FieldInfo{Name: "Message", Type: "*string", Column: "message"}, pointer: &s.Message},
field{info: parse.FieldInfo{Name: "WalRecords", Type: "int64", Column: "wal_records"}, pointer: &s.WalRecords},
field{info: parse.FieldInfo{Name: "WalFpi", Type: "int64", Column: "wal_fpi"}, pointer: &s.WalFpi},
field{info: parse.FieldInfo{Name: "WalBytes", Type: "int64", Column: "wal_bytes"}, pointer: &s.WalBytes},
field{info: parse.FieldInfo{Name: "StateCode", Type: "int64", Column: "state_code"}, pointer: &s.StateCode},
field{info: parse.FieldInfo{Name: "State", Type: "string", Column: "state"}, pointer: &s.State})
field{info: parse.FieldInfo{Name: "WalBytes", Type: "int64", Column: "wal_bytes"}, pointer: &s.WalBytes})
}

if v <= pgStatMonitorVersion10PG12 {
Expand Down Expand Up @@ -257,7 +248,7 @@ func (v *pgStatMonitorAllViewType) NewStruct() reform.Struct {

// String returns a string representation of this struct or record.
func (s pgStatMonitor) String() string {
res := make([]string, 51)
res := make([]string, 49)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
mnd: Magic number: 49, in detected (gomnd)

res[0] = "Bucket: " + reform.Inspect(s.Bucket, true)
res[1] = "BucketStartTime: " + reform.Inspect(s.BucketStartTime, true)
res[2] = "UserID: " + reform.Inspect(s.UserID, true)
Expand Down Expand Up @@ -307,8 +298,6 @@ func (s pgStatMonitor) String() string {
res[46] = "WalRecords: " + reform.Inspect(s.WalRecords, true)
res[47] = "WalFpi: " + reform.Inspect(s.WalFpi, true)
res[48] = "WalBytes: " + reform.Inspect(s.WalBytes, true)
res[49] = "StateCode: " + reform.Inspect(s.StateCode, true)
res[50] = "State: " + reform.Inspect(s.State, true)
return strings.Join(res, ", ")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func filter(mb []*agentpb.MetricsBucket) []*agentpb.MetricsBucket {
func TestVersion(t *testing.T) {
pgsmVersion, err := ver.NewVersion("1.0.0-beta-2")
require.NoError(t, err)
require.True(t, pgsmVersion.GreaterThanOrEqual(v10))
require.True(t, pgsmVersion.LessThan(v10))
}

func TestPGStatMonitorSchema(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions agent/agents/postgres/pgstatmonitor/stat_monitor_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (ssc *statMonitorCache) getStatMonitorExtended(ctx context.Context, q *refo
databases := queryDatabases(q)
usernames := queryUsernames(q)

pgMonitorVersion, _, err := getPGMonitorVersion(q)
pgMonitorVersion, prerelease, err := getPGMonitorVersion(q)
if err != nil {
err = errors.Wrap(err, "failed to get row and view for pg_stat_monitor version")
return
Expand All @@ -91,10 +91,11 @@ func (ssc *statMonitorCache) getStatMonitorExtended(ctx context.Context, q *refo

row, view := NewPgStatMonitorStructs(pgMonitorVersion)
conditions := "WHERE queryid IS NOT NULL AND query IS NOT NULL"
if pgMonitorVersion >= pgStatMonitorVersion09 {
// only pg_stat_monitor 0.9.0 and above supports state_code. It tells what is the query's current state.
if pgMonitorVersion >= pgStatMonitorVersion09 && pgMonitorVersion <= pgStatMonitorVersion11PG14 && prerelease != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that we decided to have a check like version >= 0.9 and version <= 2.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

// only pg_stat_monitor 0.9.0, 1.0.0-beta-2, 1.0.0-rc.1, 1.0.0-rc.2, 1.0.0 and 1.1.0 supports state_code. It tells what is the query's current state.
// To have correct data in QAN, we have to get only queries that are either 'FINISHED' or 'FINISHED WITH ERROR'.
conditions += " AND (state_code = 3 OR state_code = 4)"
ssc.l.Debug("PGSM version with state and state_code")
}
rows, e := q.SelectRows(view, conditions)
if e != nil {
Expand Down