private function processFunctionLogs()

in src/TestUtils/CloudFunctionDeploymentTrait.php [156:194]


    private function processFunctionLogs(string $startTime, callable $process, ?int $retries = null, ?int $sleep = null)
    {
        if (empty(self::$loggingClient)) {
            self::$loggingClient = new LoggingClient([
                'projectId' => self::$projectId
            ]);
        }

        // Define the log search criteria.
        $logFullName = 'projects/' . self::$projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
        $filter = sprintf(
            'logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
            $logFullName,
            self::$fn->getFunctionName(),
            $startTime
        );

        echo PHP_EOL . "Retrieving logs [$filter]..." . PHP_EOL;

        if (!is_null($sleep)) {
            printf('Sleeping for %d second(s)' . PHP_EOL, $sleep);
            sleep($sleep);
        }

        // Check for new logs for the function.
        $attempt = 1;
        $this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
            $entries = self::$loggingClient->entries(['filter' => $filter]);

            // If no logs came in try again.
            if (empty($entries->current())) {
                echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
                throw new ExpectationFailedException('Log Entries not available');
            }
            echo 'Processing logs...' . PHP_EOL;

            $process($entries);
        }, $retries);
    }