diff --git a/ChangeLog.md b/ChangeLog.md index 0b6558c8dee3a9440814e88080679ac4b246cecc..08456115ee05cedfe2c080cc6b86166e6642804a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,10 @@ +* 153 [bug] slawek + + Corrected an issue with fetching Stork events from the + databases running on PostgreSQL 10. Also, the Stork + server requires PostgreSQL version 10 or later. + (Gitlab #571) + * 152 [build] marcin Resolved an issue with building Stork packages in Docker on the MacOS. @@ -1099,4 +1106,4 @@ LEGEND * [perf] Performance related change. * [ui] User Interface change. -*: Backward incompatible or operational change. +*: Backward incompatible or operational change. \ No newline at end of file diff --git a/Rakefile b/Rakefile index 0349deda22c4c5c72a6b4c7848580780bdbda7d5..d82eedcad95481cd29fc0b5248ca859e60d6b724 100644 --- a/Rakefile +++ b/Rakefile @@ -955,6 +955,8 @@ if ENV['CHROME_BIN'] CHROME_DRV_VERSION = '87.0.4280.20' elsif out.include? '90.' CHROME_DRV_VERSION = '90.0.4430.72' + elsif out.include? '92.' + CHROME_DRV_VERSION = '92.0.4515.159' else CHROME_DRV_VERSION = "" puts "Cannot match Chrome browser version and chromedriver version" diff --git a/backend/server/database/connection.go b/backend/server/database/connection.go index 2fe23c8ac0de404ce92b275e1fa017d2a252add2..787ad90221394886e420eb1d1d0da9eb19194a45 100644 --- a/backend/server/database/connection.go +++ b/backend/server/database/connection.go @@ -13,6 +13,13 @@ import ( log "github.com/sirupsen/logrus" ) +// Minimal supported database Postgres server version. +const ( + minSupportedDatabaseServerVersionMajnor = 10 + minSupportedDatabaseServerVersionMinor = 0 + minSupportedDatabaseServerVersionPatch = 0 +) + type DBLogger struct{} // Hook run before SQL query execution. @@ -77,6 +84,31 @@ func NewPgDBConn(pgParams *pg.Options, tracing bool) (*PgDB, error) { if err != nil { return nil, pkgerrors.Wrapf(err, "unable to connect to the database using provided credentials") } + + // Check that a database version is supported + version, err := GetDatabaseServerVersion(db) + if err != nil { + return nil, err + } + + minVersion := minSupportedDatabaseServerVersionMajnor*100*100 + + minSupportedDatabaseServerVersionMinor*100 + + minSupportedDatabaseServerVersionPatch + + if version < minVersion { + currentPatch := version % 100 + currentMinor := (version / 100) % 100 + currentMajnor := version / (100 * 100) + + log.Warnf("unsupported database server version: got %d.%d.%d, required at least %d.%d.%d, "+ + "please consider upgrading Postgres server because Stork may not work correctly with this version", + currentMajnor, currentMinor, currentPatch, + minSupportedDatabaseServerVersionMajnor, + minSupportedDatabaseServerVersionMinor, + minSupportedDatabaseServerVersionPatch, + ) + } + return db, nil } @@ -153,3 +185,13 @@ func Transaction(dbIface interface{}) (tx *pg.Tx, rollback func(), commit func() } return tx, rollback, commit, err } + +// Fetch the connected Postgres version in numeric format. +func GetDatabaseServerVersion(db *PgDB) (int, error) { + var version int + _, err := db.QueryOne(pg.Scan(&version), "SELECT CAST(current_setting('server_version_num') AS integer)") + if err != nil { + return 0, err + } + return version, nil +} diff --git a/backend/server/database/model/event.go b/backend/server/database/model/event.go index cff0a13bc5fc1dc69672710d7f79957ffc71b1cf..47ce53a40c6273a63ba597f08ebf882857f94ed9 100644 --- a/backend/server/database/model/event.go +++ b/backend/server/database/model/event.go @@ -67,18 +67,18 @@ func GetEventsByPage(db *pg.DB, offset int64, limit int64, level int64, daemonTy q = q.Where("level >= ?", level) } if daemonType != nil { - q = q.Join("JOIN daemon ON daemon.id = CAST (relations->'DaemonID' AS INTEGER)") + q = q.Join("JOIN daemon ON daemon.id = CAST (relations->>'DaemonID' AS INTEGER)") q = q.Where("daemon.name = ?", daemonType) } if appType != nil { - q = q.Join("JOIN app ON app.id = CAST (relations->'AppID' AS INTEGER)") + q = q.Join("JOIN app ON app.id = CAST (relations->>'AppID' AS INTEGER)") q = q.Where("app.type = ?", appType) } if machineID != nil { - q = q.Where("CAST (relations->'MachineID' AS INTEGER) = ?", *machineID) + q = q.Where("CAST (relations->>'MachineID' AS INTEGER) = ?", *machineID) } if userID != nil { - q = q.Where("CAST (relations->'UserID' AS INTEGER) = ?", *userID) + q = q.Where("CAST (relations->>'UserID' AS INTEGER) = ?", *userID) } // prepare sorting expression, offset and limit diff --git a/backend/server/database/test/connection_test.go b/backend/server/database/test/connection_test.go index 9af5703f215fc674555d05eecd3c9f5441199409..b38be057542a269220c67c72865a0cd0d73effb2 100644 --- a/backend/server/database/test/connection_test.go +++ b/backend/server/database/test/connection_test.go @@ -43,3 +43,15 @@ func TestTransaction(t *testing.T) { // Those two pointers should point at the same object. require.Same(t, tx, tx2) } + +// Tests the logic that fetches database server version. +func TestGetDatabaseServerVersion(t *testing.T) { + db, _, teardown := SetupDatabaseTestCase(t) + defer teardown() + + version, err := dbops.GetDatabaseServerVersion(db) + + require.NoError(t, err) + require.GreaterOrEqual(t, version, 100000) + require.Less(t, version, 200000) +} diff --git a/doc/install.rst b/doc/install.rst index a833e235b3f46b920d4e39a42c1a5ff49bca4ad4..384273d5b42dd3c8fdbdc8692d7ab79e84e1f9bb 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -47,8 +47,9 @@ statistics. Stork uses Go implementation for handling TLS connections, certificates and keys. The secrets are stored in the PostgreSQL database, in the `secret` table. -For the ``Stork Server``, a PostgreSQL database (https://www.postgresql.org/) version 11 or later is required. It may work with -PostgreSQL 10, but this has not been tested. The general installation procedure for PostgreSQL is OS-specific and is not included +For the ``Stork Server``, a PostgreSQL database (https://www.postgresql.org/) version 10 +or later is required. Stork will attempt to run with older versions but may not work +correctly. The general installation procedure for PostgreSQL is OS-specific and is not included here. However, please note that Stork uses pgcrypto extensions, which often come in a separate package. For example, a postgresql-crypto package is required on Fedora and postgresql12-contrib is needed on RHEL and CentOS.