google-cloud-php
google-cloud-php copied to clipboard
Google\ApiCore\ValidationException: Could not map bindings for google.monitoring.v3.MetricService/CreateTimeSeries to any Uri template.
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
- Search the issues already opened: https://github.com/googleapis/google-cloud-php/issues
- Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+php
If you are still having issues, please be sure to include as much information as possible:
Environment details
- OS: linux
- PHP version: 8.1
- Package name and version: google/cloud-monitoring 1.1.6
Steps to reproduce
- attempt to use the example at https://github.com/googleapis/google-cloud-php/tree/main/Monitoring
- experience the error below
PHP Notice: Google\ApiCore\ValidationException: Could not map bindings for google.monitoring.v3.MetricService/CreateTimeSeries to any Uri template.
Bindings: Array
(
[name] => REDACTED
)
UriTemplates: Array
(
[0] => /v3/{name=projects/*}/timeSeries
)
in /var/www/html/vendor/google/gax/src/RequestBuilder.php:127
Stack trace:
#0 /var/www/html/vendor/google/gax/src/Transport/RestTransport.php(120): Google\ApiCore\RequestBuilder->build()
#1 /var/www/html/vendor/google/gax/src/GapicClientTrait.php(608): Google\ApiCore\Transport\RestTransport->startUnaryCall()
#2 /var/www/html/vendor/google/gax/src/Middleware/CredentialsWrapperMiddleware.php(61): Google\Cloud\Monitoring\V3\Gapic\MetricServiceGapicClient->Google\ApiCore\{closure}()
#3 /var/www/html/vendor/google/gax/src/Middleware/FixedHeaderMiddleware.php(66): Google\ApiCore\Middleware\CredentialsWrapperMiddleware->__invoke()
#4 /var/www/html/vendor/google/gax/src/Middleware/RetryMiddleware.php(85): Google\ApiCore\Middleware\FixedHeaderMiddleware->__invoke()
#5 /var/www/html/vendor/google/gax/src/Middleware/OptionsFilterMiddleware.php(63): Google\ApiCore\Middleware\RetryMiddleware->__invoke()
#6 /var/www/html/vendor/google/gax/src/GapicClientTrait.php(583): Google\ApiCore\Middleware\OptionsFilterMiddleware->__invoke()
#7 /var/www/html/vendor/google/cloud-monitoring/src/V3/Gapic/MetricServiceGapicClient.php(758): Google\Cloud\Monitoring\V3\Gapic\MetricServiceGapicClient->startCall()
Code example
use Google\Api\Metric;
use Google\Api\MonitoredResource;
use Google\Cloud\Monitoring\V3\MetricServiceClient;
use Google\Cloud\Monitoring\V3\Point;
use Google\Cloud\Monitoring\V3\TimeInterval;
use Google\Cloud\Monitoring\V3\TimeSeries;
use Google\Cloud\Monitoring\V3\TypedValue;
use Google\Protobuf\Timestamp;
$metricServiceClient = new MetricServiceClient();
$formattedProjectName = $metricServiceClient->projectName($projectId);
$labels = [
'instance_id' => $instanceId,
'zone' => $zone,
];
$m = new Metric();
$m->setType('custom.googleapis.com/my_metric');
$r = new MonitoredResource();
$r->setType('gce_instance');
$r->setLabels($labels);
$value = new TypedValue();
$value->setDoubleValue(3.14);
$timestamp = new Timestamp();
$timestamp->setSeconds(time());
$interval = new TimeInterval();
$interval->setStartTime($timestamp);
$interval->setEndTime($timestamp);
$point = new Point();
$point->setValue($value);
$point->setInterval($interval);
$points = [$point];
$timeSeries = new TimeSeries();
$timeSeries->setMetric($m);
$timeSeries->setResource($r);
$timeSeries->setPoints($points);
try {
$metricServiceClient->createTimeSeries($formattedProjectName, [$timeSeries]);
print('Successfully submitted a time series' . PHP_EOL);
} finally {
$metricServiceClient->close();
}
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
@i386 Is it possible your $projectId
is null and/or contains invalid characters which need escaped?
Closing due to no repro