Repository navigation
chore(appengine): upgrade Google Cloud dependencies to ^2.0 - #2346
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates several Google Cloud client libraries to their latest major versions (such as upgrading google/cloud-datastore, google/cloud-logging, and google/cloud-storage to ^2.0) across various App Engine samples. It adapts the code to the new library APIs, including migrating to request objects for RPC calls (e.g., ListGroupStatsRequest, ListEventsRequest, and CreateTaskRequest) and upgrading the Speech API usage from V1 to V2. The review feedback correctly identifies an opportunity to improve code readability in DeployTest.php and VerifyReportedErrorTrait.php by avoiding the reuse of the $response variable name in nested loops.
| $request = (new ListGroupStatsRequest()) | ||
| ->setProjectName($projectName) | ||
| ->setTimeRange($timeRange); | ||
| $response = $errorStats->listGroupStats($request); | ||
| foreach ($response->iterateAllElements() as $groupStat) { | ||
| $response = $errorStats->listEvents($projectName, $groupStat->getGroup()->getGroupId(), [ | ||
| 'timeRange' => $timeRange, | ||
| ]); | ||
| $eventsRequest = (new ListEventsRequest()) | ||
| ->setProjectName($projectName) | ||
| ->setGroupId($groupStat->getGroup()->getGroupId()) | ||
| ->setTimeRange($timeRange); | ||
| $response = $errorStats->listEvents($eventsRequest); | ||
| foreach ($response->iterateAllElements() as $event) { | ||
| $messages[] = $event->getMessage(); | ||
| } |
There was a problem hiding this comment.
Reusing the $response variable name for both the outer listGroupStats response and the inner listEvents response is confusing and can lead to readability or maintenance issues. It is cleaner and more idiomatic to use distinct, descriptive variable names like $groupStatsResponse and $eventsResponse.
$request = (new ListGroupStatsRequest())
->setProjectName($projectName)
->setTimeRange($timeRange);
$groupStatsResponse = $errorStats->listGroupStats($request);
foreach ($groupStatsResponse->iterateAllElements() as $groupStat) {
$eventsRequest = (new ListEventsRequest())
->setProjectName($projectName)
->setGroupId($groupStat->getGroup()->getGroupId())
->setTimeRange($timeRange);
$eventsResponse = $errorStats->listEvents($eventsRequest);
foreach ($eventsResponse->iterateAllElements() as $event) {
$messages[] = $event->getMessage();
}| $request = (new ListGroupStatsRequest()) | ||
| ->setProjectName($projectName) | ||
| ->setTimeRange($timeRange) | ||
| ->setPageSize(100); | ||
| $response = $errorStats->listGroupStats($request); | ||
| foreach ($response->iterateAllElements() as $groupStat) { | ||
| $response = $errorStats->listEvents($projectName, $groupStat->getGroup()->getGroupId(), [ | ||
| 'timeRange' => $timeRange, | ||
| 'pageSize' => 100, | ||
| ]); | ||
| $eventsRequest = (new ListEventsRequest()) | ||
| ->setProjectName($projectName) | ||
| ->setGroupId($groupStat->getGroup()->getGroupId()) | ||
| ->setTimeRange($timeRange) | ||
| ->setPageSize(100); | ||
| $response = $errorStats->listEvents($eventsRequest); | ||
| foreach ($response->iterateAllElements() as $event) { | ||
| $messages[] = $event->getMessage(); | ||
| } |
There was a problem hiding this comment.
Reusing the $response variable name for both the outer listGroupStats response and the inner listEvents response is confusing and can lead to readability or maintenance issues. It is cleaner and more idiomatic to use distinct, descriptive variable names like $groupStatsResponse and $eventsResponse.
$request = (new ListGroupStatsRequest())
->setProjectName($projectName)
->setTimeRange($timeRange)
->setPageSize(100);
$groupStatsResponse = $errorStats->listGroupStats($request);
foreach ($groupStatsResponse->iterateAllElements() as $groupStat) {
$eventsRequest = (new ListEventsRequest())
->setProjectName($projectName)
->setGroupId($groupStat->getGroup()->getGroupId())
->setTimeRange($timeRange)
->setPageSize(100);
$eventsResponse = $errorStats->listEvents($eventsRequest);
foreach ($eventsResponse->iterateAllElements() as $event) {
$messages[] = $event->getMessage();
}
Upgrade App Engine and Error Reporting samples to the latest
google/cloud-*releases:google/cloud-datastore,google/cloud-logging, andgoogle/cloud-storageto^2.0, andgoogle/cloud-error-reportingto^0.28.0appengine/standard/grpc/speech.phptogoogle/cloud-speechv2appengine/standard/tasks,appengine/flexible/datastore, and Error Reporting tests for v2 compatibility