Skip to content

Commit 05cd5d9

Browse files
committed
AC-15461:Migration New Relic from REST v2 to NerdGraph (GraphQL)
1 parent 94f7ef7 commit 05cd5d9

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

app/code/Magento/NewRelicReporting/Model/Apm/Deployments.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function setDeployment(
100100
$apiMode = $this->config->getApiMode();
101101

102102
if ($apiMode === ApiMode::MODE_NERDGRAPH) {
103-
return $this->createNerdGraphDeployment(
103+
return $this->setNerdGraphDeployment(
104104
$description,
105105
$changelog,
106106
$user,
@@ -110,7 +110,7 @@ public function setDeployment(
110110
$groupId
111111
);
112112
} else {
113-
return $this->createV2RestDeployment($description, $changelog, $user, $revision);
113+
return $this->setV2RestDeployment($description, $changelog, $user, $revision);
114114
}
115115
}
116116

@@ -123,7 +123,7 @@ public function setDeployment(
123123
* @param string|null $revision
124124
* @return bool|string
125125
*/
126-
private function createV2RestDeployment(string $description, bool|string $changelog, bool|string $user, ?string
126+
private function setV2RestDeployment(string $description, bool|string $changelog, bool|string $user, ?string
127127
$revision): bool|string
128128
{
129129
$apiUrl = $this->config->getNewRelicApiUrl();
@@ -185,10 +185,10 @@ private function createV2RestDeployment(string $description, bool|string $change
185185
* @param string|null $groupId
186186
* @return array|false
187187
*/
188-
private function createNerdGraphDeployment(string $description, ?string $changelog, ?string $user, ?string
188+
private function setNerdGraphDeployment(string $description, ?string $changelog, ?string $user, ?string
189189
$revision, ?string $commit, ?string $deepLink, ?string $groupId): false|array
190190
{
191-
return $this->deploymentTracker->createDeployment(
191+
return $this->deploymentTracker->setDeployment(
192192
$description,
193193
$changelog ? (string)$changelog : null,
194194
$user ? (string)$user : null,

app/code/Magento/NewRelicReporting/Model/NerdGraph/DeploymentTracker.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\NewRelicReporting\Model\NerdGraph;
99

10+
use Exception;
1011
use Magento\NewRelicReporting\Model\Config;
1112
use Psr\Log\LoggerInterface;
1213

@@ -59,7 +60,7 @@ public function __construct(
5960
* @param string|null $groupId Group ID for organizing deployments
6061
* @return array|false Deployment data on success, false on failure
6162
*/
62-
public function createDeployment(
63+
public function setDeployment(
6364
string $description,
6465
?string $changelog = null,
6566
?string $user = null,
@@ -98,7 +99,7 @@ public function createDeployment(
9899
$deepLink,
99100
$groupId
100101
);
101-
} catch (\Exception $e) {
102+
} catch (Exception $e) {
102103
$this->logger->error('NerdGraph deployment creation failed: ' . $e->getMessage());
103104
return false;
104105
}

app/code/Magento/NewRelicReporting/Test/Unit/Model/Apm/DeploymentsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function testSetDeploymentNerdGraphMode()
322322

323323
// Mock DeploymentTracker to be called with correct parameters
324324
$this->deploymentTrackerMock->expects($this->once())
325-
->method('createDeployment')
325+
->method('setDeployment')
326326
->with($description, $changelog, $user, $revision, $commit, $deepLink, $groupId)
327327
->willReturn($expectedNerdGraphResponse);
328328

@@ -364,7 +364,7 @@ public function testSetDeploymentNerdGraphModeFailure()
364364

365365
// Mock DeploymentTracker to return false (failure)
366366
$this->deploymentTrackerMock->expects($this->once())
367-
->method('createDeployment')
367+
->method('setDeployment')
368368
->with($description, $change, $user, $revision, null, null, null)
369369
->willReturn(false);
370370

@@ -397,7 +397,7 @@ public function testSetDeploymentModeDetectionNerdGraph()
397397

398398
$expectedResult = ['deploymentId' => 'test-123', 'entityGuid' => 'test-guid'];
399399
$this->deploymentTrackerMock->expects($this->once())
400-
->method('createDeployment')
400+
->method('setDeployment')
401401
->with($description, $changelog, $user, $revision, null, null, null)
402402
->willReturn($expectedResult);
403403

@@ -426,7 +426,7 @@ public function testSetDeploymentNerdGraphEnhancedParameters()
426426

427427
// Verify all enhanced parameters are passed correctly
428428
$this->deploymentTrackerMock->expects($this->once())
429-
->method('createDeployment')
429+
->method('setDeployment')
430430
->with(
431431
$this->equalTo($description),
432432
$this->equalTo($changelog),
@@ -665,7 +665,7 @@ public function testSetDeploymentNerdGraphParameterCasting()
665665

666666
// Verify that falsy string parameters are cast to null correctly
667667
$this->deploymentTrackerMock->expects($this->once())
668-
->method('createDeployment')
668+
->method('setDeployment')
669669
->with(
670670
$description,
671671
null, // empty string should become null
@@ -706,7 +706,7 @@ public function testSetDeploymentNerdGraphTruthyStrings()
706706

707707
// Verify that truthy strings are passed as-is (cast to string)
708708
$this->deploymentTrackerMock->expects($this->once())
709-
->method('createDeployment')
709+
->method('setDeployment')
710710
->with(
711711
$description,
712712
'actual changelog', // Should be cast to string
@@ -747,7 +747,7 @@ public function testSetDeploymentNerdGraphNullParameters()
747747

748748
// Verify that null parameters are passed through as null
749749
$this->deploymentTrackerMock->expects($this->once())
750-
->method('createDeployment')
750+
->method('setDeployment')
751751
->with(
752752
$description,
753753
null, // null should remain null

app/code/Magento/NewRelicReporting/Test/Unit/Model/NerdGraph/DeploymentTrackerTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testCreateDeploymentSuccess()
9797
$this->nerdGraphClientMock->expects($this->once())
9898
->method('query')
9999
->with(
100-
$this->stringContains('mutation CreateDeployment'),
100+
$this->stringContains('mutation createDeployment'),
101101
$this->callback(function ($variables) use (
102102
$entityGuid,
103103
$description,
@@ -125,7 +125,7 @@ public function testCreateDeploymentSuccess()
125125
->method('info')
126126
->with('NerdGraph deployment created successfully');
127127

128-
$result = $this->deploymentTracker->createDeployment(
128+
$result = $this->deploymentTracker->setDeployment(
129129
$description,
130130
$changelog,
131131
$user,
@@ -175,7 +175,7 @@ public function testCreateDeploymentWithMinimalParameters()
175175
$this->nerdGraphClientMock->expects($this->once())
176176
->method('query')
177177
->with(
178-
$this->stringContains('mutation CreateDeployment'),
178+
$this->stringContains('mutation createDeployment'),
179179
$this->callback(function ($variables) use ($entityGuid, $description) {
180180
return isset($variables['deployment']) &&
181181
$variables['deployment']['entityGuid'] === $entityGuid &&
@@ -190,7 +190,7 @@ public function testCreateDeploymentWithMinimalParameters()
190190
->method('info')
191191
->with('NerdGraph deployment created successfully');
192192

193-
$result = $this->deploymentTracker->createDeployment($description);
193+
$result = $this->deploymentTracker->setDeployment($description);
194194

195195
$this->assertIsArray($result);
196196
$this->assertArrayHasKey('deploymentId', $result);
@@ -236,7 +236,7 @@ public function testCreateDeploymentEntityGuidFallbackFromAppName()
236236
$this->nerdGraphClientMock->expects($this->once())
237237
->method('query')
238238
->with(
239-
$this->stringContains('mutation CreateDeployment'),
239+
$this->stringContains('mutation createDeployment'),
240240
$this->callback(function ($variables) use ($resolvedGuid, $description) {
241241
return isset($variables['deployment']) &&
242242
$variables['deployment']['entityGuid'] === $resolvedGuid &&
@@ -248,7 +248,7 @@ public function testCreateDeploymentEntityGuidFallbackFromAppName()
248248
$this->loggerMock->expects($this->exactly(2))
249249
->method('info');
250250

251-
$result = $this->deploymentTracker->createDeployment($description);
251+
$result = $this->deploymentTracker->setDeployment($description);
252252

253253
$this->assertIsArray($result);
254254
$this->assertArrayHasKey('deploymentId', $result);
@@ -294,7 +294,7 @@ public function testCreateDeploymentEntityGuidFallbackFromAppId()
294294
$this->nerdGraphClientMock->expects($this->once())
295295
->method('query')
296296
->with(
297-
$this->stringContains('mutation CreateDeployment'),
297+
$this->stringContains('mutation createDeployment'),
298298
$this->callback(function ($variables) use ($resolvedGuid, $description) {
299299
return isset($variables['deployment']) &&
300300
$variables['deployment']['entityGuid'] === $resolvedGuid &&
@@ -306,7 +306,7 @@ public function testCreateDeploymentEntityGuidFallbackFromAppId()
306306
$this->loggerMock->expects($this->exactly(2))
307307
->method('info');
308308

309-
$result = $this->deploymentTracker->createDeployment($description);
309+
$result = $this->deploymentTracker->setDeployment($description);
310310

311311
$this->assertIsArray($result);
312312
$this->assertArrayHasKey('deploymentId', $result);
@@ -334,7 +334,7 @@ public function testCreateDeploymentFailureMissingEntityGuid()
334334
$this->loggerMock->expects($this->atLeastOnce())
335335
->method('error');
336336

337-
$result = $this->deploymentTracker->createDeployment($description);
337+
$result = $this->deploymentTracker->setDeployment($description);
338338

339339
$this->assertFalse($result);
340340
}
@@ -366,7 +366,7 @@ public function testCreateDeploymentFailureEntityGuidResolutionFailed()
366366

367367
$this->loggerMock->expects($this->atLeastOnce())->method('error');
368368

369-
$result = $this->deploymentTracker->createDeployment($description);
369+
$result = $this->deploymentTracker->setDeployment($description);
370370

371371
$this->assertFalse($result);
372372
}
@@ -396,7 +396,7 @@ public function testCreateDeploymentWithGraphQLErrors()
396396

397397
$this->loggerMock->expects($this->atLeastOnce())->method('error');
398398

399-
$result = $this->deploymentTracker->createDeployment($description);
399+
$result = $this->deploymentTracker->setDeployment($description);
400400

401401
$this->assertFalse($result);
402402
}
@@ -419,7 +419,7 @@ public function testCreateDeploymentWithEmptyResponse()
419419

420420
$this->loggerMock->expects($this->atLeastOnce())->method('error');
421421

422-
$result = $this->deploymentTracker->createDeployment($description);
422+
$result = $this->deploymentTracker->setDeployment($description);
423423

424424
$this->assertFalse($result);
425425
}
@@ -448,7 +448,7 @@ public function testCreateDeploymentWithMalformedResponse()
448448

449449
$this->loggerMock->expects($this->atLeastOnce())->method('error');
450450

451-
$result = $this->deploymentTracker->createDeployment($description);
451+
$result = $this->deploymentTracker->setDeployment($description);
452452

453453
$this->assertFalse($result);
454454
}
@@ -471,7 +471,7 @@ public function testCreateDeploymentWithNetworkFailure()
471471

472472
$this->loggerMock->expects($this->atLeastOnce())->method('error');
473473

474-
$result = $this->deploymentTracker->createDeployment($description);
474+
$result = $this->deploymentTracker->setDeployment($description);
475475

476476
$this->assertFalse($result);
477477
}
@@ -502,7 +502,7 @@ public function testCreateDeploymentWithSpecialCharacters()
502502
$this->nerdGraphClientMock->expects($this->once())
503503
->method('query')
504504
->with(
505-
$this->stringContains('mutation CreateDeployment'),
505+
$this->stringContains('mutation createDeployment'),
506506
$this->callback(function ($variables) use ($entityGuid, $description) {
507507
return isset($variables['deployment']) &&
508508
$variables['deployment']['entityGuid'] === $entityGuid &&
@@ -515,7 +515,7 @@ public function testCreateDeploymentWithSpecialCharacters()
515515
->method('info')
516516
->with('NerdGraph deployment created successfully');
517517

518-
$result = $this->deploymentTracker->createDeployment($description);
518+
$result = $this->deploymentTracker->setDeployment($description);
519519

520520
$this->assertIsArray($result);
521521
$this->assertArrayHasKey('deploymentId', $result);
@@ -556,7 +556,7 @@ public function testCreateDeploymentWithLongParameters()
556556
->method('info')
557557
->with('NerdGraph deployment created successfully');
558558

559-
$result = $this->deploymentTracker->createDeployment($description, $changelog, $user);
559+
$result = $this->deploymentTracker->setDeployment($description, $changelog, $user);
560560

561561
$this->assertIsArray($result);
562562
$this->assertArrayHasKey('deploymentId', $result);
@@ -592,7 +592,7 @@ public function testCreateDeploymentMutationStructure()
592592
$this->nerdGraphClientMock->expects($this->once())
593593
->method('query')
594594
->with(
595-
$this->stringContains('mutation CreateDeployment'),
595+
$this->stringContains('mutation createDeployment'),
596596
$this->callback(function ($variables) use (
597597
$entityGuid,
598598
$description,
@@ -620,7 +620,7 @@ public function testCreateDeploymentMutationStructure()
620620
->method('info')
621621
->with('NerdGraph deployment created successfully');
622622

623-
$result = $this->deploymentTracker->createDeployment(
623+
$result = $this->deploymentTracker->setDeployment(
624624
$description,
625625
$changelog,
626626
$user,

dev/tests/integration/testsuite/Magento/NewRelicReporting/Model/NerdGraph/DeploymentWorkflowTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testDeploymentWorkflowWhenDisabled()
122122
*/
123123
public function testDeploymentWorkflowWithMissingConfiguration()
124124
{
125-
$result = $this->deploymentTracker->createDeployment('Test deployment');
125+
$result = $this->deploymentTracker->setDeployment('Test deployment');
126126

127127
$this->assertFalse($result);
128128
}
@@ -322,7 +322,7 @@ public function testLoggerIntegration()
322322
public function testDeploymentWorkflowErrorHandling()
323323
{
324324
// This should fail gracefully and return false rather than throwing an exception
325-
$result = $this->deploymentTracker->createDeployment('Test deployment');
325+
$result = $this->deploymentTracker->setDeployment('Test deployment');
326326
$this->assertFalse($result);
327327
}
328328

@@ -371,7 +371,7 @@ public function testNerdGraphEntityGuidValidation()
371371
$this->assertEquals('MzgwNjUyNnxBUE18QVBQTElDQVRJT058OTE2OTk4', $entityGuid);
372372

373373
// Test deployment with valid entity GUID format
374-
$result = $this->deploymentTracker->createDeployment(
374+
$result = $this->deploymentTracker->setDeployment(
375375
'Entity GUID validation test',
376376
'Testing entity GUID handling',
377377
'entity-tester'
@@ -408,7 +408,7 @@ public function testNerdGraphUrlConfiguration()
408408
*/
409409
public function testDeploymentWithAllNerdGraphParameters()
410410
{
411-
$result = $this->deploymentTracker->createDeployment(
411+
$result = $this->deploymentTracker->setDeployment(
412412
'Full NerdGraph deployment test',
413413
'Complete changelog with all features',
414414
'nerdgraph-user',
@@ -432,7 +432,7 @@ public function testDeploymentWithAllNerdGraphParameters()
432432
*/
433433
public function testDeploymentWithMinimalNerdGraphParameters()
434434
{
435-
$result = $this->deploymentTracker->createDeployment('Minimal NerdGraph test');
435+
$result = $this->deploymentTracker->setDeployment('Minimal NerdGraph test');
436436

437437
// Should work with just description
438438
$this->assertFalse($result); // Fails with fake credentials
@@ -447,11 +447,11 @@ public function testDeploymentWithMinimalNerdGraphParameters()
447447
public function testDeploymentTrackerErrorHandlingScenarios()
448448
{
449449
// Test with missing entity GUID
450-
$result = $this->deploymentTracker->createDeployment('Error test 1');
450+
$result = $this->deploymentTracker->setDeployment('Error test 1');
451451
$this->assertFalse($result);
452452

453453
// Test with empty description
454-
$result = $this->deploymentTracker->createDeployment('');
454+
$result = $this->deploymentTracker->setDeployment('');
455455
$this->assertFalse($result);
456456
}
457457

0 commit comments

Comments
 (0)