Skip to content

Commit 58bc821

Browse files
committed
AC-15461: Migration New Relic from REST v2 to NerdGraph (GraphQL)
1 parent c64c467 commit 58bc821

File tree

6 files changed

+53
-57
lines changed

6 files changed

+53
-57
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
* Supports both v2 REST and NerdGraph APIs based on configuration
8080
*
8181
* @param string $description
82-
* @param string|null $change
82+
* @param string|null $changelog
8383
* @param string|null $user
8484
* @param string|null $revision
8585
* @param string|null $commit Git commit hash (NerdGraph only)
@@ -90,7 +90,7 @@ public function __construct(
9090
*/
9191
public function setDeployment(
9292
string $description,
93-
?string $change = null,
93+
?string $changelog = null,
9494
?string $user = null,
9595
?string $revision = null,
9696
?string $commit = null,
@@ -103,28 +103,28 @@ public function setDeployment(
103103
if ($apiMode === ApiMode::MODE_NERDGRAPH) {
104104
return $this->createNerdGraphDeployment(
105105
$description,
106-
$change,
106+
$changelog,
107107
$user,
108108
$revision,
109109
$commit,
110110
$deepLink,
111111
$groupId
112112
);
113113
} else {
114-
return $this->createV2RestDeployment($description, $change, $user, $revision);
114+
return $this->createV2RestDeployment($description, $changelog, $user, $revision);
115115
}
116116
}
117117

118118
/**
119119
* Create deployment using v2 REST API (legacy)
120120
*
121121
* @param string $description
122-
* @param bool|string $change
122+
* @param bool|string $changelog
123123
* @param bool|string $user
124124
* @param string|null $revision
125125
* @return bool|string
126126
*/
127-
private function createV2RestDeployment(string $description, bool|string $change, bool|string $user, ?string
127+
private function createV2RestDeployment(string $description, bool|string $changelog, bool|string $user, ?string
128128
$revision): bool|string
129129
{
130130
$apiUrl = $this->config->getNewRelicApiUrl();
@@ -152,7 +152,7 @@ private function createV2RestDeployment(string $description, bool|string $change
152152
$params = [
153153
'deployment' => [
154154
'description' => $description,
155-
'changelog' => $change,
155+
'changelog' => $changelog,
156156
'user' => $user,
157157
'revision' => $revision
158158
]
@@ -178,20 +178,20 @@ private function createV2RestDeployment(string $description, bool|string $change
178178
* Create deployment using NerdGraph (GraphQL) API
179179
*
180180
* @param string $description
181-
* @param string|null $change
181+
* @param string|null $changelog
182182
* @param string|null $user
183183
* @param string|null $revision
184184
* @param string|null $commit
185185
* @param string|null $deepLink
186186
* @param string|null $groupId
187187
* @return array|false
188188
*/
189-
private function createNerdGraphDeployment(string $description, ?string $change, ?string $user, ?string
189+
private function createNerdGraphDeployment(string $description, ?string $changelog, ?string $user, ?string
190190
$revision, ?string $commit, ?string $deepLink, ?string $groupId): false|array
191191
{
192192
return $this->deploymentTracker->createDeployment(
193193
$description,
194-
$change ? (string)$change : null,
194+
$changelog ? (string)$changelog : null,
195195
$user ? (string)$user : null,
196196
$revision,
197197
$commit,

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
* Create a deployment marker via NerdGraph
5252
*
5353
* @param string $description Deployment description
54-
* @param string|null $change commit message
54+
* @param string|null $changelog commit message
5555
* @param string|null $user User who performed the deployment
5656
* @param string|null $version Version or revision
5757
* @param string|null $commit Git commit hash
@@ -61,7 +61,7 @@ public function __construct(
6161
*/
6262
public function createDeployment(
6363
string $description,
64-
?string $change = null,
64+
?string $changelog = null,
6565
?string $user = null,
6666
?string $version = null,
6767
?string $commit = null,
@@ -79,7 +79,7 @@ public function createDeployment(
7979
$entityGuid,
8080
$description,
8181
$version,
82-
$change,
82+
$changelog,
8383
$user,
8484
$commit,
8585
$deepLink,
@@ -92,7 +92,7 @@ public function createDeployment(
9292
$response,
9393
$variables,
9494
$description,
95-
$change,
95+
$changelog,
9696
$user,
9797
$commit,
9898
$deepLink,
@@ -163,7 +163,7 @@ private function getDeploymentMutation(): string
163163
* @param string $entityGuid
164164
* @param string $description
165165
* @param string|null $version
166-
* @param string|null $change
166+
* @param string|null $changelog
167167
* @param string|null $user
168168
* @param string|null $commit
169169
* @param string|null $deepLink
@@ -174,7 +174,7 @@ private function buildDeploymentVariables(
174174
string $entityGuid,
175175
string $description,
176176
?string $version,
177-
?string $change,
177+
?string $changelog,
178178
?string $user,
179179
?string $commit,
180180
?string $deepLink,
@@ -190,7 +190,7 @@ private function buildDeploymentVariables(
190190
]
191191
];
192192

193-
$this->addOptionalFields($variables, $change, $user, $commit, $deepLink, $groupId);
193+
$this->addOptionalFields($variables, $changelog, $user, $commit, $deepLink, $groupId);
194194

195195
return $variables;
196196
}
@@ -199,7 +199,7 @@ private function buildDeploymentVariables(
199199
* Add optional fields to deployment variables
200200
*
201201
* @param array $variables
202-
* @param string|null $change
202+
* @param string|null $changelog
203203
* @param string|null $user
204204
* @param string|null $commit
205205
* @param string|null $deepLink
@@ -208,14 +208,14 @@ private function buildDeploymentVariables(
208208
*/
209209
private function addOptionalFields(
210210
array &$variables,
211-
?string $change,
211+
?string $changelog,
212212
?string $user,
213213
?string $commit,
214214
?string $deepLink,
215215
?string $groupId
216216
): void {
217-
if ($change) {
218-
$variables['deployment']['changelog'] = $change;
217+
if ($changelog) {
218+
$variables['deployment']['changelog'] = $changelog;
219219
}
220220

221221
if ($user) {
@@ -241,7 +241,7 @@ private function addOptionalFields(
241241
* @param array $response
242242
* @param array $variables
243243
* @param string $description
244-
* @param string|null $change
244+
* @param string|null $changelog
245245
* @param string|null $user
246246
* @param string|null $commit
247247
* @param string|null $deepLink
@@ -252,7 +252,7 @@ private function processDeploymentResponse(
252252
array $response,
253253
array $variables,
254254
string $description,
255-
?string $change,
255+
?string $changelog,
256256
?string $user,
257257
?string $commit,
258258
?string $deepLink,
@@ -277,7 +277,7 @@ private function processDeploymentResponse(
277277
'entityGuid' => $deploymentData['entityGuid'],
278278
'version' => $deployedVersion,
279279
'description' => $description,
280-
'changelog' => $change,
280+
'changelog' => $changelog,
281281
'user' => $user,
282282
'commit' => $commit,
283283
'deepLink' => $deepLink,

app/code/Magento/NewRelicReporting/Model/Observer/ReportSystemCacheFlushToNewRelic.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright 2025 Adobe
4-
* All Rights Reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
55
*/
66
namespace Magento\NewRelicReporting\Model\Observer;
77

@@ -10,9 +10,7 @@
1010
use Magento\NewRelicReporting\Model\Config;
1111

1212
/**
13-
* Observer to report system cache flush to New Relic
1413
* Class ReportSystemCacheFlushToNewRelic
15-
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1614
*/
1715
class ReportSystemCacheFlushToNewRelic implements ObserverInterface
1816
{
@@ -51,7 +49,6 @@ public function __construct(
5149
*
5250
* @param Observer $observer
5351
* @return void
54-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5552
*/
5653
public function execute(Observer $observer)
5754
{
@@ -61,7 +58,7 @@ public function execute(Observer $observer)
6158
$this->deploymentsFactory->create()->setDeployment(
6259
'Cache Flush',
6360
$user->getUserName() . ' flushed the cache.',
64-
$user->getUserName() ?: false
61+
$user->getUserName()
6562
);
6663
}
6764
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function testSetDeploymentRequestFail()
295295
public function testSetDeploymentNerdGraphMode()
296296
{
297297
$description = 'NerdGraph deployment test';
298-
$change = 'Enhanced changelog';
298+
$changelog = 'Enhanced changelog';
299299
$user = 'nerdgraph_user';
300300
$revision = 'v2.0.0';
301301
$commit = 'abc123';
@@ -307,7 +307,7 @@ public function testSetDeploymentNerdGraphMode()
307307
'entityGuid' => 'TEST_ENTITY_GUID',
308308
'version' => $revision,
309309
'description' => $description,
310-
'changelog' => $change,
310+
'changelog' => $changelog,
311311
'user' => $user,
312312
'commit' => $commit,
313313
'deepLink' => $deepLink,
@@ -323,12 +323,12 @@ public function testSetDeploymentNerdGraphMode()
323323
// Mock DeploymentTracker to be called with correct parameters
324324
$this->deploymentTrackerMock->expects($this->once())
325325
->method('createDeployment')
326-
->with($description, $change, $user, $revision, $commit, $deepLink, $groupId)
326+
->with($description, $changelog, $user, $revision, $commit, $deepLink, $groupId)
327327
->willReturn($expectedNerdGraphResponse);
328328

329329
$result = $this->model->setDeployment(
330330
$description,
331-
$change,
331+
$changelog,
332332
$user,
333333
$revision,
334334
$commit,
@@ -386,7 +386,7 @@ public function testSetDeploymentNerdGraphModeFailure()
386386
public function testSetDeploymentModeDetectionNerdGraph()
387387
{
388388
$description = 'NerdGraph mode detection test';
389-
$change = 'Test changelog';
389+
$changelog = 'Test changelog';
390390
$user = 'test_user';
391391
$revision = 'v1.0.0';
392392

@@ -398,10 +398,10 @@ public function testSetDeploymentModeDetectionNerdGraph()
398398
$expectedResult = ['deploymentId' => 'test-123', 'entityGuid' => 'test-guid'];
399399
$this->deploymentTrackerMock->expects($this->once())
400400
->method('createDeployment')
401-
->with($description, $change, $user, $revision, null, null, null)
401+
->with($description, $changelog, $user, $revision, null, null, null)
402402
->willReturn($expectedResult);
403403

404-
$result = $this->model->setDeployment($description, $change, $user, $revision);
404+
$result = $this->model->setDeployment($description, $changelog, $user, $revision);
405405
$this->assertEquals($expectedResult, $result);
406406
}
407407

@@ -413,7 +413,7 @@ public function testSetDeploymentModeDetectionNerdGraph()
413413
public function testSetDeploymentNerdGraphEnhancedParameters()
414414
{
415415
$description = 'Enhanced parameters test';
416-
$change = 'changelog';
416+
$changelog = 'changelog';
417417
$user = 'test_user';
418418
$revision = 'v2.1.0';
419419
$commit = 'def456';
@@ -429,7 +429,7 @@ public function testSetDeploymentNerdGraphEnhancedParameters()
429429
->method('createDeployment')
430430
->with(
431431
$this->equalTo($description),
432-
$this->equalTo($change),
432+
$this->equalTo($changelog),
433433
$this->equalTo($user),
434434
$this->equalTo($revision),
435435
$this->equalTo($commit),
@@ -445,7 +445,7 @@ public function testSetDeploymentNerdGraphEnhancedParameters()
445445

446446
$result = $this->model->setDeployment(
447447
$description,
448-
$change,
448+
$changelog,
449449
$user,
450450
$revision,
451451
$commit,
@@ -468,7 +468,7 @@ public function testSetDeploymentNerdGraphEnhancedParameters()
468468
private function getDataVariables(): array
469469
{
470470
$description = 'Event description';
471-
$change = 'flush the cache username';
471+
$changelog = 'flush the cache username';
472472
$user = 'username';
473473
$uri = 'https://example.com/listener';
474474
$selfUri = 'https://api.newrelic.com/v2/applications/%s/deployments.json';
@@ -484,15 +484,15 @@ private function getDataVariables(): array
484484
$params = [
485485
'deployment' => [
486486
'description' => $description,
487-
'changelog' => $change,
487+
'changelog' => $changelog,
488488
'user' => $user,
489489
'revision' => $revision
490490
]
491491
];
492492

493493
$selfUri = sprintf($selfUri, $appId);
494494
return ['description' => $description,
495-
'change' => $change,
495+
'change' => $changelog,
496496
'user' => $user,
497497
'uri' => $uri,
498498
'self_uri' => $selfUri,

0 commit comments

Comments
 (0)