Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

PMM-9875 Errors view usage #370

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9c7358f
PMM-9630 Use status, status_code only for some versions.
Mar 7, 2022
f27e249
PMM-9630 Remove unnecessary line.
Mar 7, 2022
4de69d6
PMM-9630 Fix test.
Mar 7, 2022
22ece8f
PMM-9630 Handle RC 2.
Mar 8, 2022
3e99acb
Revert "PMM-9630 Handle RC 2."
Mar 8, 2022
9006b7c
PMM-9630 Bump PSGM framework version and defaults.
Mar 9, 2022
dfe4d3e
PMM-9630 If refactor.
Mar 10, 2022
d1a4258
Merge branch 'main' into PMM-9630-status-code-usage
JiriCtvrtka Mar 11, 2022
05acb7d
Merge branch 'main' into PMM-9630-status-code-usage
JiriCtvrtka Mar 11, 2022
f62724f
Merge branch 'main' into PMM-9630-status-code-usage
Mar 14, 2022
eb4edf6
PMM-9875 Errors view draft.
Apr 26, 2022
ca5dba8
Merge branch 'main' into PMM-9630-status-code-usage
Apr 26, 2022
cb2e585
PMM-9630 Code.
Apr 27, 2022
1a43975
Merge branch 'PMM-9630-status-code-usage' into PMM-9875-errors-view-u…
Apr 27, 2022
02b1116
PMM-9875 Changes.
Apr 29, 2022
702f78d
PMM-9875 More severity levels.
Apr 29, 2022
fb765a2
Merge branch 'main' into PMM-9875-errors-view-usage
Apr 29, 2022
88e51fa
PMM-9875 Remove UTC.
Apr 29, 2022
f661935
Revert "Merge branch 'PMM-9630-status-code-usage' into PMM-9875-error…
Apr 27, 2022
063a7bf
PMM-9875 Remove comment.
Apr 29, 2022
a1f6426
PMM-9875 Typo.
Apr 29, 2022
669d8ca
PMM-9875 Lint.
Apr 29, 2022
ff56485
PMM-9875 Move block into method.
Apr 29, 2022
1f9aa6c
PMM-9875 Add missing return.
Apr 29, 2022
ba4a2a0
PMM-9875 Lint.
Apr 29, 2022
b4b574d
Merge branch 'main' into PMM-9875-errors-view-usage
JiriCtvrtka May 2, 2022
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: 9 additions & 0 deletions agents/postgres/pgstatmonitor/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ type pgStatMonitorSettingsTextValue struct {
Value string `reform:"value"`
}

// pgStatMonitorErrors represents a row in pg_stat_monitor_errors view.
//reform:pg_stat_monitor_errors
type pgStatMonitorErrors struct {
Severity string `reform:"severity"`
Message string `reform:"message"`
MessageTime string `reform:"msgtime"`
Calls int64 `reform:"calls"`
}

// pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data.
// It's made for performance reason.
type pgStatMonitorExtended struct {
Expand Down
91 changes: 91 additions & 0 deletions agents/postgres/pgstatmonitor/models_reform.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions agents/postgres/pgstatmonitor/pgstatmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const (
commandTypeUpdate = "UPDATE"
commandTypeInsert = "INSERT"
commandTypeDelete = "DELETE"
commandTypeUtiity = "UTILITY"
commandTypeUtility = "UTILITY"
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

)

var commandTypeToText = []string{
Expand All @@ -101,7 +101,7 @@ var commandTypeToText = []string{
commandTypeUpdate,
commandTypeInsert,
commandTypeDelete,
commandTypeUtiity,
commandTypeUtility,
commandTextNotAvailable,
}

Expand Down Expand Up @@ -337,6 +337,8 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u
return nil, err
}

m.checkErrorsView(ctx)
JiriCtvrtka marked this conversation as resolved.
Show resolved Hide resolved

buckets := m.makeBuckets(current, prev)
m.l.Debugf("Made %d buckets out of %d stat monitor in %d interval.",
len(buckets), len(current), periodLengthSecs)
Expand All @@ -356,6 +358,45 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u
return buckets, nil
}

func (m *PGStatMonitorQAN) checkErrorsView(ctx context.Context) error {
row := &pgStatMonitorErrors{}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
rows, err := m.q.SelectRows(pgStatMonitorErrorsView, "")
if err != nil {
return errors.Wrap(err, "failed to query pg_stat_monitor_errors view")
}

now := time.Now()
for ctx.Err() == nil {
if err = m.q.NextRow(row, rows); err != nil {
if errors.Is(err, reform.ErrNoRows) {
break
}

return errors.Wrap(err, "cannot read row from errors view")
}

messageTime, err := time.Parse("2006-01-02 15:04:05", row.MessageTime)
if err != nil {
return errors.Wrap(err, "cannot parse messageTime")
}
if now.After(messageTime) {
continue
}

template := "Message: %s, Calls: %d"
switch row.Severity {
case "INFO":
m.l.Infof(template, row.Message, row.Calls)
case "WARNING":
m.l.Warningf(template, row.Message, row.Calls)
case "ERROR":
m.l.Errorf(template, row.Message, row.Calls)
ShashankSinha252 marked this conversation as resolved.
Show resolved Hide resolved
}
}

return nil
}

// makeBuckets uses current state of pg_stat_monitor table and accumulated previous state
// to make metrics buckets.
func (m *PGStatMonitorQAN) makeBuckets(current, cache map[time.Time]map[string]*pgStatMonitorExtended) []*agentpb.MetricsBucket {
Expand Down