Skip to content

Commit 71cf892

Browse files
authored
MongoDB appName & MySQL program_name (#291)
* Identify powersync in MongoDB connections. * Add `program_name` for MySQL. * Add changeset.
1 parent 96993bb commit 71cf892

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

.changeset/slow-hounds-walk.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@powersync/service-module-mongodb-storage': patch
3+
'@powersync/service-module-mongodb': patch
4+
'@powersync/service-module-mysql': patch
5+
'@powersync/lib-service-mongodb': patch
6+
'@powersync/service-core': patch
7+
'@powersync/service-image': patch
8+
---
9+
10+
Add 'powersync' as the app name for MongoDB and MySQL connections.

libs/lib-mongodb/src/db/mongo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as mongo from 'mongodb';
22
import * as timers from 'timers/promises';
33
import { BaseMongoConfigDecoded, normalizeMongoConfig } from '../types/types.js';
4-
import { validateIpHostname } from '@powersync/lib-services-framework';
54

65
/**
76
* Time for new connection to timeout.
@@ -33,6 +32,9 @@ export interface MongoConnectionOptions {
3332
maxPoolSize: number;
3433
}
3534

35+
/**
36+
* Create a MongoClient for the storage database.
37+
*/
3638
export function createMongoClient(config: BaseMongoConfigDecoded, options?: MongoConnectionOptions) {
3739
const normalized = normalizeMongoConfig(config);
3840
return new mongo.MongoClient(normalized.uri, {
@@ -47,6 +49,9 @@ export function createMongoClient(config: BaseMongoConfigDecoded, options?: Mong
4749
// How long to wait for new primary selection
4850
serverSelectionTimeoutMS: 30_000,
4951

52+
// Identify the client
53+
appName: 'powersync-storage',
54+
5055
lookup: normalized.lookup,
5156

5257
// Avoid too many connections:

modules/module-mongodb-storage/src/storage/implementation/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function replicaIdToSubkey(table: bson.ObjectId, id: storage.ReplicaId):
107107
/**
108108
* Helper function for creating a MongoDB client from consumers of this package
109109
*/
110-
export const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
110+
const createMongoClient = (url: string, options?: mongo.MongoClientOptions) => {
111111
return new mongo.MongoClient(url, options);
112112
};
113113

modules/module-mongodb/src/replication/MongoManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { mongo } from '@powersync/lib-service-mongodb';
33
import { NormalizedMongoConnectionConfig } from '../types/types.js';
44
import { BSON_DESERIALIZE_DATA_OPTIONS } from '@powersync/service-core';
55

6+
/**
7+
* Manage a MongoDB source database connection.
8+
*/
69
export class MongoManager {
710
public readonly client: mongo.MongoClient;
811
public readonly db: mongo.Db;
@@ -26,6 +29,9 @@ export class MongoManager {
2629
// How long to wait for new primary selection
2730
serverSelectionTimeoutMS: 30_000,
2831

32+
// Identify the client
33+
appName: 'powersync',
34+
2935
// Avoid too many connections:
3036
// 1. It can overwhelm the source database.
3137
// 2. Processing too many queries in parallel can cause the process to run out of memory.

modules/module-mysql/src/replication/BinLogReplicationJob.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ export class BinLogReplicationJob extends replication.AbstractReplicationJob {
5555
// such as caused by cached PG schemas.
5656
const connectionManager = this.connectionFactory.create({
5757
// Pool connections are only used intermittently.
58-
idleTimeout: 30_000
58+
idleTimeout: 30_000,
59+
60+
connectAttributes: {
61+
// https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html
62+
// These do not appear to be supported by Zongji yet, so we only specify it here.
63+
// Query using `select * from performance_schema.session_connect_attrs`.
64+
program_name: 'powersync'
65+
66+
// _client_name and _client_version is specified by the driver
67+
}
5968
});
6069
try {
6170
await this.rateLimiter?.waitUntilAllowed({ signal: this.abortController.signal });

0 commit comments

Comments
 (0)