GithubHelp home page GithubHelp logo

gax-php's Introduction

Google API Core for PHP

Build Status

Google API Core for PHP (gax-php) is a set of modules which aids the development of APIs for clients based on gRPC and Google API conventions.

Application code will rarely need to use most of the classes within this library directly, but code generated automatically from the API definition files in Google APIs can use services such as page streaming and retry to provide a more convenient and idiomatic API surface to callers.

PHP Versions

gax-php currently requires PHP 5.6 or higher.

Contributing

Contributions to this library are always welcome and highly encouraged.

See the CONTRIBUTING documentation for more information on how to get started.

Versioning

This library follows Semantic Versioning.

This library is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority.

Repository Structure

All code lives under the src/ directory. Handwritten code lives in the src/ApiCore directory and is contained in the Google\ApiCore namespace.

Generated classes for protobuf common types and LongRunning client live under the src/ directory, in the appropriate directory and namespace.

Code in the metadata/ directory is provided to support generated protobuf classes, and should not be used directly.

Development Set-Up

These steps describe the dependencies to install for Linux, and equivalents can be found for Mac or Windows.

  1. Install dependencies.

    > cd ~/
    > sudo apt-get install php php-dev libcurl3-openssl-dev php-pear php-bcmath php-xml
    > curl -sS https://getcomposer.org/installer | php
    > sudo pecl install protobuf
  2. Set up this repo.

    > cd /path/to/gax-php
    > composer install
  3. Run tests.

    > composer test
  4. Updating dependencies after changing composer.json:

    > composer update
    `
  5. Formatting source:

    > composer cs-lint
    > composer cs-fix

License

BSD - See LICENSE for more information.

gax-php's People

Contributors

ajupazhamayil avatar alicejli avatar bshaffer avatar bytestream avatar carusogabriel avatar chingor13 avatar dwsupplee avatar garrettjonesgoogle avatar google-cloud-policy-bot[bot] avatar hectorhammett avatar jdpedrie avatar jeromegamez avatar justinbeckwith avatar lucasmichot avatar michaelbausor avatar miraleung avatar noahdietz avatar norberttech avatar phillip-hopper avatar pierrickvoulet avatar release-please[bot] avatar renovate-bot avatar saranshdhingra avatar shinfan avatar theacodes avatar vam-google avatar vishwarajanand avatar weiranfang avatar williamdes avatar yash30201 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gax-php's Issues

Make validation of REST bindings optional

Currently, if an API method supports additional bindings that are not listed in the rest config file, then attempting to set those bindings in the request message will cause an error, such as googleapis/google-cloud-php#985

We should allow (or make it possible) for clients to use unvalidated data, so that REST calls can be made to paths that are unknown to the client.

REST transport crashes on timestamps with the protobuf extension

The RestTransport when parsing results delegates the deserialization from json to protobuf message to the protobuf implementation. For messages with timestamp fields, the behavior differs between the extension and the php library. Basically a timestamp returned from the JSON REST API returns a timestamp string and is expected to be parsed into a google.protobuf.Timestamp message (seconds/nanoseconds). The php implementation has a hack to convert a string timestamp while the extension implementation does not and fails.

The bug currently seems like something for the protobuf library, but these feels like a feature of the Google APIs and not general to protobuf. Perhaps the adapter from a timestamp string to seconds/nanos belongs here in gax.

Better RequestBuilder Error Message

In RequestBuilder, the error message is Failed to build the provided path (google.cloud.iot.v1.DeviceManager/ListDevices) with the supplied message. when anything goes wrong.

This error message is not very useful for debugging. The case I ran into is the projectId was empty in a template with format `projects/{projectId}'. This took a while to debug.

A better error message would propagate the errant value somewhere in the exception. Something like Invalid "parent" attribute for google.cloud.iot.v1.DeviceManager/ListDevices.

Bug: Received message larger than max (5013781 vs. 4194304)

Environment details

  • OS: Debian
  • PHP version: 7.4
  • Package name and version: google/gax v1.7.1

Google\Cloud API that is using gax-php.

I receive the fallowing error message:

{ "message": "Received message larger than max (5013781 vs. 4194304)", "code": 8, "status": "RESOURCE_EXHAUSTED", "details": [ { "@type": "grpc-status", "data": "8" }, { "@type": "grpc-message", "data": "Received message larger than max (5013781 vs. 4194304)" } ] }

How can i solve this?

Make PagedListResponse Iterable

We should make PagedListResponse iterable. This would clean up the code:

$devices = $client->getDevices($parent, $registry);

// current code, not intuitive
foreach ($devices->iterateAllElements() as $device) {
    printf('Device ID: %s' . PHP_EOL, $device->getId());
}

// better code
foreach ($devices as $device) {
    printf('Device ID: %s' . PHP_EOL, $device->getId());
}

Another issue is the second one does not throw an error, it just fails to print out anything, which is the same behavior as if it had no elements. So it's very confusing!

Fix grpc installation issue on Travis

When Travis installs the grpc extension using pecl, if it is using the pre-installed PHP version (currently 5.6.24) then the extension is incorrectly installed for PHP 7. This causes tests to fail. If a PHP version other than 5.6.24 is specified (e.g. 5.6.25, 5.6.23, etc.) then that PHP version is installed, and the pecl installation of grpc succeeds.

This is temporarily resolved by specifying the PHP version in Travis to anything except 5.6.24, but a more permanent solution would be better.

Warning in gax/version - file not found

Source file:line /home/xxx/xxx/vendor/google/gax/src/Version.php:59
Msg: file_get_contents(/home/xxx/xxx/vendor/googleads/google-ads-php/VERSION): failed to open stream: No such file or directory

Environment details

  • OS: CentOS 6
  • PHP version: 7.2.19
  • Package name and version: googleads/google-ads-php: 1.4.1

Steps to reproduce

  1. Use composer.json and require package googleads/google-ads-php: 1.4.1
  2. Run example code and see notice

Code example

<?php
require_once __DIR__.'/vendor/autoload.php';

set_error_handler(function ($num, $msg, $file, $line, $ctx) {
	echo "Error ({$num}) occurred in {$file}:{$line} - {$msg}"."\n";
}, error_reporting());

$oauth_credential = new \Google\Auth\FetchAuthTokenCache(
	new \Google\Auth\Credentials\UserRefreshCredentials('https://www.googleapis.com/auth/adwords', [
		'client_id' => 123,
		'client_secret' => 123,
		'refresh_token' => 123
	]),
	null,
	new \Google\Auth\Cache\MemoryCacheItemPool
);

$client = (new \Google\Ads\GoogleAds\Lib\V1\GoogleAdsClientBuilder())
	->withDeveloperToken(123)
	->withOAuth2Credential($oauth_credential)
	->build();

$client->getAccountBudgetServiceClient();

Related issue in google-ads-php repo: googleads/google-ads-php#136

New release

Hi guys,

Would we be able to tag a new release which includes updated auth and gRPC dependencies?

Address frequent travis build failures

Frequently one or more builds will fail because of e.g. a composer failure. These should be retried automatically. Or else, we should move off Travis completely.

PathTemplate parse error when resource name has a "~" separator

The gapic-generator project was updated to support complex resource names with a "~" separator (googleapis/gapic-generator#3164), however it appears at runtime gax-php is having trouble parsing them.

For example, using the resource name customers/{customer_id}/userLocationViews/{country_criterion_id}~{is_targeting_location} causes the following error at runtime:

106) Google\Ads\GoogleAds\V5\Services\UserLocationViewServiceClientTest::getUserLocationViewExceptionTest
Google\ApiCore\ValidationException: Error parsing 'customers/{customer_id}/userLocationViews/{country_criterion_id}~{is_targeting_location}' at index 64: expected '/'

/google-ads-php/vendor/google/gax/src/ResourceTemplate/Parser.php:189
/google-ads-php/vendor/google/gax/src/ResourceTemplate/Parser.php:181
/google-ads-php/vendor/google/gax/src/ResourceTemplate/Parser.php:58
/google-ads-php/vendor/google/gax/src/ResourceTemplate/RelativeResourceTemplate.php:72
/google-ads-php/vendor/google/gax/src/PathTemplate.php:66
/google-ads-php/src/Google/Ads/GoogleAds/V5/Services/Gapic/UserLocationViewServiceGapicClient.php:118
/google-ads-php/src/Google/Ads/GoogleAds/V5/Services/Gapic/UserLocationViewServiceGapicClient.php:148
/google-ads-php/tests/Google/Ads/GoogleAds/V5/Services/UserLocationViewServiceClientTest.php:128

Support for logging when making REST calls

In the Google Ads API client library, some people may select to make a call using REST instead of gRPC.
Or with some reasons, they cannot use the gRPC extension on their system.

In that case, we probably still want to them to be able to use the logging feature so they can troubleshoot the issues and report them to us, when needed.

Knack

GAX Parser empty/falsey value throws cryptic exception.

The old JISON parser accepted various values evaluating to '' for template placeholders. The replacement parser released in v0.37.0 doesn't support empty values.

This strikes me as a good thing, since resource names missing (for instance) a project ID aren't valid, however the error message arising from this case is a bit hard to understand for new users. (see googleapis/google-cloud-php#1276).

Current behavior:

echo FirestoreGapicClient::databaseRootName(null, '(default)');
// Uncaught Google\ApiCore\ValidationException: Cannot bind segment '{project=*}' to value ''

Improved behavior:

echo FirestoreGapicClient::databaseRootName(null, '(default)');
// Uncaught Google\ApiCore\ValidationException: Segment '{project=*}' expected non-empty string, instead got null.

Bump protobuf version to 3.15

Problem description

Missmatch between protobuf versions causes this error;

message: "proto descriptor was previously loaded (included in multiple metadata bundles?)"

From my digging I understand that trying to use the PHP pecl module of protobuf at the same time as a composer package utilizing another version of protobuf causes this error.

We are currenlty using the googleads/google-ads-php package which wants protobuf 3.15 while gax-php wants protobuf 3.12.

While having the protobuf php module enabled the above error gets triggered, but when only using the different version composer packages of protobuf it does not get triggered.

So the request here is if you could bump your protobuf dependency to 3.15 to match googleads/google-ads-php so that we can use the php pecl module for protobuf

Environment details

  • OS: Docker php:8.0.3-fpm-alpine
  • PHP version: 8.0
  • Package name and version:

Steps to reproduce

  1. Install protobuf 3.15.* php module
  2. php composer.phar require googleads/google-ads-php
  3. Try to fetch data that triggers gax-php

Globals in Jison Parser

I would rather see these globals surfaced in a public property, i.e:

Google\Gax\PathTemplate::incrementBindingCount();
Google\Gax\PathTemplate::getBindingCount();
Google\Gax\PathTemplate::incrementSegmentCount();
Google\Gax\PathTemplate::getSegmentCount();

Similarly, these constants should be class constants

Google\Gax\PathTemplate::BINDING;
Google\Gax\PathTemplate::END_BINDING;
Google\Gax\PathTemplate::TERMINAL;

Which value to use for denoting error code in "RetrySettings"?

Hello! I am trying to use the built-in feature of retrying API requests as explained in here: src/RetrySettings.php. However it is not clear what value to pass in retryableCodes.

There are two options:

  • pass the string value of \Google\ApiCore\ApiStatus constants like ApiStatus::DEADLINE_EXCEEDED

    • this variant described in the comments here: RetrySettings.php
  • pass the integer value of \Google\Rpc\Code constants like Code::DEADLINE_EXCEEDED

What type I should use?

Invalid argument

My first call to annotateVideo throws an exception, but I double-checked the arguments and everything looks ok. Stanley, can you dig deeper? My code is here:
https://github.com/SurferJeffAtGoogle/php-docs-samples/tree/video/video

/usr/local/bin/php /usr/local/google/home/rennie/Downloads/phpunit-5.7.19.phar --configuration /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/phpunit.xml.dist --teamcity
Testing started at 9:36 AM ...
PHPUnit 5.7.19 by Sebastian Bergmann and contributors.


Request contains an invalid argument.
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiException.php:51
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiCallable.php:151
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiCallable.php:59
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiCallable.php:90
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiCallable.php:126
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/gax/src/ApiCallable.php:192
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/google/cloud-videointelligence/V1beta1/VideoIntelligenceServiceClient.php:411
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/src/detect_face.php:27
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/video.php:48
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/symfony/console/Command/Command.php:260
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/vendor/symfony/console/Tester/CommandTester.php:84
 /usr/local/google/home/rennie/gitrepos/php-docs-samples/video/test/CommandTest.php:54
 


Time: 723 ms, Memory: 27.75MB


ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

The value of $uri is gs://cloudmleap/video/next/fox-snatched.mp4

Enable master branch protection

      This repository does not seem to have master branch
      protection enabled, at least in the way I'm expecting.
      I was hoping for:

      - master branch protection
      - requiring at least one code reviewer
      - requiring at least two status checks
      - enforcing rules for admins

      Please turn it on!

What is the advantage of Jison?

I've been looking at Jison, and it's a very robust library. It seems to me this is overkill for parsing paths from short strings.

Is there a speed advantage over regex, or is this being used in another way I'm not aware of?

Composer V2.0 Deprecation Warning for PSR-4 Namespace

Composer reports that a file in the Testing directory have namespaces that aren't PSR-4 compliant. This can be solved from the user side in the short term in various ways, but the long term fix will need to be making the namespaces PSR-4 compliant.

Class GPBMetadata\Google\ApiCore\Tests\Unit\Example ./vendor/google/gax/metadata/Google/ApiCore/Tests/Unit/Example.php

Remove GPBXXX classes once available in protobuf

We are adding GPBLabel and GPBType in PR #92

These classes are required because their counterparts in google/protobuf live in the Internal namespace. Once these classes are made public by protobuf, we should remove them from GAX.

Timestamp type appears to be missing

When attempting to decode a message received from pubsub I'm getting the following error:

PHP Fatal error: Class '\google\protobuf\Timestamp' not found in /Users/dave/dev/gcloud-php/vendor/stanley-cheung/protobuf-php/library/DrSlump/Protobuf/Codec/Binary.php on line 267

I looked through src/generated and wasn't able to find this type.

Please let me know if there is anything I can do to help.

Google\ApiCore\Transport\{closure}() must be an instance of Google\ApiCore\Transport\Exception

I deploy code to upload offline conversion by google ads api
...
$response = $conversionUploadServiceClient->uploadClickConversions(
$customerId,
[$clickConversion],
false
);
...
but have issue this:

[TypeError]
Argument 1 passed to Google\ApiCore\Transport\RestTransport::Google\ApiCore\Transport{closure}() must be an instance of Exception, instance of Error given, called in /home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php on line 204 (0)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/Google/ApiCore/Transport/RestTransport.php:129
#0: Google\ApiCore\Transport\RestTransport->Google\ApiCore\Transport{closure}(object)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:204
#1: GuzzleHttp\Promise\Promise::callHandler(integer, object, NULL)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:153
#2: GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/TaskQueue.php:48
#3: GuzzleHttp\Promise\TaskQueue->run()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Handler/CurlMultiHandler.php:158
#4: GuzzleHttp\Handler\CurlMultiHandler->tick()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Handler/CurlMultiHandler.php:183
#5: GuzzleHttp\Handler\CurlMultiHandler->execute(boolean)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:248
#6: GuzzleHttp\Promise\Promise->invokeWaitFn()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:224
#7: GuzzleHttp\Promise\Promise->waitIfPending()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:269
#8: GuzzleHttp\Promise\Promise->invokeWaitList()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:226
#9: GuzzleHttp\Promise\Promise->waitIfPending()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/GuzzleHttp/Promise/Promise.php:62
#10: GuzzleHttp\Promise\Promise->wait()
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/Google/Ads/GoogleAds/V6/Services/Gapic/ConversionUploadServiceGapicClient.php:239
#11: Google\Ads\GoogleAds\V6\Services\Gapic\ConversionUploadServiceGapicClient->uploadClickConversions(integer, array, boolean)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/Google/Export/UploadOfflineConversion.php:143
#12: Google\Export\UploadOfflineConversion::runExample(object, integer, integer, string, string, double)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/Google/Export/UploadOfflineConversion.php:82
#13: Google\Export\UploadOfflineConversion::upload(array)
/home/bitrix/www/bitrix/activities/custom/vibgoogleactivity/vibgoogleactivity.php:75
#14: CBPVIBGoogleActivity->Execute()
/home/bitrix/www/bitrix/modules/bizproc/classes/general/workflow.php:466
#15: CBPWorkflow->RunQueuedItem(object, integer, NULL)
/home/bitrix/www/bitrix/modules/bizproc/classes/general/workflow.php:443
#16: CBPWorkflow->RunQueue()
/home/bitrix/www/bitrix/modules/bizproc/classes/general/workflow.php:198
#17: CBPWorkflow->Start()
/home/bitrix/www/bitrix/modules/bizproc/classes/general/document.php:341
#18: CBPDocument::StartWorkflow(string, array, array, array)
/home/bitrix/www/bitrix/modules/crm/classes/general/crm_bizproc.php:88
#19: CCrmBizProc->StartWorkflow(string, array)
/home/bitrix/www/bitrix/components/vportal/crm.deal.editac/component.php:882
#20: include(string)
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:605
#21: CBitrixComponent->__includeComponent()
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:680
#22: CBitrixComponent->includeComponent(string, array, object, boolean)
/home/bitrix/www/bitrix/modules/main/classes/general/main.php:1039
#23: CAllMain->IncludeComponent(string, string, array, object)
/home/bitrix/www/bitrix/components/bitrix/crm.deal/templates/.default/editac.php:76
#24: include(string)
/home/bitrix/www/bitrix/modules/main/classes/general/component_template.php:789
#25: CBitrixComponentTemplate->__IncludePHPTemplate(array, array, string)
/home/bitrix/www/bitrix/modules/main/classes/general/component_template.php:884
#26: CBitrixComponentTemplate->IncludeTemplate(array)
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:764
#27: CBitrixComponent->showComponentTemplate()
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:712
#28: CBitrixComponent->includeComponentTemplate(string)
/home/bitrix/www/bitrix/components/bitrix/crm.deal/component.php:312
#29: include(string)
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:605
#30: CBitrixComponent->__includeComponent()
/home/bitrix/www/bitrix/modules/main/classes/general/component.php:680
#31: CBitrixComponent->includeComponent(string, array, NULL, boolean)
/home/bitrix/www/bitrix/modules/main/classes/general/main.php:1039
#32: CAllMain->IncludeComponent(string, string, array)
/home/bitrix/www/crm/deal/index.php:9
#33: include_once(string)
/home/bitrix/www/bitrix/modules/main/include/urlrewrite.php:159
#34: include_once(string)
/home/bitrix/www/bitrix/urlrewrite.php:2

Create streamlined release process

Currently it is necessary to manually bump the version in AgentHeaderDescriptor when a new version is released - this should be incorporated into a simple process which bumps the header and tags a release

Unexpected error in GAX JISON parser for Firestore document path.

See googleapis/google-cloud-php#1119 for context.

The parse methods in GAX do not accept various symbols which are valid values in Firestore document names.

*
=
}
{

The presence of any of these symbols in arguments given to FirestoreGapicClient::documentPathName() raises the following error:

Fatal error: Uncaught Exception: Parse error on line 1:
Kind/F{[<,>.?509880146
------^
Expecting FORWARD_SLASH, COLON, RIGHT_BRACE, got 'LEFT_BRACE'

Is there any possibility that the parser may be able to support these symbols?

Cryptic error message when passing empty strings to path template

Copied from: googleapis/google-cloud-php#789
cc @bshaffer

I get the following error when running this Monitoring Sample and providing empty strings from Project ID and Instance ID:

Fatal error: Uncaught Exception: Parse error on line 1: ^ Expecting FORWARD_SLASH, WILDCARD, PATH_WILDCARD, LITERAL, LEFT_BRACE, got 'NOTHING' in vendor/google/gax/src/Jison/Parser.php:499 Stack trace:
#0 vendor/google/gax/src/Jison/Parser.php(561): Google\GAX\Jison\Parser->parseError('Parse error on ...', Object(Google\GAX\Jison\ParserError))
#1 vendor/google/gax/src/Parser.php(66): Google\GAX\Jison\Parser->parse(false)
#2 vendor/google/gax/src/PathTemplate.php(59): Google\GAX\Parser->parse(false)
#3 vendor/google/gax/src/PathTemplate.php(104): Google\GAX\PathTemplate->__construct(false)
#4 vendor/google/cloud-monitoring/V3/Gapic/MetricServiceGapicClient.php(236): Google\GAX\PathTemplate->render(Array)
#5 monitoring.php(25): Google\Cloud\Monitoring\V3\Gapic\MetricServiceGapicClient::projectName(false)
#6 {main} Next Google\GAX\ValidationException: Exception in parser in vendor/google/gax/src/Parser.php:84
Stack trace:
#0 vendor/google/gax/src/PathTemplate.php(59): Google\GAX in vendor/google/gax/src/Parser.php on line 84

Here is a full executable script (using google/cloud-monitoring:^0.6). I assume the issue is actually in google/gax, but wanted to log it here with context:

require_once __DIR__ . '/vendor/autoload.php';

use Google\Api\Metric;
use Google\Api\MonitoredResource;
use Google\Cloud\Monitoring\V3\MetricServiceClient;
use Google\Monitoring\V3\Point;
use Google\Monitoring\V3\TimeInterval;
use Google\Monitoring\V3\TimeSeries;
use Google\Monitoring\V3\TypedValue;
use Google\Protobuf\Timestamp;

// These variables are set by the App Engine environment. To test locally,
// ensure these are set or manually change their values.
$projectId = '';
$instanceId = '';
$zone = 'us-central1-f';

$client = new MetricServiceClient();
$projectName = $client->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);
$client->createTimeSeries($projectName, [$timeSeries]);

Add Protobuf info in the agent header "x-goog-api-client"

Is your feature request related to a problem? Please describe.

A basic value currently looks like gl-php/7.2.16-1+ubuntu14.04.1+deb.sury.org+1 gapic/ gax/1.2.0 grpc/1.26.0. Two additional pieces of information would be great to add:

  • Version of Protobuf
  • Protobuf implementation (C or PHP)

Describe the solution you'd like

Improve the agent header value to contain the protobuf information in the following format: protobuf-<implementation type>/<version>

  • <version>: 3.11.4 for example
  • <implementation>: c for the C implementation (extension) or php for the PHP implementation (regular dependency)

For example: gl-php/7.2.16-1+ubuntu14.04.1+deb.sury.org+1 gapic/ gax/1.2.0 grpc/1.26.0 protobuf-c/3.11.4

Additional context

This is really helpful for troubleshooting issues (based on basic logging)

Rename Repository and Composer Package

As the term "GAX" is a bit arcane, we should rename the repository and package. One option is as follows:

  • Repo: googleapis/gax-php => googleapis/php-core
  • Package: google/gax => google/api-core.

Because other repositories are using "common" (e.g. api-common-java and nodejs-common), and also because we have other namespaces besides ApiCore in google/gax, we should consider the following as well:

  • Repo: googleapis/gax-php => googleapis/php-common
  • Package: google/gax => google/api-common.

Thoughts?

Improper Parsing of FieldMask for REST requests

Same as googleapis/google-cloud-php#958

Field Masks are being improperly parsed as querystrings due to the fact they are handled in a special way by serializeToJsonString. For example, for the following FieldMask:

$mask = new FieldMask;
$mask->setPaths(['credentials']);

FieldMask::getQuerystringValue returns a string, but RequestBuilder expects an array. As a result, nothing is rendered, when the correct way to parse it is update_mask.paths=credentials.

When the FieldMask is parsed like any other message, this issue goes away. So one possible fix would be for the RequestBuilder to exclude FieldMask specifically when calling messageToArray:

if (GPBUtil::hasSpecialJsonMapping($message) && !$message instanceof FieldMask) {
    return json_decode($message->serializeToJsonString(), true);
}
$messageArray = [];
foreach ($this->getAllProperties($message) as $name => $value) {
    $propertyValue = $this->getPrivatePropertyValue($message, $name);
    $messageArray[$name] = $this->getQuerystringValue($propertyValue);
}
return $messageArray;

Composer warning!

Deprecation Notice: Class GPBMetadata\Google\ApiCore\Tests\Unit\Example located in ./vendor/google/gax/metadata/Google/ApiCore/Tests/Unit/Example.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/Cellar/composer/1.10.1/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

InvalidArgumentException with guzzlehttp dependency

Error message is clear:

InvalidArgumentException: Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or the "multipart" request option to send a multipart/form-data request.

Please update library.

configureCallConstructionOptions does not respect phpDocComment type

In GapicClientTrait::configureCallConstructionOptions, the documentation states that $retrySettings should be of type RetrySettings. However, in [configureCallConstructionOptions] (

$retrySettings = $retrySettings->with(
) it uses the $retrySettings as an argument for the RetrySettings::width which only accepts array as arguments. Thus if one sends a RetrySettings object as stated in multiple parts of the documentation for the $optionalArgs['retrySettings] key, then an error is rased stating Uncaught Type Error argument 1 must be of type array, object given

Rewrite CallSettings.load to accept config_overrides

Based on the discussion in googleapis/gax-python#95, we are going to accept a parameter config_overrides to construct_settings, and retire retrying_overrides.

config_overrides is in the same structure as client_config is, and expected to be supplied from the API users to override the config. Typically, I expect that users will copy the default JSON config file and modify it and pass it.

The returned config has to fall back to the default config, so the config_overrides can be a subset of client_config. The new load will merge these configs before constructing the config.

See also: googleapis/gax-python#103

Add support for IPv6 Addresses in ServiceAddressTrait

Currently, GAX does not support IPv6 addresses. Providing an IPv6 hostname will raise Google\ApiCore\ValidationException.

Example:

<?php

use Google\ApiCore\ServiceAddressTrait;
use Google\ApiCore\ValidationException;

include __DIR__ .'/../gax-php/vendor/autoload.php';

class TestClient
{
    use ServiceAddressTrait;

    public $hostname;

    public $port;

    public function __construct($address)
    {
        list (
            $this->hostname,
            $this->port
        ) = $this->normalizeServiceAddress($address);
    }
}

$addresses = [
    '[::1]:8080',
    '::1',
    '[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080',
    '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
];

foreach ($addresses as $address) {
    try {
        $client = new TestClient($address);
        var_dump('Success: '. $address);
    } catch (ValidationException $e) {
        var_dump('Fail: '. $e->getMessage());
    }
}

Output:

string(40) "Fail: Invalid serviceAddress: [::1]:8080"
string(33) "Fail: Invalid serviceAddress: ::1"
string(76) "Fail: Invalid serviceAddress: [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080"
string(69) "Fail: Invalid serviceAddress: 2001:0db8:85a3:0000:0000:8a2e:0370:7334"

Adding getHasser (or getHazzer?) to Serializer.php

With proto3, we now have some classes that contain a hasXXX() method.
The googleads/google-ads-php repo needs to use a method similar to getGetter() to fetch the hasXXX() method name.

It'd be great if we can have such a method implemented right in Serializer (where getGetter and getSetter are written), so we don't need to write our own.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.