Bug 1429861 - [RFE] Pass engine database credentials for postgresql collectd plugin
Summary: [RFE] Pass engine database credentials for postgresql collectd plugin
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-metrics
Classification: oVirt
Component: RFEs
Version: 1.0.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ovirt-4.1.3
: 1.0.4.2
Assignee: Yedidyah Bar David
QA Contact: Lukas Svaty
URL:
Whiteboard:
Depends On:
Blocks: oVirt-Metrics-and-Logs 1451625 1456459
TreeView+ depends on / blocked
 
Reported: 2017-03-07 10:20 UTC by Shirly Radco
Modified: 2017-07-06 13:41 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
With this update, ovirt-engine-metrics can now configure collectd to connect to the Red Hat Virtualization Manager's postgresql database and get information from it. Previously, making collectd connect to the postgresql database did not work and was disabled by BZ#1436001.
Clone Of:
Environment:
Last Closed: 2017-07-06 13:41:39 UTC
oVirt Team: Integration
Embargoed:
rule-engine: ovirt-4.1+
rule-engine: exception+
ylavi: planning_ack+
sbonazzo: devel_ack+
lsvaty: testing_ack+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 74876 0 master MERGED Pass engine db credentials to collectd-postgresql 2020-05-04 12:00:08 UTC
oVirt gerrit 74886 0 master ABANDONED Configure collectd-postgresql 2020-05-04 12:00:08 UTC
oVirt gerrit 76947 0 master MERGED create_collectd_pg_pass.sh: Fix path for selinux fcontext 2020-05-04 12:00:08 UTC

Description Shirly Radco 2017-03-07 10:20:41 UTC
Description of problem:
The postgresql collectd plugin requires the engine database name, host, user and password, in order to query it.

We need to add a way for the collectd.conf can consume this information.

Comment 1 Yedidyah Bar David 2017-03-07 10:34:41 UTC
We might be able to do this by making engine-setup create a file [1] with something like:

[Service]
ExecStartPre=/path/to/create_pgpass.sh
Environment=PGHOST=dbhost
Environment=PGPORT=dbport
Environment=PGDATABASE=dbname
Environment=PGUSER=dbuser
Environment=PGPASSFILE=[2]

where /path/to/create_pgpass.sh will be a script that securely creates pgpass in [2] and the other credentials are copied from existing.

[1] /etc/systemd/system/collectd.service.d/postgresql.conf
[2] /var/lib/ovirt-collectd/pgpass/engine.pgpass

Comment 2 Yaniv Kaul 2017-03-08 06:53:17 UTC
Isn't a read only account sufficient?

Comment 3 Shirly Radco 2017-03-08 13:05:03 UTC
(In reply to Yaniv Kaul from comment #2)
> Isn't a read only account sufficient?

I think it is a good solution for user and password.
But we need to maintain the host and db name in case they change.
With the solution Didi is proposing it should be easier in case of an update.

Comment 4 Yedidyah Bar David 2017-03-08 13:50:55 UTC
(In reply to Shirly Radco from comment #3)
> (In reply to Yaniv Kaul from comment #2)
> > Isn't a read only account sufficient?

Probably yes, depending on what we want to do there.

> 
> I think it is a good solution for user and password.
> But we need to maintain the host and db name in case they change.
> With the solution Didi is proposing it should be easier in case of an update.

Indeed.

If we want to allow using custom credentials, and use comment 1, it might be enough for the user to add another similar file to /etc/systemd/system/collectd.service.d/ with these credentials, need to check about the order. I guess last wins, so would name it zzz-postgresql.conf. Perhaps we should name ours 10-postgresql.conf for more explicit ordering.

Comment 5 Shirly Radco 2017-03-26 13:48:45 UTC
Yaniv, Do we want to support local db only? 
If yes, It will require adding its config file only for local db installations.

Comment 6 Shirly Radco 2017-03-28 10:25:13 UTC
(In reply to Shirly Radco from comment #5)
> Yaniv, Do we want to support local db only? 
> If yes, It will require adding its config file only for local db
> installations.

We discussed in scrub meeting. We will add it only to local db.

Comment 7 Yedidyah Bar David 2017-03-28 13:05:44 UTC
Note: There is no (simple/robust) way to know if the db is local. We'll test if its host equals 'localhost', which is what engine-setup configures if choosing 'Local'. This means, among other things, that users that chose "Remote", then input e.g. '127.0.0.1', will cause their db to be considered remote. OK?

Comment 8 Shirly Radco 2017-03-28 14:03:48 UTC
(In reply to Yedidyah Bar David from comment #7)
> Note: There is no (simple/robust) way to know if the db is local. We'll test
> if its host equals 'localhost', which is what engine-setup configures if
> choosing 'Local'. This means, among other things, that users that chose
> "Remote", then input e.g. '127.0.0.1', will cause their db to be considered
> remote. OK?

Can we check both localhost and '127.0.0.1' ?

Comment 9 Yedidyah Bar David 2017-03-28 14:28:03 UTC
(In reply to Shirly Radco from comment #8)
> Can we check both localhost and '127.0.0.1' ?

We can do whatever we want, but why?

A default setup using automatic provisioning will have 'localhost'.

Users doing anything else, most likely have their reasons.

Personally I do not see why we should monitor only if local. I didn't attend the meeting in which this was decided, sorry - but perhaps the reason should be documented here as well.

If we go that route, do we also check other less or more complex options? E.g. you can have in /etc/hosts '127.0.0.1 localhost dbserver' and use 'dbserver'. If you then want us to also consider that one as local, we need to also lookup. And you can also obviously set it to an address of another interface of the local machine.

Thinking about this, I think we'll allow enforcing this anyway, so that users that want to monitor the db can do that regardless of where it is.

Comment 10 Yedidyah Bar David 2017-03-30 14:02:07 UTC
Shirly opened another bug for this, bug 1436598. So I think we can move the discussion there.

Comment 11 Lukas Svaty 2017-04-10 11:04:19 UTC
From bug regarding creating different files for postgres load BZ#1436001:

 we need to tackle renaming this file to standard priority format 40-postgresql.conf and also filling the file, as it at the moment only contains loading of the plugin:

[root@ls-engine1 ~]# cat /etc/collectd.d/postgresql.conf 
LoadPlugin postgresql

Comment 12 Yaniv Lavi 2017-04-20 10:38:57 UTC
(In reply to Yedidyah Bar David from comment #9)
> 
> Personally I do not see why we should monitor only if local. I didn't attend
> the meeting in which this was decided, sorry - but perhaps the reason should
> be documented here as well.
> 

- We can not assume we are the owners of the postgres and have permission to the stats. 
- Most likely it is monitored on the remote site 
- We need to be able to work out of the box and not have collectd fail on no prmissions to stats table for example.

Comment 13 Yedidyah Bar David 2017-04-20 11:59:49 UTC
(In reply to Yaniv Dary from comment #12)
> - We can not assume we are the owners of the postgres and have permission to
> the stats. 

Indeed, and this is true also for a local db. We are going to use engine db creds, which should work the same whether local or remote.

> - Most likely it is monitored on the remote site 

Indeed. But IMO there is some added value in monitoring and keeping stats etc. in our own store even then. E.g. one day we might base decisions on these stats, and would like to be able to make these decisions also for remote dbs.

> - We need to be able to work out of the box and not have collectd fail on no
> prmissions to stats table for example.

See above.

Do we need permissions that the engine db user does not have? If so, I suggest to open a bug for that and we'll discuss it there. For current bug, I suggest to start with queries that the engine user can query.

Comment 14 Yedidyah Bar David 2017-04-24 10:16:02 UTC
Seems like we already have bug 1436598 for this - please reply there. Thanks. For current bug I do not separate remote/local.

Comment 15 Yedidyah Bar David 2017-05-14 05:25:35 UTC
Lukas, why move from post to assigned/failedqa? Patch is still pending merge.

Comment 16 Lukas Svaty 2017-05-15 07:42:02 UTC
hmm, seem like a wrong updated bug, moving back to post, sorry for the inconvenience

Comment 17 Yedidyah Bar David 2017-05-17 13:28:39 UTC
Sorry, Shirly found a bug.

Comment 18 Yedidyah Bar David 2017-05-28 10:15:16 UTC
Note to QE: Please test this with both local and remote db. Verify that you do not get errors in collectd logs (perhaps syslog) about connecting to db.

Comment 19 Lukas Svaty 2017-06-21 12:24:00 UTC
tested with local and remote database both reporting correctly by plugin postgresql searchable by collectd.plugin == postgresql

these value types:
"type": "pg_db_size"
"type": "pg_blks", "
"type": "pg_n_tup_g"
"type": "pg_xact"

last two with different type_instances

Is this correct? Or should we expect some information regarding data in tables as well, I dont see it configured in the collectd config anyway.

Example sample:
{
  "_index": "ovirt-metrics-2017.06.21",
  "_type": "fluentd",
  "_id": "AVzKmJd-GNi9AvMt77i4",
  "_score": null,
  "_source": {
    "hostname": "ls-example.com",
    "collectd": {
      "dstypes": [
        "derive"
      ],
      "interval": 10,
      "plugin": "postgresql",
      "plugin_instance": "engine",
      "type": "pg_blks",
      "type_instance": "heap_hit",
      "postgresql": {
        "pg_blks": 2.69932371916975
      }
    },
    "tag": "project.ovirt-metrics-engine",
    "ovirt": {
      "entity": "engine"
    },
    "ipaddr4": "10.34.63.61",
    "ipaddr6": "2620:52:0:223c:21a:4aff:fe80:3f6c",
    "@timestamp": "2017-06-21T14:20:03+02:00"
  },
  "fields": {
    "@timestamp": [
      1498047603000
    ]
  },
  "highlight": {
    "collectd.plugin": [
      "@kibana-highlighted-field@postgresql@/kibana-highlighted-field@"
    ]
  },
  "sort": [
    1498047603000
  ]
}

Comment 20 Lukas Svaty 2017-06-21 12:24:45 UTC
moving to VERIFIED for now, if you believe further verification is requried please reopen

Comment 21 Yedidyah Bar David 2017-06-21 13:00:38 UTC
IMO Current bug is only about making collectd able to access engine's db (automatically, unlike when verifying bug 1434570).

Perhaps your question should be asked in the scope of bug 1436087, or a new bug.

Moving needinfo to Shirly for review.

Comment 22 Shirly Radco 2017-06-22 07:24:30 UTC
Answered in bug 1436087.

Comment 23 Megan Lewis 2017-07-05 04:50:57 UTC
The documentation updates for this bug is being tracked in https://bugzilla.redhat.com/show_bug.cgi?id=1451625


Note You need to log in before you can comment on or make changes to this bug.