-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build measurement backend and API (#2460)
In #2395, a user requested for the instrumentation data collected by CMake and CTest in [CMake issue 26099](https://gitlab.kitware.com/cmake/cmake/-/issues/26099)to be stored in CDash. This PR sets up the infrastructure needed to store and retrieve "build measurements" in CDash. Our existing "test measurement" functionality will be used to store the test instrumentation data. A future PR will introduce logic to populate the new build measurements table during the submission parsing process.
- Loading branch information
1 parent
b4406fb
commit c77bd6e
Showing
9 changed files
with
321 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum BuildMeasurementType: int | ||
{ | ||
case TARGET = 0; | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\BuildMeasurementType; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasOne; | ||
|
||
/** | ||
* @property int $id | ||
* @property int $buildid | ||
* @property string $name | ||
* @property string $source | ||
* @property BuildMeasurementType $type | ||
* @property string $value | ||
* | ||
* @mixin Builder<BuildMeasurement> | ||
*/ | ||
class BuildMeasurement extends Model | ||
{ | ||
protected $table = 'buildmeasurements'; | ||
|
||
public $timestamps = false; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'source', | ||
'type', | ||
'value', | ||
]; | ||
|
||
protected $casts = [ | ||
'id' => 'integer', | ||
'buildid' => 'integer', | ||
'type' => BuildMeasurementType::class, | ||
]; | ||
|
||
/** | ||
* @return HasOne<Build> | ||
*/ | ||
public function build(): HasOne | ||
{ | ||
return $this->hasOne(Build::class, 'id', 'buildid'); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use App\Enums\BuildMeasurementType; | ||
use Illuminate\Support\ServiceProvider; | ||
use Nuwave\Lighthouse\Schema\TypeRegistry; | ||
use GraphQL\Type\Definition\PhpEnumType; | ||
|
||
final class GraphQLServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* @throws \GraphQL\Error\InvariantViolation | ||
*/ | ||
public function boot(TypeRegistry $typeRegistry): void | ||
{ | ||
$typeRegistry->register(new PhpEnumType(BuildMeasurementType::class)); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
database/migrations/2024_09_24_184156_build_measurements_table.php
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,36 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('buildmeasurements', function (Blueprint $table) { | ||
$table->id(); | ||
$table->integer('buildid')->nullable(false); | ||
$table->smallInteger('type')->nullable(false); | ||
$table->string('name', 511)->nullable(false); | ||
$table->string('source', 511)->nullable(false); | ||
$table->string('value', 255)->nullable(false); | ||
|
||
$table->foreign('buildid')->references('id')->on('build')->cascadeOnDelete(); | ||
$table->index(['buildid', 'name']); | ||
$table->index(['buildid', 'source']); | ||
$table->index(['buildid', 'type']); | ||
$table->index(['buildid', 'value']); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('buildmeasurements'); | ||
} | ||
}; |
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,165 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\GraphQL; | ||
|
||
use App\Enums\BuildMeasurementType; | ||
use App\Models\Build; | ||
use App\Models\BuildMeasurement; | ||
use App\Models\Project; | ||
use Illuminate\Support\Str; | ||
use Tests\TestCase; | ||
use Tests\Traits\CreatesProjects; | ||
use Tests\Traits\CreatesUsers; | ||
|
||
class BuildMeasurementTypeTest extends TestCase | ||
{ | ||
use CreatesUsers; | ||
use CreatesProjects; | ||
|
||
private Project $project; | ||
private Project $project2; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->project = $this->makePublicProject(); | ||
$this->project2 = $this->makePrivateProject(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
// Deleting the project will delete all corresponding builds and build measurements | ||
$this->project->delete(); | ||
$this->project2->delete(); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* A basic test to ensure that each of the fields works | ||
*/ | ||
public function testBasicFieldAccess(): void | ||
{ | ||
/** @var Build $build */ | ||
$build = $this->project->builds()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'uuid' => Str::uuid()->toString(), | ||
]); | ||
|
||
/** @var BuildMeasurement $measurement */ | ||
$measurement = $build->measurements()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'source' => Str::uuid()->toString(), | ||
'type' => BuildMeasurementType::TARGET, | ||
'value' => 5, | ||
]); | ||
|
||
$this->graphQL(' | ||
query($id: ID) { | ||
build(id: $id) { | ||
measurements { | ||
edges { | ||
node { | ||
id | ||
name | ||
source | ||
type | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
', [ | ||
'id' => $build->id, | ||
])->assertJson([ | ||
'data' => [ | ||
'build' => [ | ||
'measurements' => [ | ||
'edges' => [ | ||
[ | ||
'node' => [ | ||
'id' => (string) $measurement->id, | ||
'name' => $measurement->name, | ||
'source' => $measurement->source, | ||
'type' => 'TARGET', | ||
'value' => '5', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], true); | ||
} | ||
|
||
public function testMeasurementFiltering(): void | ||
{ | ||
/** @var Build $build */ | ||
$build = $this->project->builds()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'uuid' => Str::uuid()->toString(), | ||
]); | ||
|
||
$build->measurements()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'source' => Str::uuid()->toString(), | ||
'type' => BuildMeasurementType::TARGET, | ||
'value' => 4, | ||
]); | ||
|
||
$build->measurements()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'source' => Str::uuid()->toString(), | ||
'type' => BuildMeasurementType::TARGET, | ||
'value' => 5, | ||
]); | ||
|
||
$build->measurements()->create([ | ||
'name' => Str::uuid()->toString(), | ||
'source' => Str::uuid()->toString(), | ||
'type' => BuildMeasurementType::TARGET, | ||
'value' => 6, | ||
]); | ||
|
||
$this->graphQL(' | ||
query($id: ID) { | ||
build(id: $id) { | ||
measurements(filters: { | ||
gt: { | ||
value: "4" | ||
} | ||
}) { | ||
edges { | ||
node { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
', [ | ||
'id' => $build->id, | ||
])->assertJson([ | ||
'data' => [ | ||
'build' => [ | ||
'measurements' => [ | ||
'edges' => [ | ||
[ | ||
'node' => [ | ||
'value' => '6', | ||
], | ||
], | ||
[ | ||
'node' => [ | ||
'value' => '5', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], true); | ||
} | ||
} |