Skip to content

Commit 6527a8b

Browse files
committed
PCBC-1015: SDK Telemetry Collection in Server
1 parent 27e9bd4 commit 6527a8b

File tree

4 files changed

+163
-1
lines changed

4 files changed

+163
-1
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014-Present Couchbase, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace Couchbase;
22+
23+
class AppTelemetryConfiguration
24+
{
25+
private ?bool $enabled = null;
26+
private ?string $endpoint = null;
27+
private ?int $backoffMilliseconds = null;
28+
private ?int $pingIntervalMilliseconds = null;
29+
private ?int $pingTimeoutMilliseconds = null;
30+
31+
/**
32+
* Specifies if the application telemetry feature should be enabled or not.
33+
*
34+
* @param bool $enabled
35+
*
36+
* @return AppTelemetryConfiguration
37+
* @since 4.5.0
38+
*/
39+
public function enabled(bool $enabled): AppTelemetryConfiguration
40+
{
41+
$this->enabled = $enabled;
42+
return $this;
43+
}
44+
45+
/**
46+
* Specifies an endpoint to override the application metrics endpoint discovered during configuration.
47+
*
48+
* @param string $endpoint
49+
*
50+
* @return AppTelemetryConfiguration
51+
* @since 4.5.0
52+
*/
53+
public function endpoint(string $endpoint): AppTelemetryConfiguration
54+
{
55+
$this->endpoint = $endpoint;
56+
return $this;
57+
}
58+
59+
/**
60+
* Specifies the time to wait before attempting a websocket reconnection, specified in millseconds.
61+
*
62+
* @param int $milliseconds
63+
*
64+
* @return AppTelemetryConfiguration
65+
* @since 4.5.0
66+
*/
67+
public function backoff(int $milliseconds): AppTelemetryConfiguration
68+
{
69+
$this->backoffMilliseconds = $milliseconds;
70+
return $this;
71+
}
72+
73+
/**
74+
* Specifies the time to wait between sending consecutive websocket PING commands to the server, specified in millseconds.
75+
*
76+
* @param int $milliseconds
77+
*
78+
* @return AppTelemetryConfiguration
79+
* @since 4.5.0
80+
*/
81+
public function pingInterval(int $milliseconds): AppTelemetryConfiguration
82+
{
83+
$this->pingIntervalMilliseconds = $milliseconds;
84+
return $this;
85+
}
86+
87+
/**
88+
* Specifies the time allowed for the server to respond to websocket PING command, specified in millseconds.
89+
*
90+
* @param int $milliseconds
91+
*
92+
* @return AppTelemetryConfiguration
93+
* @since 4.5.0
94+
*/
95+
public function pingTimeout(int $milliseconds): AppTelemetryConfiguration
96+
{
97+
$this->pingTimeoutMilliseconds = $milliseconds;
98+
return $this;
99+
}
100+
101+
/**
102+
* @internal
103+
*/
104+
public function export(): array
105+
{
106+
return [
107+
'enabled' => $this->enabled,
108+
'endpoint' => $this->endpoint,
109+
'backoff' => $this->backoffMilliseconds,
110+
'pingInterval' => $this->pingIntervalMilliseconds,
111+
'pingTimeout' => $this->pingTimeoutMilliseconds,
112+
];
113+
}
114+
}

Couchbase/ClusterOptions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ClusterOptions
6666
private ?ThresholdLoggingOptions $thresholdLoggingTracerOptions = null;
6767
private ?LoggingMeterOptions $loggingMeterOptions = null;
6868
private ?TransactionsConfiguration $transactionsConfiguration = null;
69+
private ?AppTelemetryConfiguration $appTelemetryConfiguration = null;
6970

7071
private ?Authenticator $authenticator;
7172

@@ -490,6 +491,18 @@ public function transactionsConfiguration(TransactionsConfiguration $options): C
490491
return $this;
491492
}
492493

494+
/**
495+
* @param AppTelemetryConfiguration $options
496+
*
497+
* @return ClusterOptions
498+
* @since 4.5.0
499+
*/
500+
public function appTelemetryConfiguration(AppTelemetryConfiguration $options): ClusterOptions
501+
{
502+
$this->appTelemetryConfiguration = $options;
503+
return $this;
504+
}
505+
493506
/**
494507
* Select the server group to use for replica APIs.
495508
*
@@ -609,6 +622,8 @@ public function export(): array
609622
'thresholdLoggingTracerOptions' =>
610623
$this->thresholdLoggingTracerOptions == null ? null : $this->thresholdLoggingTracerOptions->export(),
611624
'loggingMeterOptions' => $this->loggingMeterOptions == null ? null : $this->loggingMeterOptions->export(),
625+
'appTelemetryConfiguration' =>
626+
$this->appTelemetryConfiguration == null ? null : $this->appTelemetryConfiguration->export(),
612627
];
613628
}
614629
}

src/deps/couchbase-cxx-client

src/wrapper/connection_handle.cxx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,6 +6222,39 @@ apply_options(couchbase::cluster_options& cluster_options, zval* options) -> cor
62226222
}
62236223
ZEND_HASH_FOREACH_END();
62246224
}
6225+
6226+
if (zend_binary_strcmp(ZSTR_VAL(key), ZSTR_LEN(key), ZEND_STRL("appTelemetryConfiguration")) == 0) {
6227+
if (value == nullptr || Z_TYPE_P(value) == IS_NULL) {
6228+
continue;
6229+
}
6230+
6231+
const zend_string* k = nullptr;
6232+
const zval* v = nullptr;
6233+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(value), k, v)
6234+
{
6235+
options::assign_boolean(ZEND_STRL("enabled"), k, v, [&](auto v) {
6236+
cluster_options.application_telemetry().enable(v);
6237+
});
6238+
6239+
options::assign_string(ZEND_STRL("endpoint"), k, v, [&](auto v) {
6240+
cluster_options.application_telemetry().override_endpoint(std::move(v));
6241+
});
6242+
6243+
options::assign_duration(ZEND_STRL("backoff"), k, v, [&](auto v) {
6244+
cluster_options.application_telemetry().backoff_interval(v);
6245+
});
6246+
6247+
options::assign_duration(ZEND_STRL("pingInterval"), k, v, [&](auto v) {
6248+
cluster_options.application_telemetry().ping_interval(v);
6249+
});
6250+
6251+
options::assign_duration(ZEND_STRL("pingTimeout"), k, v, [&](auto v) {
6252+
cluster_options.application_telemetry().ping_timeout(v);
6253+
});
6254+
}
6255+
ZEND_HASH_FOREACH_END();
6256+
}
6257+
62256258
} catch (const core_error_info& e) {
62266259
return e;
62276260
}

0 commit comments

Comments
 (0)