-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add support for pg_stat_statements to MetricBeat Postgresql module #7060
Add support for pg_stat_statements to MetricBeat Postgresql module #7060
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
assert.Contains(t, event["user"].(common.MapStr), "id") | ||
|
||
assert.Contains(t, event, "database") | ||
db_oid := event["database"].(common.MapStr)["oid"].(int64) |
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.
don't use underscores in Go names; var db_oid should be dbOid
assert.Contains(t, event["user"].(common.MapStr), "id") | ||
|
||
assert.Contains(t, event, "database") | ||
db_oid := event["database"].(common.MapStr)["oid"].(int64) |
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.
don't use underscores in Go names; var db_oid should be dbOid
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.
Can you add a changelog? Should we also add this to our system tests?
@@ -41,6 +39,8 @@ metricbeat.modules: | |||
- uptime # System Uptime | |||
#- core # Per CPU core usage | |||
#- diskio # Disk IO | |||
#- filesystem # File system usage for each mountpoint |
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.
You probably need to rebase on master to get rid of this diff.
"rtt": 115 | ||
}, | ||
"postgresql": { | ||
"statements": { |
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.
Should the metricset be called statement
? Because each even only contains one statement.
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.
I'd agree in general with that, but if we keep it as statements
then all metricsets follow the exact naming of pg stats tables (pg_stat_activity
, pg_stat_database
, pg_stat_bgwriter
and pg_stat_statements
).
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.
In general I would prefer the the naming convention superseed service specific namings: https://www.elastic.co/guide/en/beats/devguide/current/event-conventions.html This provides a unified querying experience on the consumer side.
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.
Ok, go for statement
then.
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.
It mostly LGTM, but I'd add it as beta, and disabled by default.
func init() { | ||
mb.Registry.MustAddMetricSet("postgresql", "statements", New, | ||
mb.WithHostParser(postgresql.ParseURL), | ||
mb.DefaultMetricSet(), |
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.
Does it generate events on each executed statement? Maybe this is too much data to be enabled by default.
// New create a new instance of the MetricSet | ||
// Part of new is also setting up the configuration by processing additional | ||
// configuration entries if needed. | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { |
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.
Add this metricset as beta, for that print a warning here with something like:
cfgwarn.Beta("The statement metricset is beta")
And change release to beta in fields.yml.
Thanks for the review. I'll make the suggested changes shortly. |
876250f
to
45aceea
Compare
assert.Contains(t, event["user"].(common.MapStr), "id") | ||
|
||
assert.Contains(t, event, "database") | ||
db_oid := event["database"].(common.MapStr)["oid"].(int64) |
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.
don't use underscores in Go names; var db_oid should be dbOid
Where should I add a changelog? To the pull request decription? |
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.
Thanks for addressing the comments, but it seems that some code is missing after the rename of the metricset.
"metricset": { | ||
"host": "postgresql:5432", | ||
"module": "postgresql", | ||
"name": "statements", |
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.
statement
"rtt": 115 | ||
}, | ||
"postgresql": { | ||
"statements": { |
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.
statement
// Fetch methods implements the data gathering and data conversion to the right | ||
// format. It publishes the event which is then forwarded to the output. In case | ||
// of an error set the Error field of mb.Event or simply call report.Error(). | ||
func (m *MetricSet) Fetch(report mb.ReporterV2) { |
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.
The actual code for fetching is missing, but it was here in the previous versions 🤔
@zinefer changelog is in the |
find lost fetch code add changelog message catch rename stragglers
…beat-statements-metricset # Conflicts: # metricbeat/include/fields.go
Thanks for the help everyone! Hopefully I've added to the changelog correctly. |
CHANGELOG.asciidoc
Outdated
==== Added | ||
|
||
*MetricBeat* | ||
- Add postgresql statement metricset. {issue}7048[7048] {pull}7060[7060] |
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.
Add it to the existing "Added" section for version HEAD please 🙂
jenkins, test this please |
…beat-statements-metricset # Conflicts: # metricbeat/include/fields.go
@zinefer there seems to be a related test failing now 🤔 https://travis-ci.org/elastic/beats/jobs/386280791#L3561 |
Yeah, I'm on it. :) I need to enable Edit: Having an issue with my environment... |
Oh, tests pass now but there are conflicts in the fields file, could you please update your branch and |
…beat-statements-metricset # Conflicts: # metricbeat/include/fields.go
No problem. :) |
jenkins, test this please |
It looks good, let's wait to jenkins :) |
…beat-statements-metricset # Conflicts: # metricbeat/include/fields.go
jenkins, test this again, please |
@zinefer merged, thanks for your contribution! |
@zinefer are there additional steps needed to get this working? I'm running it now, and my logs show: Edit: I restarted everything and it picked up my configs. The error message is gone, but the Postgres metrics are not displayed anywhere... |
This pull request adds a new metricset,
statements
to the MetricBeat Postgres module.This metricset will poll
pg_stat_statements
and provide per-query statistic information which is not obtainable with just the currentactivity
anddatabase
metricsets.Related Issue #7048