-
Notifications
You must be signed in to change notification settings - Fork 229
PMM-9875 Errors view usage. #914
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
373713c
PMM-9875 Errors view usage.
2592963
Merge branch 'main' into PMM-9875-errors-view-usage
JiriCtvrtka 55886c3
Merge branch 'main' into PMM-9875-errors-view-usage
739c59d
Merge branch 'main' into PMM-9875-errors-view-usage
11feccf
Merge branch 'main' into PMM-9875-errors-view-usage
f66f374
PMM-9875 Fix.
11d91b2
Merge branch 'main' into PMM-9875-errors-view-usage
7d67953
Merge branch 'main' into PMM-9875-errors-view-usage
e0c3381
Merge branch 'main' into PMM-9875-errors-view-usage
JiriCtvrtka 3b72ee4
Merge branch 'main' into PMM-9875-errors-view-usage
JiriCtvrtka 3ad90e1
Merge branch 'main' into PMM-9875-errors-view-usage
JiriCtvrtka ff8d677
PMM-9875 Add version check.
JiriCtvrtka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ type PGStatMonitorQAN struct { | |
| changes chan agents.Change | ||
| monitorCache *statMonitorCache | ||
| disableQueryExamples bool | ||
| waitTime time.Duration | ||
| } | ||
|
|
||
| // Params represent Agent parameters. | ||
|
|
@@ -254,6 +255,8 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { | |
| } | ||
| running = m.checkDefaultWaitTime(waitTime) | ||
|
|
||
| m.waitTime = waitTime | ||
|
|
||
| // query pg_stat_monitor every waitTime seconds | ||
| start := time.Now() | ||
| m.l.Debugf("Scheduling next collection in %s at %s.", waitTime, start.Add(waitTime).Format("15:04:05")) | ||
|
|
@@ -299,6 +302,8 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { | |
| continue | ||
| } | ||
|
|
||
| m.waitTime = waitTime | ||
|
|
||
| lengthS := uint32(waitTime.Seconds()) | ||
| buckets, err := m.getNewBuckets(ctx, lengthS, normalizedQuery) | ||
|
|
||
|
|
@@ -407,6 +412,11 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u | |
| return nil, err | ||
| } | ||
|
|
||
| err = m.checkErrorsView(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| buckets := m.makeBuckets(current, prev) | ||
| m.l.Debugf("Made %d buckets out of %d stat monitor in %d interval.", | ||
| len(buckets), len(current), periodLengthSecs) | ||
|
|
@@ -426,6 +436,56 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u | |
| return buckets, nil | ||
| } | ||
|
|
||
| func (m *PGStatMonitorQAN) checkErrorsView(ctx context.Context) error { | ||
| vPGSM, _, err := getPGMonitorVersion(m.q) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to get row and view for pg_stat_monitor version") | ||
| } | ||
|
|
||
| // Errors view is supported in PGSM 2.0 and higher. | ||
| if vPGSM < pgStatMonitorVersion20PG12 { | ||
| return nil | ||
| } | ||
|
|
||
| row := &pgStatMonitorErrors{} | ||
| 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.Add(m.waitTime)) { | ||
| 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) | ||
| } | ||
| } | ||
|
|
||
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 🐶
calculated cyclomatic complexity for function checkErrorsView is 12, max is 10 (cyclop)