Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 114 additions & 0 deletions Couchbase/AppTelemetryConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/**
* Copyright 2014-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace Couchbase;

class AppTelemetryConfiguration
{
private ?bool $enabled = null;
private ?string $endpoint = null;
private ?int $backoffMilliseconds = null;
private ?int $pingIntervalMilliseconds = null;
private ?int $pingTimeoutMilliseconds = null;

/**
* Specifies if the application telemetry feature should be enabled or not.
*
* @param bool $enabled
*
* @return AppTelemetryConfiguration
* @since 4.5.0
*/
public function enabled(bool $enabled): AppTelemetryConfiguration
{
$this->enabled = $enabled;
return $this;
}

/**
* Specifies an endpoint to override the application metrics endpoint discovered during configuration.
*
* @param string $endpoint
*
* @return AppTelemetryConfiguration
* @since 4.5.0
*/
public function endpoint(string $endpoint): AppTelemetryConfiguration
{
$this->endpoint = $endpoint;
return $this;
}

/**
* Specifies the time to wait before attempting a websocket reconnection, specified in millseconds.
*
* @param int $milliseconds
*
* @return AppTelemetryConfiguration
* @since 4.5.0
*/
public function backoff(int $milliseconds): AppTelemetryConfiguration
{
$this->backoffMilliseconds = $milliseconds;
return $this;
}

/**
* Specifies the time to wait between sending consecutive websocket PING commands to the server, specified in millseconds.
*
* @param int $milliseconds
*
* @return AppTelemetryConfiguration
* @since 4.5.0
*/
public function pingInterval(int $milliseconds): AppTelemetryConfiguration
{
$this->pingIntervalMilliseconds = $milliseconds;
return $this;
}

/**
* Specifies the time allowed for the server to respond to websocket PING command, specified in millseconds.
*
* @param int $milliseconds
*
* @return AppTelemetryConfiguration
* @since 4.5.0
*/
public function pingTimeout(int $milliseconds): AppTelemetryConfiguration
{
$this->pingTimeoutMilliseconds = $milliseconds;
return $this;
}

/**
* @internal
*/
public function export(): array
{
return [
'enabled' => $this->enabled,
'endpoint' => $this->endpoint,
'backoff' => $this->backoffMilliseconds,
'pingInterval' => $this->pingIntervalMilliseconds,
'pingTimeout' => $this->pingTimeoutMilliseconds,
];
}
}
15 changes: 15 additions & 0 deletions Couchbase/ClusterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ClusterOptions
private ?ThresholdLoggingOptions $thresholdLoggingTracerOptions = null;
private ?LoggingMeterOptions $loggingMeterOptions = null;
private ?TransactionsConfiguration $transactionsConfiguration = null;
private ?AppTelemetryConfiguration $appTelemetryConfiguration = null;

private ?Authenticator $authenticator;

Expand Down Expand Up @@ -490,6 +491,18 @@ public function transactionsConfiguration(TransactionsConfiguration $options): C
return $this;
}

/**
* @param AppTelemetryConfiguration $options
*
* @return ClusterOptions
* @since 4.5.0
*/
public function appTelemetryConfiguration(AppTelemetryConfiguration $options): ClusterOptions
{
$this->appTelemetryConfiguration = $options;
return $this;
}

/**
* Select the server group to use for replica APIs.
*
Expand Down Expand Up @@ -609,6 +622,8 @@ public function export(): array
'thresholdLoggingTracerOptions' =>
$this->thresholdLoggingTracerOptions == null ? null : $this->thresholdLoggingTracerOptions->export(),
'loggingMeterOptions' => $this->loggingMeterOptions == null ? null : $this->loggingMeterOptions->export(),
'appTelemetryConfiguration' =>
$this->appTelemetryConfiguration == null ? null : $this->appTelemetryConfiguration->export(),
];
}
}
2 changes: 1 addition & 1 deletion src/deps/couchbase-cxx-client
33 changes: 33 additions & 0 deletions src/wrapper/connection_handle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6222,6 +6222,39 @@ apply_options(couchbase::cluster_options& cluster_options, zval* options) -> cor
}
ZEND_HASH_FOREACH_END();
}

if (zend_binary_strcmp(ZSTR_VAL(key), ZSTR_LEN(key), ZEND_STRL("appTelemetryConfiguration")) == 0) {
if (value == nullptr || Z_TYPE_P(value) == IS_NULL) {
continue;
}

const zend_string* k = nullptr;
const zval* v = nullptr;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(value), k, v)
{
options::assign_boolean(ZEND_STRL("enabled"), k, v, [&](auto v) {
cluster_options.application_telemetry().enable(v);
});

options::assign_string(ZEND_STRL("endpoint"), k, v, [&](auto v) {
cluster_options.application_telemetry().override_endpoint(std::move(v));
});

options::assign_duration(ZEND_STRL("backoff"), k, v, [&](auto v) {
cluster_options.application_telemetry().backoff_interval(v);
});

options::assign_duration(ZEND_STRL("pingInterval"), k, v, [&](auto v) {
cluster_options.application_telemetry().ping_interval(v);
});

options::assign_duration(ZEND_STRL("pingTimeout"), k, v, [&](auto v) {
cluster_options.application_telemetry().ping_timeout(v);
});
}
ZEND_HASH_FOREACH_END();
}

} catch (const core_error_info& e) {
return e;
}
Expand Down
Loading