Reference documentation and code samples for the Google Cloud Appoptimize V1beta Client class AppOptimizeClient.
Service Description: Service for managing and querying optimization reports.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Namespace
Google \ Cloud \ AppOptimize \ V1beta \ ClientMethods
__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 |
FetchAuthTokenInterface|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 |
↳ 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 |
↳ 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|TransportInterface
The transport used for executing network requests. May be either the string |
↳ 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|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'. |
createReport
Creates a new report.
This initiates a long-running operation that, upon completion, results
in a report resource. Once the report is created, its results can be read
via ReadReport.
The async variant is AppOptimizeClient::createReportAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\CreateReportRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\ApiCore\OperationResponse<Google\Cloud\AppOptimize\V1beta\Report> |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\AppOptimize\V1beta\CreateReportRequest;
use Google\Cloud\AppOptimize\V1beta\Report;
use Google\Rpc\Status;
/**
* @param string $formattedParent The parent Google Cloud project that will own the report.
*
* This value does not define the scope of the report data. See `Report.scope`
* for setting the data scope.
*
* Format: `projects/{project}/locations/{location}`. Please see
* {@see AppOptimizeClient::locationName()} for help formatting this field.
* @param string $reportId The ID to use for this report. This ID must be unique within
* the parent project and should comply with RFC 1034 restrictions (letters,
* numbers, and hyphen, with the first character a letter, the last a letter
* or a number, and a 63 character maximum).
* @param string $reportDimensionsElement A list of dimensions to include in the report. Supported values:
*
* * `project`
* * `application`
* * `service_or_workload`
* * `resource`
* * `resource_type`
* * `location`
* * `product_display_name`
* * `sku`
* * `month`
* * `day`
* * `hour`
*
* To aggregate results by time, specify at least one time dimension
* (`month`, `day`, or `hour`). All time dimensions use Pacific Time,
* respect Daylight Saving Time (DST), and follow these ISO 8601 formats:
*
* * `month`: `YYYY-MM` (e.g., `2024-01`)
* * `day`: `YYYY-MM-DD` (e.g., `2024-01-10`)
* * `hour`: `YYYY-MM-DDTHH` (e.g., `2024-01-10T00`)
*
* If the time range filter does not align with the selected time dimension,
* the range is expanded to encompass the full period of the finest-grained
* time dimension.
*
* For example, if the filter is `2026-01-10` through `2026-01-12` and the
* `month` dimension is selected, the effective time range expands to include
* all of January (`2026-01-01` to `2026-02-01`).
* @param string $reportMetricsElement A list of metrics to include in the report. Supported values:
*
* * `cost`
* * `cpu_mean_utilization`
* * `cpu_usage_core_seconds`
* * `cpu_allocation_core_seconds`
* * `cpu_p95_utilization`
* * `memory_mean_utilization`
* * `memory_usage_byte_seconds`
* * `memory_allocation_byte_seconds`
* * `memory_p95_utilization`
*/
function create_report_sample(
string $formattedParent,
string $reportId,
string $reportDimensionsElement,
string $reportMetricsElement
): void {
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$reportDimensions = [$reportDimensionsElement,];
$reportMetrics = [$reportMetricsElement,];
$report = (new Report())
->setDimensions($reportDimensions)
->setMetrics($reportMetrics);
$request = (new CreateReportRequest())
->setParent($formattedParent)
->setReportId($reportId)
->setReport($report);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $appOptimizeClient->createReport($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Report $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->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
{
$formattedParent = AppOptimizeClient::locationName('[PROJECT]', '[LOCATION]');
$reportId = '[REPORT_ID]';
$reportDimensionsElement = '[DIMENSIONS]';
$reportMetricsElement = '[METRICS]';
create_report_sample($formattedParent, $reportId, $reportDimensionsElement, $reportMetricsElement);
}
deleteReport
Deletes the specified report.
The async variant is AppOptimizeClient::deleteReportAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\DeleteReportRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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. |
use Google\ApiCore\ApiException;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\AppOptimize\V1beta\DeleteReportRequest;
/**
* @param string $formattedName The name of the report to delete.
*
* Format: `projects/{project}/locations/{location}/reports/{report_id}`. Please see
* {@see AppOptimizeClient::reportName()} for help formatting this field.
*/
function delete_report_sample(string $formattedName): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = (new DeleteReportRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
$appOptimizeClient->deleteReport($request);
printf('Call completed successfully.' . PHP_EOL);
} 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
{
$formattedName = AppOptimizeClient::reportName('[PROJECT]', '[LOCATION]', '[REPORT]');
delete_report_sample($formattedName);
}
getReport
Retrieves the details of a report configuration.
The async variant is AppOptimizeClient::getReportAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\GetReportRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\AppOptimize\V1beta\Report |
|
use Google\ApiCore\ApiException;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\AppOptimize\V1beta\GetReportRequest;
use Google\Cloud\AppOptimize\V1beta\Report;
/**
* @param string $formattedName The name of the report to retrieve.
*
* Format: `projects/{project}/locations/{location}/reports/{report_id}`. Please see
* {@see AppOptimizeClient::reportName()} for help formatting this field.
*/
function get_report_sample(string $formattedName): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = (new GetReportRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Report $response */
$response = $appOptimizeClient->getReport($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
{
$formattedName = AppOptimizeClient::reportName('[PROJECT]', '[LOCATION]', '[REPORT]');
get_report_sample($formattedName);
}
listReports
Lists reports within a given project.
The async variant is AppOptimizeClient::listReportsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\ListReportsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\AppOptimize\V1beta\ListReportsRequest;
use Google\Cloud\AppOptimize\V1beta\Report;
/**
* @param string $formattedParent The parent project whose reports are to be listed.
*
* Format: `projects/{project}/locations/{location}`. Please see
* {@see AppOptimizeClient::locationName()} for help formatting this field.
*/
function list_reports_sample(string $formattedParent): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = (new ListReportsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $appOptimizeClient->listReports($request);
/** @var Report $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->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
{
$formattedParent = AppOptimizeClient::locationName('[PROJECT]', '[LOCATION]');
list_reports_sample($formattedParent);
}
readReport
Reads data within a specified report.
The async variant is AppOptimizeClient::readReportAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\ReadReportRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\AppOptimize\V1beta\ReadReportRequest;
use Google\Protobuf\ListValue;
/**
* @param string $formattedName The resource name of the report to query.
*
* Format: `projects/{project}/locations/{location}/reports/{report_id}`. Please see
* {@see AppOptimizeClient::reportName()} for help formatting this field.
*/
function read_report_sample(string $formattedName): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = (new ReadReportRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $appOptimizeClient->readReport($request);
/** @var ListValue $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->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
{
$formattedName = AppOptimizeClient::reportName('[PROJECT]', '[LOCATION]', '[REPORT]');
read_report_sample($formattedName);
}
getLocation
Gets information about a location.
The async variant is AppOptimizeClient::getLocationAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\Location\Location |
|
use Google\ApiCore\ApiException;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;
/**
* 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 get_location_sample(): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = new GetLocationRequest();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $appOptimizeClient->getLocation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
listLocations
Lists information about the supported locations for this service.
This method lists locations based on the resource scope provided in the [ListLocationsRequest.name] field:
Global locations: If name is empty, the method lists the
public locations available to all projects. * Project-specific
locations: If name follows the format
projects/{project}, the method lists locations visible to that
specific project. This includes public, private, or other
project-specific locations enabled for the project.
For gRPC and client library implementations, the resource name is
passed as the name field. For direct service calls, the resource
name is
incorporated into the request path based on the specific service
implementation and version.
The async variant is AppOptimizeClient::listLocationsAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
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\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\AppOptimize\V1beta\Client\AppOptimizeClient;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
/**
* 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 list_locations_sample(): void
{
// Create a client.
$appOptimizeClient = new AppOptimizeClient();
// Prepare the request message.
$request = new ListLocationsRequest();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $appOptimizeClient->listLocations($request);
/** @var Location $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
createReportAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\CreateReportRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse> |
|
deleteReportAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\DeleteReportRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
|
getReportAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\GetReportRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\AppOptimize\V1beta\Report> |
|
listReportsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\ListReportsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
readReportAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\AppOptimize\V1beta\ReadReportRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
getLocationAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Location\Location> |
|
listLocationsAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
| Returns | |
|---|---|
| Type | Description |
Google\LongRunning\Client\OperationsClient |
|
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
| Parameters | |
|---|---|
| Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\OperationResponse |
|
static::applicationName
Formats a string containing the fully-qualified path to represent a application resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
application |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted application resource. |
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted location resource. |
static::projectName
Formats a string containing the fully-qualified path to represent a project resource.
| Parameter | |
|---|---|
| Name | Description |
project |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted project resource. |
static::reportName
Formats a string containing the fully-qualified path to represent a report resource.
| Parameters | |
|---|---|
| Name | Description |
project |
string
|
location |
string
|
report |
string
|
| Returns | |
|---|---|
| Type | Description |
string |
The formatted report resource. |
static::parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- application: projects/{project}/locations/{location}/applications/{application}
- location: projects/{project}/locations/{location}
- project: projects/{project}
- report: projects/{project}/locations/{location}/reports/{report}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
| Parameters | |
|---|---|
| Name | Description |
formattedName |
string
The formatted name string |
template |
?string
Optional name of template to match |
| Returns | |
|---|---|
| Type | Description |
array |
An associative array from name component IDs to component values. |