Skip to content

Commit b208b09

Browse files
committed
JSCBC-1362: Add tracing and metrics configuration to ConnectOptions
Motivation ---------- While the SDK does not yet support distributed tracing (JSCBC-1040), the underlying C++ core does have threshold logging, metrics logging and orphan response logging. Threshold and metrics logging can be disabled and each logger has various configuration options available. This change gives users the ability to tune the underlying loggers. Changes ------- * Add TracingConfig to ConnectOptions * Add MetricsConfig to ConnectionOptions * Pass the tracing and metrics configurations onto the underlying C++ core Change-Id: Ib0e26fdca90aafd29fc3c0a1e31793d975f54fe7 Reviewed-on: https://review.couchbase.org/c/couchnode/+/233865 Tested-by: Jared Casey <[email protected]> Reviewed-by: Mateusz <[email protected]>
1 parent e44f281 commit b208b09

File tree

3 files changed

+274
-1
lines changed

3 files changed

+274
-1
lines changed

lib/binding.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ export interface CppAppTelemetryConfig {
3636
pingTimeout?: number
3737
}
3838

39+
export interface CppTracingConfig {
40+
enableTracing?: boolean
41+
emitInterval?: number
42+
sampleSize?: number
43+
orphanEmitInterval?: number
44+
orphanSampleSize?: number
45+
kvThreshold?: number
46+
queryThreshold?: number
47+
searchThreshold?: number
48+
analyticsThreshold?: number
49+
managementThreshold?: number
50+
eventingThreshold?: number
51+
viewsThreshold?: number
52+
}
53+
54+
export interface CppMetricsConfig {
55+
enableMetrics?: boolean
56+
emitInterval?: number
57+
}
58+
3959
export interface CppDocumentId {
4060
bucket: string
4161
scope: string
@@ -3524,6 +3544,8 @@ export interface CppConnection extends CppConnectionAutogen {
35243544
credentials: CppClusterCredentials,
35253545
dnsOptions: CppDnsConfig | null,
35263546
appTelemetryOptions: CppAppTelemetryConfig | null,
3547+
tracingOptions: CppTracingConfig | null,
3548+
metricsOptions: CppMetricsConfig | null,
35273549
callback: (err: CppError | null) => void
35283550
): void
35293551
shutdown(callback: (err: CppError | null) => void): void

lib/cluster.ts

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,108 @@ export interface AppTelemetryConfig {
170170
pingTimeout?: number
171171
}
172172

173+
/**
174+
* Specifies threshold logging options for the client.
175+
*
176+
* NOTE: These options are used to configure the underlying C++ core threshold logging.
177+
*
178+
* @category Core
179+
*/
180+
export interface TracingConfig {
181+
/**
182+
* Specifies to enable or disable threshold logging.
183+
* Defaults to true (enabled) if not specified.
184+
*/
185+
enableTracing?: boolean
186+
187+
/**
188+
* Specifies the interval after which the aggregated trace information is logged, specified in millseconds.
189+
* Defaults to 10000 (10 seconds) if not specified.
190+
*/
191+
emitInterval?: number
192+
193+
/**
194+
* Specifies how many entries to sample per service in each emit interval.
195+
* Defaults to 64 if not specified.
196+
*/
197+
sampleSize?: number
198+
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+
211+
/**
212+
* Threshold over which the request is taken into account for the KV service, specified in millseconds.
213+
* Defaults to 500ms if not specified.
214+
*/
215+
kvThreshold?: number
216+
217+
/**
218+
* Threshold over which the request is taken into account for the query service, specified in millseconds.
219+
* Defaults to 1000ms if not specified.
220+
*/
221+
queryThreshold?: number
222+
223+
/**
224+
* Threshold over which the request is taken into account for the search service, specified in millseconds.
225+
* Defaults to 1000ms if not specified.
226+
*/
227+
searchThreshold?: number
228+
229+
/**
230+
* Threshold over which the request is taken into account for the analytics service, specified in millseconds.
231+
* Defaults to 1000ms if not specified.
232+
*/
233+
analyticsThreshold?: number
234+
235+
/**
236+
* Threshold over which the request is taken into account for management operations, specified in millseconds.
237+
* Defaults to 1000ms if not specified.
238+
*/
239+
managementThreshold?: number
240+
241+
/**
242+
* Threshold over which the request is taken into account for eventing service, specified in millseconds.
243+
* Defaults to 1000ms if not specified.
244+
*/
245+
eventingThreshold?: number
246+
247+
/**
248+
* Threshold over which the request is taken into account for the views service, specified in millseconds.
249+
* Defaults to 1000ms if not specified.
250+
*/
251+
viewsThreshold?: number
252+
}
253+
254+
/**
255+
* Specifies metrics logging options for the client.
256+
*
257+
* NOTE: These options are used to configure the underlying C++ core metrics logging.
258+
*
259+
* @category Core
260+
*/
261+
export interface MetricsConfig {
262+
/**
263+
* Specifies to enable or disable metrics logging.
264+
* Defaults to true (enabled) if not specified.
265+
*/
266+
enableMetrics?: boolean
267+
268+
/**
269+
* Specifies the interval after which metrics information is logged, specified in millseconds.
270+
* Defaults to 10 minutes if not specified.
271+
*/
272+
emitInterval?: number
273+
}
274+
173275
/**
174276
* Specifies the options which can be specified when connecting
175277
* to a cluster.
@@ -242,6 +344,16 @@ export interface ConnectOptions {
242344
*
243345
*/
244346
appTelemetryConfig?: AppTelemetryConfig
347+
348+
/**
349+
* Specifies the tracing (threshold logging) config for connections of this cluster.
350+
*/
351+
tracingConfig?: TracingConfig
352+
353+
/**
354+
* Specifies the metrics config for connections of this cluster.
355+
*/
356+
metricsConfig?: MetricsConfig
245357
}
246358

247359
/**
@@ -273,6 +385,8 @@ export class Cluster {
273385
private _dnsConfig: DnsConfig | null
274386
private _preferredServerGroup: string | undefined
275387
private _appTelemetryConfig: AppTelemetryConfig | null
388+
private _tracingConfig: TracingConfig | null
389+
private _metricsConfig: MetricsConfig | null
276390

277391
/**
278392
* @internal
@@ -472,6 +586,34 @@ export class Cluster {
472586
this._appTelemetryConfig = null
473587
}
474588

589+
if (options.tracingConfig) {
590+
this._tracingConfig = {
591+
enableTracing: options.tracingConfig.enableTracing,
592+
emitInterval: options.tracingConfig.emitInterval,
593+
sampleSize: options.tracingConfig.sampleSize,
594+
orphanEmitInterval: options.tracingConfig.orphanEmitInterval,
595+
orphanSampleSize: options.tracingConfig.orphanSampleSize,
596+
kvThreshold: options.tracingConfig.kvThreshold,
597+
queryThreshold: options.tracingConfig.queryThreshold,
598+
searchThreshold: options.tracingConfig.searchThreshold,
599+
analyticsThreshold: options.tracingConfig.analyticsThreshold,
600+
managementThreshold: options.tracingConfig.managementThreshold,
601+
eventingThreshold: options.tracingConfig.eventingThreshold,
602+
viewsThreshold: options.tracingConfig.viewsThreshold,
603+
}
604+
} else {
605+
this._tracingConfig = null
606+
}
607+
608+
if (options.metricsConfig) {
609+
this._metricsConfig = {
610+
enableMetrics: options.metricsConfig.enableMetrics,
611+
emitInterval: options.metricsConfig.emitInterval,
612+
}
613+
} else {
614+
this._metricsConfig = null
615+
}
616+
475617
this._openBuckets = []
476618
this._conn = new binding.Connection()
477619
}
@@ -832,6 +974,8 @@ export class Cluster {
832974
authOpts,
833975
this._dnsConfig,
834976
this._appTelemetryConfig,
977+
this._tracingConfig,
978+
this._metricsConfig,
835979
(cppErr) => {
836980
if (cppErr) {
837981
const err = errorFromCpp(cppErr)

src/connection.cpp

Lines changed: 108 additions & 1 deletion
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[4].As<Napi::Function>();
282+
auto callbackJsFn = info[6].As<Napi::Function>();
283283

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

346+
if (!info[4].IsNull()) {
347+
auto jsTracingConfigObj = info[4].As<Napi::Object>();
348+
auto jsEnableTracing = jsTracingConfigObj.Get("enableTracing");
349+
if (!(jsEnableTracing.IsNull() || jsEnableTracing.IsUndefined())) {
350+
connstrInfo.options.enable_tracing =
351+
js_to_cbpp<bool>(jsEnableTracing);
352+
}
353+
couchbase::core::tracing::threshold_logging_options tracing_options{};
354+
bool has_tracing_options = false;
355+
356+
auto jsEmitInterval = jsTracingConfigObj.Get("emitInterval");
357+
if (!(jsEmitInterval.IsNull() || jsEmitInterval.IsUndefined())) {
358+
tracing_options.threshold_emit_interval =
359+
js_to_cbpp<std::chrono::milliseconds>(jsEmitInterval);
360+
has_tracing_options = true;
361+
}
362+
auto jsSampleSize = jsTracingConfigObj.Get("sampleSize");
363+
if (!(jsSampleSize.IsNull() || jsSampleSize.IsUndefined())) {
364+
tracing_options.threshold_sample_size =
365+
js_to_cbpp<std::size_t>(jsSampleSize);
366+
has_tracing_options = true;
367+
}
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+
}
383+
auto jsKvThreshold = jsTracingConfigObj.Get("kvThreshold");
384+
if (!(jsKvThreshold.IsNull() || jsKvThreshold.IsUndefined())) {
385+
tracing_options.key_value_threshold =
386+
js_to_cbpp<std::chrono::milliseconds>(jsKvThreshold);
387+
has_tracing_options = true;
388+
}
389+
auto jsQueryThreshold = jsTracingConfigObj.Get("queryThreshold");
390+
if (!(jsQueryThreshold.IsNull() || jsQueryThreshold.IsUndefined())) {
391+
tracing_options.query_threshold =
392+
js_to_cbpp<std::chrono::milliseconds>(jsQueryThreshold);
393+
has_tracing_options = true;
394+
}
395+
auto jsSearchThreshold = jsTracingConfigObj.Get("searchThreshold");
396+
if (!(jsSearchThreshold.IsNull() || jsSearchThreshold.IsUndefined())) {
397+
tracing_options.search_threshold =
398+
js_to_cbpp<std::chrono::milliseconds>(jsSearchThreshold);
399+
has_tracing_options = true;
400+
}
401+
auto jsAnalyticsThreshold =
402+
jsTracingConfigObj.Get("analyticsThreshold");
403+
if (!(jsAnalyticsThreshold.IsNull() ||
404+
jsAnalyticsThreshold.IsUndefined())) {
405+
tracing_options.analytics_threshold =
406+
js_to_cbpp<std::chrono::milliseconds>(jsAnalyticsThreshold);
407+
has_tracing_options = true;
408+
}
409+
auto jsManagementThreshold =
410+
jsTracingConfigObj.Get("managementThreshold");
411+
if (!(jsManagementThreshold.IsNull() ||
412+
jsManagementThreshold.IsUndefined())) {
413+
tracing_options.management_threshold =
414+
js_to_cbpp<std::chrono::milliseconds>(jsManagementThreshold);
415+
has_tracing_options = true;
416+
}
417+
auto jsEventingThreshold = jsTracingConfigObj.Get("eventingThreshold");
418+
if (!(jsEventingThreshold.IsNull() ||
419+
jsEventingThreshold.IsUndefined())) {
420+
tracing_options.eventing_threshold =
421+
js_to_cbpp<std::chrono::milliseconds>(jsEventingThreshold);
422+
has_tracing_options = true;
423+
}
424+
auto jsViewsThreshold = jsTracingConfigObj.Get("viewsThreshold");
425+
if (!(jsViewsThreshold.IsNull() || jsViewsThreshold.IsUndefined())) {
426+
tracing_options.view_threshold =
427+
js_to_cbpp<std::chrono::milliseconds>(jsViewsThreshold);
428+
has_tracing_options = true;
429+
}
430+
431+
if (has_tracing_options) {
432+
connstrInfo.options.tracing_options = tracing_options;
433+
}
434+
}
435+
436+
if (!info[5].IsNull()) {
437+
auto jsMetricsConfigObj = info[5].As<Napi::Object>();
438+
auto jsEnableMetrics = jsMetricsConfigObj.Get("enableMetrics");
439+
if (!(jsEnableMetrics.IsNull() || jsEnableMetrics.IsUndefined())) {
440+
connstrInfo.options.enable_metrics =
441+
js_to_cbpp<bool>(jsEnableMetrics);
442+
}
443+
444+
auto jsEmitInterval = jsMetricsConfigObj.Get("emitInterval");
445+
if (!(jsEmitInterval.IsNull() || jsEmitInterval.IsUndefined())) {
446+
couchbase::core::metrics::logging_meter_options logging_options{};
447+
logging_options.emit_interval =
448+
js_to_cbpp<std::chrono::milliseconds>(jsEmitInterval);
449+
connstrInfo.options.metrics_options = logging_options;
450+
}
451+
}
452+
346453
auto cookie = CallCookie(info.Env(), callbackJsFn, "cbConnectCallback");
347454
this->_instance->_cluster.open(
348455
couchbase::core::origin(creds, connstrInfo),

0 commit comments

Comments
 (0)