Google Cloud Sql Admin V1 Client - Class SqlWorkloadCapturesServiceClient (1.13.0)

Reference documentation and code samples for the Google Cloud Sql Admin V1 Client class SqlWorkloadCapturesServiceClient.

Service Description: Cloud SQL Workload Captures service.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Namespace

Google \ Cloud \ Sql \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array|Google\ApiCore\Options\ClientOptions

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials Google\Auth\FetchAuthTokenInterface|Google\ApiCore\CredentialsWrapper

This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Cloud\Sql\V1\SqlWorkloadCapturesServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new SqlWorkloadCapturesServiceClient(['credentials' => $creds]); https://cloud.google.com/docs/authentication/external/externally-sourced-credentials

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|Google\ApiCore\Transport\TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

↳ logger false|Psr\Log\LoggerInterface

A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag

↳ universeDomain string

The service domain for the client. Defaults to 'googleapis.com'.

list

Lists all captured workloads associated with the instance.

The async variant is SqlWorkloadCapturesServiceClient::listAsync() .

Parameters
Name Description
request Google\Cloud\Sql\V1\SqlWorkloadCapturesListRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Sql\V1\WorkloadCapturesListResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlWorkloadCapturesServiceClient;
use Google\Cloud\Sql\V1\SqlWorkloadCapturesListRequest;
use Google\Cloud\Sql\V1\WorkloadCapturesListResponse;

/**
 * @param string $project  Project ID of the project that contains the instance.
 * @param string $instance Cloud SQL instance ID. This does not include the project ID.
 */
function list_sample(string $project, string $instance): void
{
    // Create a client.
    $sqlWorkloadCapturesServiceClient = new SqlWorkloadCapturesServiceClient();

    // Prepare the request message.
    $request = (new SqlWorkloadCapturesListRequest())
        ->setProject($project)
        ->setInstance($instance);

    // Call the API and handle any network failures.
    try {
        /** @var WorkloadCapturesListResponse $response */
        $response = $sqlWorkloadCapturesServiceClient->list($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $project = '[PROJECT]';
    $instance = '[INSTANCE]';

    list_sample($project, $instance);
}

start

Starts capturing the SQL queries, transactions, and other operations executed on the primary instance. This traffic is securely stored and forms a "captured workload". This workload can be replayed later on a different instance to safely test performance impacts, database upgrades, configuration changes etc. before applying them to production.

The async variant is SqlWorkloadCapturesServiceClient::startAsync() .

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStartRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Sql\V1\Operation
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlWorkloadCapturesServiceClient;
use Google\Cloud\Sql\V1\Operation;
use Google\Cloud\Sql\V1\WorkloadCapturesStartRequest;

/**
 * @param string $project  Project ID of the project that contains the instance.
 * @param string $instance Cloud SQL instance ID. This does not include the project ID.
 */
function start_sample(string $project, string $instance): void
{
    // Create a client.
    $sqlWorkloadCapturesServiceClient = new SqlWorkloadCapturesServiceClient();

    // Prepare the request message.
    $request = (new WorkloadCapturesStartRequest())
        ->setProject($project)
        ->setInstance($instance);

    // Call the API and handle any network failures.
    try {
        /** @var Operation $response */
        $response = $sqlWorkloadCapturesServiceClient->start($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $project = '[PROJECT]';
    $instance = '[INSTANCE]';

    start_sample($project, $instance);
}

startReplay

Starts executing a captured workload on a separate Cloud SQL instance provisioned for workload replay. This target instance simulates the production environment without affecting the primary instance.

The async variant is SqlWorkloadCapturesServiceClient::startReplayAsync() .

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStartReplayRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Sql\V1\Operation
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlWorkloadCapturesServiceClient;
use Google\Cloud\Sql\V1\Operation;
use Google\Cloud\Sql\V1\StartWorkloadReplayContext;
use Google\Cloud\Sql\V1\WorkloadCapturesStartReplayRequest;

/**
 * @param string $project                                  Project ID of the project that contains the instance.
 * @param string $instance                                 Cloud SQL instance ID. This does not include the project ID.
 * @param string $startWorkloadReplayContextReplayInstance The name of the Cloud SQL instance where the captured workload
 *                                                         (SQL queries) is being executed, excluding the project ID (for example,
 *                                                         `my-replay-instance`). The instance name must start with a lowercase letter
 *                                                         and contain only lowercase letters, numbers, and hyphens. The combined
 *                                                         length of `project-ID:instance-name` must be 98 characters or less.
 * @param string $workloadId                               The ID of the workload to replay.
 */
function start_replay_sample(
    string $project,
    string $instance,
    string $startWorkloadReplayContextReplayInstance,
    string $workloadId
): void {
    // Create a client.
    $sqlWorkloadCapturesServiceClient = new SqlWorkloadCapturesServiceClient();

    // Prepare the request message.
    $startWorkloadReplayContext = (new StartWorkloadReplayContext())
        ->setReplayInstance($startWorkloadReplayContextReplayInstance);
    $request = (new WorkloadCapturesStartReplayRequest())
        ->setProject($project)
        ->setInstance($instance)
        ->setStartWorkloadReplayContext($startWorkloadReplayContext)
        ->setWorkloadId($workloadId);

    // Call the API and handle any network failures.
    try {
        /** @var Operation $response */
        $response = $sqlWorkloadCapturesServiceClient->startReplay($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $project = '[PROJECT]';
    $instance = '[INSTANCE]';
    $startWorkloadReplayContextReplayInstance = '[REPLAY_INSTANCE]';
    $workloadId = '[WORKLOAD_ID]';

    start_replay_sample($project, $instance, $startWorkloadReplayContextReplayInstance, $workloadId);
}

stop

Stops capturing the query traffic and related operations executed on the primary instance.

The async variant is SqlWorkloadCapturesServiceClient::stopAsync() .

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStopRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Sql\V1\Operation
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlWorkloadCapturesServiceClient;
use Google\Cloud\Sql\V1\Operation;
use Google\Cloud\Sql\V1\WorkloadCapturesStopRequest;

/**
 * @param string $project  Project ID of the project that contains the instance.
 * @param string $instance Cloud SQL instance ID. This does not include the project ID.
 */
function stop_sample(string $project, string $instance): void
{
    // Create a client.
    $sqlWorkloadCapturesServiceClient = new SqlWorkloadCapturesServiceClient();

    // Prepare the request message.
    $request = (new WorkloadCapturesStopRequest())
        ->setProject($project)
        ->setInstance($instance);

    // Call the API and handle any network failures.
    try {
        /** @var Operation $response */
        $response = $sqlWorkloadCapturesServiceClient->stop($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $project = '[PROJECT]';
    $instance = '[INSTANCE]';

    stop_sample($project, $instance);
}

stopReplay

Stops an active workload replay on the target Cloud SQL replay instance.

The async variant is SqlWorkloadCapturesServiceClient::stopReplayAsync() .

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStopReplayRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Cloud\Sql\V1\Operation
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Sql\V1\Client\SqlWorkloadCapturesServiceClient;
use Google\Cloud\Sql\V1\Operation;
use Google\Cloud\Sql\V1\WorkloadCapturesStopReplayRequest;

/**
 * @param string $project  Project ID of the project that contains the target replay
 *                         instance.
 * @param string $instance Cloud SQL instance ID of the target replay instance. This does
 *                         not include the project ID.
 */
function stop_replay_sample(string $project, string $instance): void
{
    // Create a client.
    $sqlWorkloadCapturesServiceClient = new SqlWorkloadCapturesServiceClient();

    // Prepare the request message.
    $request = (new WorkloadCapturesStopReplayRequest())
        ->setProject($project)
        ->setInstance($instance);

    // Call the API and handle any network failures.
    try {
        /** @var Operation $response */
        $response = $sqlWorkloadCapturesServiceClient->stopReplay($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $project = '[PROJECT]';
    $instance = '[INSTANCE]';

    stop_replay_sample($project, $instance);
}

listAsync

Parameters
Name Description
request Google\Cloud\Sql\V1\SqlWorkloadCapturesListRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Sql\V1\WorkloadCapturesListResponse>

startAsync

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStartRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Sql\V1\Operation>

startReplayAsync

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStartReplayRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Sql\V1\Operation>

stopAsync

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStopRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Sql\V1\Operation>

stopReplayAsync

Parameters
Name Description
request Google\Cloud\Sql\V1\WorkloadCapturesStopReplayRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Sql\V1\Operation>