Skip to content

Commit 7b92f05

Browse files
committed
JSCBC-1363: Split orphan reporter config from tracing config
Motivation ========== With a future release of the C++ core, the orphan reporting config will split out from the tracing config. As the Node client only recently added the tracing and metrics config it would be ideal to premptively split the config options in order to prevent having to deprecate the orphan reporting options w/in the tracing options. Changes ======= * Add OrphanReporterConfig * Update bindings to handle separate orphan reporting config Change-Id: Ibcb5c574b76fde95815d72f5d33ce0a02ca5b87d Reviewed-on: https://review.couchbase.org/c/couchnode/+/234372 Tested-by: Jared Casey <[email protected]> Reviewed-by: Dimitris Christodoulou <[email protected]>
1 parent 4397ae3 commit 7b92f05

File tree

3 files changed

+72
-39
lines changed

3 files changed

+72
-39
lines changed

lib/binding.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export interface CppTracingConfig {
4040
enableTracing?: boolean
4141
emitInterval?: number
4242
sampleSize?: number
43-
orphanEmitInterval?: number
44-
orphanSampleSize?: number
4543
kvThreshold?: number
4644
queryThreshold?: number
4745
searchThreshold?: number
@@ -51,6 +49,11 @@ export interface CppTracingConfig {
5149
viewsThreshold?: number
5250
}
5351

52+
export interface CppOrphanReporterConfig {
53+
emitInterval?: number
54+
sampleSize?: number
55+
}
56+
5457
export interface CppMetricsConfig {
5558
enableMetrics?: boolean
5659
emitInterval?: number
@@ -3545,6 +3548,7 @@ export interface CppConnection extends CppConnectionAutogen {
35453548
dnsOptions: CppDnsConfig | null,
35463549
appTelemetryOptions: CppAppTelemetryConfig | null,
35473550
tracingOptions: CppTracingConfig | null,
3551+
orphanReporterOptions: CppOrphanReporterConfig | null,
35483552
metricsOptions: CppMetricsConfig | null,
35493553
callback: (err: CppError | null) => void
35503554
): void

lib/cluster.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,6 @@ export interface TracingConfig {
196196
*/
197197
sampleSize?: number
198198

199-
/**
200-
* Specifies the interval after which the aggregated orphaned response information is logged, specified in millseconds.
201-
* Defaults to 10000 (10 seconds) if not specified.
202-
*/
203-
orphanEmitInterval?: number
204-
205-
/**
206-
* Specifies how many orphaned response entries to sample per service in each emit interval.
207-
* Defaults to 64 if not specified.
208-
*/
209-
orphanSampleSize?: number
210-
211199
/**
212200
* Threshold over which the request is taken into account for the KV service, specified in millseconds.
213201
* Defaults to 500ms if not specified.
@@ -251,6 +239,27 @@ export interface TracingConfig {
251239
viewsThreshold?: number
252240
}
253241

242+
/**
243+
* Specifies orphan report logging options for the client.
244+
*
245+
* NOTE: These options are used to configure the underlying C++ core orphan report logging.
246+
*
247+
* @category Core
248+
*/
249+
export interface OrphanReporterConfig {
250+
/**
251+
* Specifies the interval after which the aggregated orphaned response information is logged, specified in millseconds.
252+
* Defaults to 10000 (10 seconds) if not specified.
253+
*/
254+
emitInterval?: number
255+
256+
/**
257+
* Specifies how many orphaned response entries to sample per service in each emit interval.
258+
* Defaults to 64 if not specified.
259+
*/
260+
sampleSize?: number
261+
}
262+
254263
/**
255264
* Specifies metrics logging options for the client.
256265
*
@@ -350,6 +359,11 @@ export interface ConnectOptions {
350359
*/
351360
tracingConfig?: TracingConfig
352361

362+
/**
363+
* Specifies the orphan report logging config for connections of this cluster.
364+
*/
365+
orphanReporterConfig?: OrphanReporterConfig
366+
353367
/**
354368
* Specifies the metrics config for connections of this cluster.
355369
*/
@@ -386,6 +400,7 @@ export class Cluster {
386400
private _preferredServerGroup: string | undefined
387401
private _appTelemetryConfig: AppTelemetryConfig | null
388402
private _tracingConfig: TracingConfig | null
403+
private _orphanReporterConfig: OrphanReporterConfig | null
389404
private _metricsConfig: MetricsConfig | null
390405

391406
/**
@@ -591,8 +606,6 @@ export class Cluster {
591606
enableTracing: options.tracingConfig.enableTracing,
592607
emitInterval: options.tracingConfig.emitInterval,
593608
sampleSize: options.tracingConfig.sampleSize,
594-
orphanEmitInterval: options.tracingConfig.orphanEmitInterval,
595-
orphanSampleSize: options.tracingConfig.orphanSampleSize,
596609
kvThreshold: options.tracingConfig.kvThreshold,
597610
queryThreshold: options.tracingConfig.queryThreshold,
598611
searchThreshold: options.tracingConfig.searchThreshold,
@@ -605,6 +618,16 @@ export class Cluster {
605618
this._tracingConfig = null
606619
}
607620

621+
if (options.orphanReporterConfig) {
622+
// TODO(JSCBC-1364): Add enableReporting to config when supported in C++ core
623+
this._orphanReporterConfig = {
624+
emitInterval: options.orphanReporterConfig.emitInterval,
625+
sampleSize: options.orphanReporterConfig.sampleSize,
626+
}
627+
} else {
628+
this._orphanReporterConfig = null
629+
}
630+
608631
if (options.metricsConfig) {
609632
this._metricsConfig = {
610633
enableMetrics: options.metricsConfig.enableMetrics,
@@ -975,6 +998,7 @@ export class Cluster {
975998
this._dnsConfig,
976999
this._appTelemetryConfig,
9771000
this._tracingConfig,
1001+
this._orphanReporterConfig,
9781002
this._metricsConfig,
9791003
(cppErr) => {
9801004
if (cppErr) {

src/connection.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Napi::Value Connection::jsConnect(const Napi::CallbackInfo &info)
279279
{
280280
auto connstr = info[0].ToString().Utf8Value();
281281
auto credentialsJsObj = info[1].As<Napi::Object>();
282-
auto callbackJsFn = info[6].As<Napi::Function>();
282+
auto callbackJsFn = info[7].As<Napi::Function>();
283283

284284
auto connstrInfo = couchbase::core::utils::parse_connection_string(connstr);
285285
auto creds =
@@ -343,16 +343,16 @@ Napi::Value Connection::jsConnect(const Napi::CallbackInfo &info)
343343
}
344344
}
345345

346+
couchbase::core::tracing::threshold_logging_options tracing_options{};
347+
bool has_tracing_options = false;
348+
346349
if (!info[4].IsNull()) {
347350
auto jsTracingConfigObj = info[4].As<Napi::Object>();
348351
auto jsEnableTracing = jsTracingConfigObj.Get("enableTracing");
349352
if (!(jsEnableTracing.IsNull() || jsEnableTracing.IsUndefined())) {
350353
connstrInfo.options.enable_tracing =
351354
js_to_cbpp<bool>(jsEnableTracing);
352355
}
353-
couchbase::core::tracing::threshold_logging_options tracing_options{};
354-
bool has_tracing_options = false;
355-
356356
auto jsEmitInterval = jsTracingConfigObj.Get("emitInterval");
357357
if (!(jsEmitInterval.IsNull() || jsEmitInterval.IsUndefined())) {
358358
tracing_options.threshold_emit_interval =
@@ -365,21 +365,6 @@ Napi::Value Connection::jsConnect(const Napi::CallbackInfo &info)
365365
js_to_cbpp<std::size_t>(jsSampleSize);
366366
has_tracing_options = true;
367367
}
368-
auto jsOrphanEmitInterval =
369-
jsTracingConfigObj.Get("orphanEmitInterval");
370-
if (!(jsOrphanEmitInterval.IsNull() ||
371-
jsOrphanEmitInterval.IsUndefined())) {
372-
tracing_options.orphaned_emit_interval =
373-
js_to_cbpp<std::chrono::milliseconds>(jsOrphanEmitInterval);
374-
has_tracing_options = true;
375-
}
376-
auto jsOrphanSampleSize = jsTracingConfigObj.Get("orphanSampleSize");
377-
if (!(jsOrphanSampleSize.IsNull() ||
378-
jsOrphanSampleSize.IsUndefined())) {
379-
tracing_options.orphaned_sample_size =
380-
js_to_cbpp<std::size_t>(jsOrphanSampleSize);
381-
has_tracing_options = true;
382-
}
383368
auto jsKvThreshold = jsTracingConfigObj.Get("kvThreshold");
384369
if (!(jsKvThreshold.IsNull() || jsKvThreshold.IsUndefined())) {
385370
tracing_options.key_value_threshold =
@@ -427,14 +412,34 @@ Napi::Value Connection::jsConnect(const Napi::CallbackInfo &info)
427412
js_to_cbpp<std::chrono::milliseconds>(jsViewsThreshold);
428413
has_tracing_options = true;
429414
}
415+
}
430416

431-
if (has_tracing_options) {
432-
connstrInfo.options.tracing_options = tracing_options;
417+
if (!info[5].IsNull()) {
418+
auto jsOrphanReporterConfigObj = info[5].As<Napi::Object>();
419+
// TODO(JSCBC-1364): Migrate to orphan reporting config when available in C++ core
420+
auto jsOrphanEmitInterval =
421+
jsOrphanReporterConfigObj.Get("emitInterval");
422+
if (!(jsOrphanEmitInterval.IsNull() ||
423+
jsOrphanEmitInterval.IsUndefined())) {
424+
tracing_options.orphaned_emit_interval =
425+
js_to_cbpp<std::chrono::milliseconds>(jsOrphanEmitInterval);
426+
has_tracing_options = true;
427+
}
428+
auto jsOrphanSampleSize = jsOrphanReporterConfigObj.Get("sampleSize");
429+
if (!(jsOrphanSampleSize.IsNull() ||
430+
jsOrphanSampleSize.IsUndefined())) {
431+
tracing_options.orphaned_sample_size =
432+
js_to_cbpp<std::size_t>(jsOrphanSampleSize);
433+
has_tracing_options = true;
433434
}
434435
}
435436

436-
if (!info[5].IsNull()) {
437-
auto jsMetricsConfigObj = info[5].As<Napi::Object>();
437+
if (has_tracing_options) {
438+
connstrInfo.options.tracing_options = tracing_options;
439+
}
440+
441+
if (!info[6].IsNull()) {
442+
auto jsMetricsConfigObj = info[6].As<Napi::Object>();
438443
auto jsEnableMetrics = jsMetricsConfigObj.Get("enableMetrics");
439444
if (!(jsEnableMetrics.IsNull() || jsEnableMetrics.IsUndefined())) {
440445
connstrInfo.options.enable_metrics =

0 commit comments

Comments
 (0)