m-barthelemy / vapor-queues-fluent-driver

A Fluent implementation for https://github.com/vapor/queues (Vapor4)
MIT License
32 stars 16 forks source link

Provide a way to quieten the logging of UPDATE queries #31

Closed tonyarnold closed 11 months ago

tonyarnold commented 1 year ago

It would be amazing, and massively improve debugging of other issues if this driver had a way to quieten the update check SQL calls:

2023-06-15T06:16:59.731664+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:16:59 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "default", 2023-06-15 06:16:59 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:16:59.732230+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:16:59 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "delayed-emails", 2023-06-15 06:16:59 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:16:59.733279+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:16:59 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "default", 2023-06-15 06:16:59 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:17:00.730786+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:17:00 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "delayed-emails", 2023-06-15 06:17:00 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:17:00.732751+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:17:00 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "default", 2023-06-15 06:17:00 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:17:00.733279+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:17:00 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "delayed-emails", 2023-06-15 06:17:00 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
2023-06-15T06:17:00.734401+00:00 app[web.1]: [ DEBUG ] UPDATE "_jobs_meta" SET "state" = $1, "updated_at" = $2 WHERE "id" = (SELECT "id" FROM "_jobs_meta" WHERE "state" = $3 AND "queue" = $4 AND "run_at" <= $5 ORDER BY "run_at" ASC LIMIT 1 FOR UPDATE SKIP LOCKED) RETURNING "id" [[QueuesFluentDriver.QueuesFluentJobState.processing, 2023-06-15 06:17:00 +0000, QueuesFluentDriver.QueuesFluentJobState.pending, "default", 2023-06-15 06:17:00 +0000]] [database-id: psql] (PostgresKit/PostgresDatabase+SQL.swift:44)
m-barthelemy commented 1 year ago

Hi,

This driver fully reuses the Fluent DB configuration you have setup for your app. In that sense, it does not control or restrict what Fluent itself logs.

IIRC the default log level of Fluent is .trace which logs every single query. If you lower it to .debug for example, you shouldn't see any raw queries getting logged. Example:

app.databases.use(
    .postgres(
        hostname: "localhost", 
        username: "...", 
        password: "", 
        database: "...", 
        encoder: .init(), 
        sqlLogLevel: .debug // HERE
    ), 
    as: .psql,
    isDefault: true
)
tonyarnold commented 1 year ago

I understand that it's Fluent doing the logging - perhaps this is an issue better raised over on the FluentKit repository.