-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
7,574 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: "Build protobuf" | ||
on: | ||
push: | ||
branches: | ||
- '*' | ||
paths: | ||
- '**.proto' | ||
- 'buf.gen.yaml' | ||
|
||
jobs: | ||
proto: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
coverage: none | ||
extensions: mbstring | ||
php-version: 8.2 | ||
|
||
- run: composer install --no-interaction --no-progress --no-suggest | ||
|
||
- uses: bufbuild/buf-setup-action@v1 | ||
|
||
- run: | | ||
buf generate | ||
rm -rf src/Tracing/FederatedTracing/Proto | ||
mv proto-tmp/Nuwave/Lighthouse/Tracing/FederatedTracing/Proto src/Tracing/FederatedTracing/Proto | ||
rm -rf proto-tmp | ||
- run: vendor/bin/php-cs-fixer fix src/Tracing/FederatedTracing/Proto | ||
|
||
- run: git pull | ||
|
||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: Apply proto changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: "Update reports.proto" | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
jobs: | ||
proto: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- run: curl -sSfo src/Tracing/FederatedTracing/reports.proto https://usage-reporting.api.apollographql.com/proto/reports.proto | ||
|
||
- run: | | ||
sed -i 's/ \[(js_use_toArray) = true]//g' src/Tracing/FederatedTracing/reports.proto | ||
sed -i 's/ \[(js_preEncoded) = true]//g' src/Tracing/FederatedTracing/reports.proto | ||
sed -i '3 i option php_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto";' src/Tracing/FederatedTracing/reports.proto | ||
sed -i '4 i option php_metadata_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto\\\\Metadata";' src/Tracing/FederatedTracing/reports.proto | ||
- uses: peter-evans/create-pull-request@v5 | ||
with: | ||
title: 'Updated `reports.proto`' | ||
commit_message: Updated `reports.proto` | ||
branch: patch/update-reports-proto | ||
delete-branch: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ phpunit.xml | |
.php-cs-fixer.cache | ||
build | ||
phpstan-tmp-dir | ||
proto-tmp | ||
|
||
# composer | ||
composer.phar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: v1 | ||
managed: | ||
enabled: true | ||
plugins: | ||
# For new releases, see https://github.com/protocolbuffers/protobuf/releases and https://buf.build/protocolbuffers/php | ||
- plugin: buf.build/protocolbuffers/php:v25.1 | ||
out: proto-tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Nuwave\Lighthouse\Tracing\ApolloTracing; | ||
|
||
use Illuminate\Support\Carbon; | ||
use Nuwave\Lighthouse\Events\BuildExtensionsResponse; | ||
use Nuwave\Lighthouse\Events\StartExecution; | ||
use Nuwave\Lighthouse\Events\StartRequest; | ||
use Nuwave\Lighthouse\Execution\ExtensionsResponse; | ||
use Nuwave\Lighthouse\Execution\ResolveInfo; | ||
use Nuwave\Lighthouse\Tracing\Tracing; | ||
use Nuwave\Lighthouse\Tracing\TracingUtilities; | ||
|
||
/** See https://github.com/apollographql/apollo-tracing#response-format. */ | ||
class ApolloTracing implements Tracing | ||
{ | ||
use TracingUtilities; | ||
|
||
/** The point in time when the request was initially started. */ | ||
protected Carbon $executionStartAbsolute; | ||
|
||
/** | ||
* The precise point in time when the request was initially started. | ||
* | ||
* This is either in seconds with microsecond precision (float) or nanoseconds (int). | ||
*/ | ||
protected int|float $executionStartPrecise; | ||
|
||
/** | ||
* Trace entries for a single query execution. | ||
* | ||
* @var array<int, array<string, mixed>> | ||
*/ | ||
protected array $resolverTraces = []; | ||
|
||
public function handleStartRequest(StartRequest $startRequest): void {} | ||
|
||
public function handleStartExecution(StartExecution $startExecution): void | ||
{ | ||
$this->executionStartAbsolute = Carbon::now(); | ||
$this->executionStartPrecise = $this->timestamp(); | ||
$this->resolverTraces = []; | ||
} | ||
|
||
public function handleBuildExtensionsResponse(BuildExtensionsResponse $buildExtensionsResponse): ?ExtensionsResponse | ||
{ | ||
$requestEndAbsolute = Carbon::now(); | ||
$requestEndPrecise = $this->timestamp(); | ||
|
||
return new ExtensionsResponse( | ||
'tracing', | ||
[ | ||
'version' => 1, | ||
'startTime' => $this->formatTimestamp($this->executionStartAbsolute), | ||
'endTime' => $this->formatTimestamp($requestEndAbsolute), | ||
'duration' => $this->diffTimeInNanoseconds($this->executionStartPrecise, $requestEndPrecise), | ||
'execution' => [ | ||
'resolvers' => $this->resolverTraces, | ||
], | ||
], | ||
); | ||
} | ||
|
||
/** Record resolver execution time. */ | ||
public function record(ResolveInfo $resolveInfo, float|int $start, float|int $end): void | ||
{ | ||
$this->resolverTraces[] = [ | ||
'path' => $resolveInfo->path, | ||
'parentType' => $resolveInfo->parentType->name, | ||
'fieldName' => $resolveInfo->fieldName, | ||
'returnType' => $resolveInfo->returnType->toString(), | ||
'startOffset' => $this->diffTimeInNanoseconds($this->executionStartPrecise, $start), | ||
'duration' => $this->diffTimeInNanoseconds($start, $end), | ||
]; | ||
} | ||
} |
Oops, something went wrong.