Skip to content

Commit 9685121

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

File tree

14 files changed

+304
-68
lines changed

14 files changed

+304
-68
lines changed

app/code/Magento/NewRelicReporting/Console/Command/DeployMarker.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ class DeployMarker extends Command
3030
/**
3131
* @var Config
3232
*/
33-
private $config;
33+
private Config $config;
3434

3535
/**
3636
* Initialize dependencies.
3737
*
3838
* @param DeploymentsFactory $deploymentsFactory
3939
* @param ServiceShellUser $serviceShellUser
40-
* @param ?string $name
40+
* @param Config $config
41+
* @param string|null $name
4142
*/
4243
public function __construct(
4344
DeploymentsFactory $deploymentsFactory,
4445
ServiceShellUser $serviceShellUser,
4546
Config $config,
46-
$name = null
47+
string $name = null
4748
) {
4849
$this->deploymentsFactory = $deploymentsFactory;
4950
$this->serviceShellUser = $serviceShellUser;

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

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

88
use Laminas\Http\Exception\RuntimeException;
99
use Laminas\Http\Request;
10-
use Magento\Framework\Exception\LocalizedException;
1110
use Magento\Framework\HTTP\LaminasClientFactory;
1211
use Magento\Framework\Serialize\SerializerInterface;
1312
use Magento\NewRelicReporting\Model\Config;
@@ -88,7 +87,6 @@ public function __construct(
8887
* @param string|null $groupId Group ID (NerdGraph only)
8988
*
9089
* @return bool|string|array
91-
* @throws LocalizedException
9290
*/
9391
public function setDeployment(
9492
string $description,
@@ -98,7 +96,8 @@ public function setDeployment(
9896
?string $commit = null,
9997
?string $deepLink = null,
10098
?string $groupId = null
101-
) {
99+
): bool|array|string
100+
{
102101
// Check API mode configuration
103102
$apiMode = $this->config->getApiMode();
104103

@@ -126,7 +125,8 @@ public function setDeployment(
126125
* @param string|null $revision
127126
* @return bool|string
128127
*/
129-
private function createV2RestDeployment(string $description, bool|string $change, bool|string $user, ?string $revision): bool|string
128+
private function createV2RestDeployment(string $description, bool|string $change, bool|string $user, ?string
129+
$revision): bool|string
130130
{
131131
$apiUrl = $this->config->getNewRelicApiUrl();
132132
if (empty($apiUrl)) {
@@ -186,9 +186,9 @@ private function createV2RestDeployment(string $description, bool|string $change
186186
* @param string|null $deepLink
187187
* @param string|null $groupId
188188
* @return array|false
189-
* @throws LocalizedException
190189
*/
191-
private function createNerdGraphDeployment(string $description, bool|string $change, bool|string $user, ?string $revision, ?string $commit, ?string $deepLink, ?string $groupId): false|array
190+
private function createNerdGraphDeployment(string $description, bool|string $change, bool|string $user, ?string
191+
$revision, ?string $commit, ?string $deepLink, ?string $groupId): false|array
192192
{
193193
return $this->deploymentTracker->createDeployment(
194194
$description,

app/code/Magento/NewRelicReporting/Model/Config/Source/ApiMode.php

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

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

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

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

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

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

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

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

1212
/**
13+
* Observer to report system cache flush to New Relic
1314
* Class ReportSystemCacheFlushToNewRelic
1415
*/
1516
class ReportSystemCacheFlushToNewRelic implements ObserverInterface

app/code/Magento/NewRelicReporting/Test/Unit/Console/Command/DeployMarkerTest.php

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -156,13 +156,16 @@ public function testExecuteSuccessWithStringResult()
156156

157157
$this->assertEquals(0, $result);
158158
$outputContent = $this->output->fetch();
159-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
159+
$this->assertMatchesRegularExpression(
160+
'/(✓|OK) NewRelic deployment marker created successfully!/',
161+
$outputContent
162+
);
160163
}
161164

162165
/**
163166
* Test successful execution with array result (NerdGraph style)
164167
*/
165-
public function testExecuteSuccessWithArrayResult_NerdGraphStyle()
168+
public function testExecuteSuccessWithArrayResultNerdGraphStyle()
166169
{
167170
$message = 'Test NerdGraph deployment';
168171
$user = 'deploy-user';
@@ -217,8 +220,11 @@ public function testExecuteSuccessWithArrayResult_NerdGraphStyle()
217220
$this->assertStringContainsString($expected, $outputContent);
218221
}
219222

220-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
221-
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent); // timestamp converted (UTC)
223+
$this->assertMatchesRegularExpression(
224+
'/(✓|OK) NewRelic deployment marker created successfully!/',
225+
$outputContent
226+
);
227+
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent);
222228
}
223229

224230
/**
@@ -253,7 +259,10 @@ public function testExecuteSuccessWithMinimalParameters()
253259

254260
$this->assertEquals(0, $result);
255261
$outputContent = $this->output->fetch();
256-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
262+
$this->assertMatchesRegularExpression(
263+
'/(✓|OK) NewRelic deployment marker created successfully!/',
264+
$outputContent
265+
);
257266
}
258267

259268
/**
@@ -361,13 +370,16 @@ public function testExecuteWithGenericException()
361370

362371
$this->assertEquals(1, $result);
363372
$outputContent = $this->output->fetch();
364-
$this->assertMatchesRegularExpression('/(✗|ERROR) Error: ' . preg_quote($exceptionMessage, '/') . '/', $outputContent);
373+
$this->assertMatchesRegularExpression(
374+
'/(✗|ERROR) Error: ' . preg_quote($exceptionMessage, '/') . '/',
375+
$outputContent
376+
);
365377
}
366378

367379
/**
368380
* Test successful execution with partial deployment data (v2 REST API style)
369381
*/
370-
public function testExecuteSuccessWithPartialDeploymentData_V2RestStyle()
382+
public function testExecuteSuccessWithPartialDeploymentDataV2RestStyle()
371383
{
372384
$message = 'Test deployment';
373385

@@ -413,8 +425,11 @@ public function testExecuteSuccessWithPartialDeploymentData_V2RestStyle()
413425
$this->assertStringContainsString($expected, $outputContent);
414426
}
415427

416-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
417-
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent); // UTC timezone
428+
$this->assertMatchesRegularExpression(
429+
'/(✓|OK) NewRelic deployment marker created successfully!/',
430+
$outputContent
431+
);
432+
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent);
418433

419434
// Should show N/A for missing optional fields
420435
$excludedFields = ['Changelog', 'Commit', 'Deep Link', 'Group ID'];
@@ -426,7 +441,7 @@ public function testExecuteSuccessWithPartialDeploymentData_V2RestStyle()
426441
/**
427442
* Test successful execution with complete deployment data (NerdGraph style)
428443
*/
429-
public function testExecuteSuccessWithCompleteDeploymentData_NerdGraphStyle()
444+
public function testExecuteSuccessWithCompleteDeploymentDataNerdGraphStyle()
430445
{
431446
$message = 'Complete deployment';
432447

@@ -488,8 +503,11 @@ public function testExecuteSuccessWithCompleteDeploymentData_NerdGraphStyle()
488503
$this->assertStringContainsString($expected, $outputContent);
489504
}
490505

491-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
492-
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent); // UTC timezone
506+
$this->assertMatchesRegularExpression(
507+
'/(✓|OK) NewRelic deployment marker created successfully!/',
508+
$outputContent
509+
);
510+
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent);
493511

494512
// Should show all optional fields
495513
$requiredFields = ['Changelog', 'Commit', 'Deep Link', 'Group ID'];
@@ -548,7 +566,10 @@ public function testExecuteSuccessWithNullTimestamp()
548566

549567
$this->assertEquals(0, $result);
550568
$outputContent = $this->output->fetch();
551-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
569+
$this->assertMatchesRegularExpression(
570+
'/(✓|OK) NewRelic deployment marker created successfully!/',
571+
$outputContent
572+
);
552573
$this->assertStringContainsString('N/A', $outputContent); // For null timestamp
553574
}
554575

@@ -610,7 +631,10 @@ public function testExecuteWithEmptyMessage()
610631
// Should process empty message (validation handled by deployment service)
611632
$this->assertEquals(0, $result);
612633
$outputContent = $this->output->fetch();
613-
$this->assertMatchesRegularExpression('/(✓|OK) NewRelic deployment marker created successfully!/', $outputContent);
634+
$this->assertMatchesRegularExpression(
635+
'/(✓|OK) NewRelic deployment marker created successfully!/',
636+
$outputContent
637+
);
614638
}
615639

616640
/**

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

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

@@ -52,7 +52,6 @@ class DeploymentsTest extends TestCase
5252
*/
5353
private $serializerMock;
5454

55-
5655
/**
5756
* @var DeploymentTracker|MockObject
5857
*/

app/code/Magento/NewRelicReporting/Test/Unit/Model/ConfigTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public function testEncryptionDecryptionIntegration()
393393
public function testGetNerdGraphUrlWithEuEndpoint(): void
394394
{
395395
$euNerdGraphUrl = 'https://api.eu.newrelic.com/graphql';
396-
396+
397397
$this->scopeConfigMock->expects($this->once())
398398
->method('getValue')
399399
->with('newrelicreporting/general/nerd_graph_api_url')
@@ -409,7 +409,7 @@ public function testGetNerdGraphUrlWithEuEndpoint(): void
409409
public function testGetNewRelicApiUrlWithEuEndpoint(): void
410410
{
411411
$euApiUrl = 'https://api.eu.newrelic.com/v2/applications/%s/deployments.json';
412-
412+
413413
$this->scopeConfigMock->expects($this->once())
414414
->method('getValue')
415415
->with('newrelicreporting/general/api_url')
@@ -425,7 +425,7 @@ public function testGetNewRelicApiUrlWithEuEndpoint(): void
425425
public function testGetInsightsApiUrlWithEuEndpoint(): void
426426
{
427427
$euInsightsUrl = 'https://insights-collector.eu01.nr-data.net/v1/accounts/%s/events';
428-
428+
429429
$this->scopeConfigMock->expects($this->once())
430430
->method('getValue')
431431
->with('newrelicreporting/general/insights_api_url')
@@ -443,7 +443,8 @@ public function testCompleteEuEndpointConfiguration(): void
443443
$euEndpoints = [
444444
'newrelicreporting/general/nerd_graph_api_url' => 'https://api.eu.newrelic.com/graphql',
445445
'newrelicreporting/general/api_url' => 'https://api.eu.newrelic.com/v2/applications/%s/deployments.json',
446-
'newrelicreporting/general/insights_api_url' => 'https://insights-collector.eu01.nr-data.net/v1/accounts/%s/events',
446+
'newrelicreporting/general/insights_api_url' =>
447+
'https://insights-collector.eu01.nr-data.net/v1/accounts/%s/events',
447448
'newrelicreporting/general/api_mode' => 'nerdgraph',
448449
'newrelicreporting/general/enable' => '1'
449450
];
@@ -461,8 +462,14 @@ public function testCompleteEuEndpointConfiguration(): void
461462

462463
// Test all EU endpoints are configured correctly
463464
$this->assertEquals('https://api.eu.newrelic.com/graphql', $this->config->getNerdGraphUrl());
464-
$this->assertEquals('https://api.eu.newrelic.com/v2/applications/%s/deployments.json', $this->config->getNewRelicApiUrl());
465-
$this->assertEquals('https://insights-collector.eu01.nr-data.net/v1/accounts/%s/events', $this->config->getInsightsApiUrl());
465+
$this->assertEquals(
466+
'https://api.eu.newrelic.com/v2/applications/%s/deployments.json',
467+
$this->config->getNewRelicApiUrl()
468+
);
469+
$this->assertEquals(
470+
'https://insights-collector.eu01.nr-data.net/v1/accounts/%s/events',
471+
$this->config->getInsightsApiUrl()
472+
);
466473
$this->assertEquals('nerdgraph', $this->config->getApiMode());
467474
$this->assertTrue($this->config->isNewRelicEnabled());
468475
$this->assertTrue($this->config->isNerdGraphMode());

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

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

0 commit comments

Comments
 (0)