Skip to content
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

feat(NODE-4878): Add remaining log configurable client options #3908

Merged
merged 22 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7d47b8b
test
aditi-khare-mongoDB Sep 19, 2023
6ced6fd
please dont push
aditi-khare-mongoDB Sep 22, 2023
2143ba1
fixed package lock isue
aditi-khare-mongoDB Oct 11, 2023
5b6f0e9
Linting fixes and CI fixes
aditi-khare-mongoDB Oct 11, 2023
496efb1
Fixed failing tests
aditi-khare-mongoDB Oct 11, 2023
b5e88ad
sinon tests working
aditi-khare-mongoDB Oct 16, 2023
831afb7
PR requested changes 0 :
aditi-khare-mongoDB Nov 1, 2023
c5e1c8d
kickoff changes:
aditi-khare-mongoDB Nov 1, 2023
4d8f403
added functionality, missing tests
aditi-khare-mongoDB Nov 1, 2023
19b7932
mongo client changes
aditi-khare-mongoDB Nov 2, 2023
708ad94
basic testing added, need default testing
aditi-khare-mongoDB Nov 2, 2023
8810c5f
all unit tests added, ready for review
aditi-khare-mongoDB Nov 2, 2023
f7303e5
fixed rebase problems
aditi-khare-mongoDB Nov 3, 2023
aec08a5
Removed connection string support
aditi-khare-mongoDB Nov 3, 2023
959c3b9
Update src/connection_string.ts
aditi-khare-mongoDB Nov 6, 2023
6f95af9
Update test/unit/mongo_client.test.js
aditi-khare-mongoDB Nov 6, 2023
bd9c07f
added unit tests for maxDocumentLength:
aditi-khare-mongoDB Nov 6, 2023
3f2e6d6
PR requested changes
aditi-khare-mongoDB Nov 7, 2023
b45ab90
Additional changes
aditi-khare-mongoDB Nov 7, 2023
45d4249
Added new test case for unsigned int
aditi-khare-mongoDB Nov 7, 2023
4492003
Merge branch 'main' into NODE-4878/log-client-configurable-options
durran Nov 8, 2023
ff92af3
Merge branch 'main' into NODE-4878/log-client-configurable-options
W-A-James Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ export function parseOptions(
...mongoOptions[Symbol.for('@@mdb.internalLoggerConfig')]
};
loggerClientOptions = {
mongodbLogPath: mongoOptions.mongodbLogPath
mongodbLogPath: mongoOptions.mongodbLogPath,
mongodbLogComponentSeverities: mongoOptions.mongodbLogComponentSeverities,
mongodbLogMaxDocumentLength: mongoOptions.mongodbLogMaxDocumentLength
};
}
mongoOptions.mongoLoggerOptions = MongoLogger.resolveOptions(
Expand Down Expand Up @@ -1229,7 +1231,17 @@ export const OPTIONS = {
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogPath: { type: 'any' }
mongodbLogPath: { type: 'any' },
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogComponentSeverities: { type: 'any' },
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogMaxDocumentLength: { type: 'uint' }
} as Record<keyof MongoClientOptions, OptionDescriptor>;

export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export type {
} from './mongo_client';
export type {
Log,
LogComponentSeveritiesClientOptions,
LogConvertible,
Loggable,
LoggableEvent,
Expand Down
17 changes: 16 additions & 1 deletion src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import { MONGO_CLIENT_EVENTS } from './constants';
import { Db, type DbOptions } from './db';
import type { Encrypter } from './encrypter';
import { MongoInvalidArgumentError } from './error';
import { type MongoDBLogWritable, MongoLogger, type MongoLoggerOptions } from './mongo_logger';
import {
type LogComponentSeveritiesClientOptions,
type MongoDBLogWritable,
MongoLogger,
type MongoLoggerOptions
} from './mongo_logger';
import { TypedEventEmitter } from './mongo_types';
import { executeOperation } from './operations/execute_operation';
import { RunAdminCommandOperation } from './operations/run_command';
Expand Down Expand Up @@ -262,6 +267,16 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogComponentSeverities?: LogComponentSeveritiesClientOptions;
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongodbLogMaxDocumentLength?: number;

/** @internal */
[featureFlag: symbol]: any;
Expand Down
76 changes: 65 additions & 11 deletions src/mongo_logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,30 @@ export interface MongoLoggerEnvOptions {
MONGODB_LOG_PATH?: string;
}

/** @internal */
export interface LogComponentSeveritiesClientOptions {
/** Optional severity level for command component */
command?: SeverityLevel;
/** Optional severity level for topology component */
topology?: SeverityLevel;
/** Optionsl severity level for server selection component */
serverSelection?: SeverityLevel;
/** Optional severity level for connection component */
connection?: SeverityLevel;
/** Optional severity level for client component */
client?: SeverityLevel;
/** Optional default severity level to be used if any of the above are unset */
default?: SeverityLevel;
}

/** @internal */
export interface MongoLoggerMongoClientOptions {
/** Destination for log messages */
mongodbLogPath?: 'stdout' | 'stderr' | MongoDBLogWritable;
/** Severity levels for logger components */
mongodbLogComponentSeverities?: LogComponentSeveritiesClientOptions;
/** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
mongodbLogMaxDocumentLength?: number;
}

/** @internal */
Expand All @@ -148,7 +168,6 @@ export interface MongoLoggerOptions {
/** Default severity level to be used if any of the above are unset */
default: SeverityLevel;
};

/** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
maxDocumentLength: number;
/** Destination for log messages. */
Expand Down Expand Up @@ -219,6 +238,18 @@ function resolveLogPath(
return createStdioLogger(process.stderr);
}

function resolveSeverityConfiguration(
clientOption: string | undefined,
environmentOption: string | undefined,
defaultSeverity: SeverityLevel
): SeverityLevel {
return (
parseSeverityFromString(clientOption) ??
parseSeverityFromString(environmentOption) ??
defaultSeverity
);
}

/** @internal */
export interface Log extends Record<string, any> {
t: Date;
Expand Down Expand Up @@ -522,22 +553,45 @@ export class MongoLogger {
...clientOptions,
mongodbLogPath: resolveLogPath(envOptions, clientOptions)
};
const defaultSeverity =
parseSeverityFromString(combinedOptions.MONGODB_LOG_ALL) ?? SeverityLevel.OFF;
const defaultSeverity = resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.default,
combinedOptions.MONGODB_LOG_ALL,
SeverityLevel.OFF
);

return {
componentSeverities: {
command: parseSeverityFromString(combinedOptions.MONGODB_LOG_COMMAND) ?? defaultSeverity,
topology: parseSeverityFromString(combinedOptions.MONGODB_LOG_TOPOLOGY) ?? defaultSeverity,
serverSelection:
parseSeverityFromString(combinedOptions.MONGODB_LOG_SERVER_SELECTION) ?? defaultSeverity,
connection:
parseSeverityFromString(combinedOptions.MONGODB_LOG_CONNECTION) ?? defaultSeverity,
client: parseSeverityFromString(combinedOptions.MONGODB_LOG_CLIENT) ?? defaultSeverity,
command: resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.command,
combinedOptions.MONGODB_LOG_COMMAND,
defaultSeverity
),
topology: resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.topology,
combinedOptions.MONGODB_LOG_TOPOLOGY,
defaultSeverity
),
serverSelection: resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.serverSelection,
combinedOptions.MONGODB_LOG_SERVER_SELECTION,
defaultSeverity
),
connection: resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.connection,
combinedOptions.MONGODB_LOG_CONNECTION,
defaultSeverity
),
client: resolveSeverityConfiguration(
combinedOptions.mongodbLogComponentSeverities?.client,
combinedOptions.MONGODB_LOG_CLIENT,
defaultSeverity
),
default: defaultSeverity
},
maxDocumentLength:
parseUnsignedInteger(combinedOptions.MONGODB_LOG_MAX_DOCUMENT_LENGTH) ?? 1000,
combinedOptions.mongodbLogMaxDocumentLength ??
parseUnsignedInteger(combinedOptions.MONGODB_LOG_MAX_DOCUMENT_LENGTH) ??
1000,
logDestination: combinedOptions.mongodbLogPath
};
}
Expand Down
Loading