Google-cloud-php: Getting "Undefined index: structValue" when using LoggingClient

Created on 21 Feb 2018  路  4Comments  路  Source: googleapis/google-cloud-php

https://github.com/GoogleCloudPlatform/google-cloud-php/blob/81ad5c82fce22095692e2011e95e0441679139ab/src/Core/GrpcTrait.php#L172

The library works when I changed it to:

        return $this->unpackStructFromApi($value['structValue']);
core p1 bug

All 4 comments

Thanks for the report @tmatsuo, just wanted to give a quick follow up on this. We are planning a release for tomorrow which will include a patch for this issue.

My apologies, I don't think we will be able to get a fix in for this today. I based that on the thought that the fix you proposed may do the trick (after some initial testing myself, it appeared to), but after further investigation I have run into a perplexing issue. I am wondering if the issue you have seen above is a symptom of what I am running into.

With the following json payloads in a set of logs (as viewed through the logs viewer or the REST API):

// first write
{ 
  "log": "write",
  "test": {
    "a": {
      "b": {
        "c": "d"
      }
    }
  }
}

// second write
{
  "log": "write",
  "test": {
    "a": {
      "b": {
        "c": {
          "d": "e"
        }
      }
    }
  }
}

And running the following script:

use Google\Auth\CredentialsLoader;
use Google\Cloud\Logging\V2\ListLogEntriesRequest;
use Google\Cloud\Logging\V2\LoggingServiceV2GrpcClient;
use Google\Protobuf\Internal\MapField;
use Grpc\ChannelCredentials;

$client = new LoggingServiceV2GrpcClient('logging.googleapis.com', [
    'credentials' => ChannelCredentials::createSsl()
]);

$credentialsLoader = CredentialsLoader::makeCredentials(
    ['https://www.googleapis.com/auth/logging.admin'],
    json_decode(file_get_contents('/key.json'), true)
);

$request = new ListLogEntriesRequest();
$request->setResourceNames(['projects/my-project']);
$request->setFilter('logName = projects/my-project/logs/logtest123');
$response = $client->ListLogEntries(
    $request,
    [],
    [
        'call_credentials_callback' => function () use ($credentialsLoader) {
            $token = $credentialsLoader->fetchAuthToken();
            return ['authorization' => ['Bearer ' . $token['access_token']]];
        }
    ]
)->wait();

$entries = $response[0]->getEntries();

foreach ($entries as $entry) {
    $entry = json_decode($entry->serializeToJsonString(), true);
    var_dump($entry['insertId']);
    var_dump($entry['jsonPayload']);
}

I am seeing the dump of the above jsonPayload as:

{
  'fields' =>
  array(2) {
    'test' =>
    array(1) {
      'structValue' =>
      array(1) {
        'fields' =>
        array(1) {
          'd' =>
          array(1) {
            'stringValue' =>
            string(1) "e"
          }
        }
      }
    }
    'log' =>
    array(1) {
      'stringValue' =>
      string(5) "write"
    }
  }
}

For all the logs in a response, even though they have different insert IDs.

This will require some further digging :confused:. It is not clear to me yet if this may be an issue in protobuf, my script, or upstream.

After looking in to this a bit more, it appears the issue I was running in to was related to the protobuf extension. Disabling it resolved the issue I outlined above, and the originally proposed fix does indeed work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codeflorist picture codeflorist  路  5Comments

smalot picture smalot  路  6Comments

Najtmare picture Najtmare  路  6Comments

castaneai picture castaneai  路  7Comments

mjniuz picture mjniuz  路  6Comments