Skip to content

Commit 94f7ef7

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

File tree

11 files changed

+1499
-181
lines changed

11 files changed

+1499
-181
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107107
$isEnabled = $this->config->isNewRelicEnabled();
108108
if (!$isEnabled) {
109109
$output->writeln('<error>✗ New Relic is not enabled. Please check your configuration.</error>');
110-
return 1;
110+
return Command::FAILURE;
111111
}
112112
try {
113113
$result = $this->deploymentsFactory->create()->setDeployment(
@@ -128,22 +128,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128128
$this->displayDeploymentDetails($output, $result);
129129
}
130130

131-
return 0;
131+
return Command::SUCCESS;
132132
} else {
133133
$output->writeln('<error>✗ Failed to create deployment marker</error>');
134-
return 1;
134+
return Command::FAILURE;
135135
}
136-
137-
} catch (LocalizedException $e) {
138-
$output->writeln('<error>✗ Configuration Error!</error>');
139-
$output->writeln('<error>' . $e->getMessage() . '</error>');
140-
$output->writeln('');
141-
$output->writeln('<comment>Please check your New Relic configuration at:</comment>');
142-
$output->writeln('<comment>Admin → Stores → Configuration → General → New Relic Reporting</comment>');
143-
return 1;
144136
} catch (\Exception $e) {
145137
$output->writeln('<error>✗ Error: ' . $e->getMessage() . '</error>');
146-
return 1;
138+
return Command::FAILURE;
147139
}
148140
}
149141

@@ -174,8 +166,8 @@ private function displayDeploymentDetails(OutputInterface $output, array $deploy
174166
) : 'N/A']
175167
];
176168

177-
if (!empty($deployment['changelog'])) {
178-
$rows[] = ['Change log', $deployment['changelog']];
169+
if (!empty($deployment['change_log'])) {
170+
$rows[] = ['Change log', $deployment['change_log']];
179171
}
180172
if (!empty($deployment['commit'])) {
181173
$rows[] = ['Commit', $deployment['commit']];

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
class Deployments
2121
{
22-
2322
/**
2423
* API URL for New Relic deployments
2524
*/
@@ -152,7 +151,7 @@ private function createV2RestDeployment(string $description, bool|string $change
152151
$params = [
153152
'deployment' => [
154153
'description' => $description,
155-
'changelog' => $changelog,
154+
'change_log' => $changelog,
156155
'user' => $user,
157156
'revision' => $revision
158157
]

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ class Config
5555
public const DISABLED = 'disabled';
5656
public const TRUE = 'true';
5757
public const FALSE = 'false';
58+
/**#@-*/
59+
60+
/**#@+
61+
* Configuration paths
62+
*/
63+
public const XML_PATH_ENABLED = 'newrelicreporting/general/enable';
64+
public const XML_PATH_API_URL = 'newrelicreporting/general/api_url';
65+
public const XML_PATH_INSIGHTS_API_URL = 'newrelicreporting/general/insights_api_url';
66+
public const XML_PATH_ACCOUNT_ID = 'newrelicreporting/general/account_id';
67+
public const XML_PATH_APP_ID = 'newrelicreporting/general/app_id';
68+
public const XML_PATH_API_KEY = 'newrelicreporting/general/api';
69+
public const XML_PATH_INSIGHTS_INSERT_KEY = 'newrelicreporting/general/insights_insert_key';
70+
public const XML_PATH_APP_NAME = 'newrelicreporting/general/app_name';
71+
public const XML_PATH_SEPARATE_APPS = 'newrelicreporting/general/separate_apps';
72+
public const XML_PATH_CRON_ENABLED = 'newrelicreporting/cron/enable_cron';
73+
public const XML_PATH_API_MODE = 'newrelicreporting/general/api_mode';
74+
public const XML_PATH_ENTITY_GUID = 'newrelicreporting/general/entity_guid';
75+
public const XML_PATH_NERD_GRAPH_API_URL = 'newrelicreporting/general/nerd_graph_api_url';
5876

5977
/**
6078
* @var ScopeConfigInterface
@@ -95,7 +113,7 @@ public function __construct(
95113
*/
96114
public function isNewRelicEnabled()
97115
{
98-
return $this->scopeConfig->isSetFlag('newrelicreporting/general/enable');
116+
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED);
99117
}
100118

101119
/**
@@ -105,7 +123,7 @@ public function isNewRelicEnabled()
105123
*/
106124
public function getNewRelicApiUrl()
107125
{
108-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/api_url');
126+
return (string)$this->scopeConfig->getValue(self::XML_PATH_API_URL);
109127
}
110128

111129
/**
@@ -115,7 +133,7 @@ public function getNewRelicApiUrl()
115133
*/
116134
public function getInsightsApiUrl()
117135
{
118-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/insights_api_url');
136+
return (string)$this->scopeConfig->getValue(self::XML_PATH_INSIGHTS_API_URL);
119137
}
120138

121139
/**
@@ -125,7 +143,7 @@ public function getInsightsApiUrl()
125143
*/
126144
public function getNewRelicAccountId()
127145
{
128-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/account_id');
146+
return (string)$this->scopeConfig->getValue(self::XML_PATH_ACCOUNT_ID);
129147
}
130148

131149
/**
@@ -135,7 +153,7 @@ public function getNewRelicAccountId()
135153
*/
136154
public function getNewRelicAppId()
137155
{
138-
return (int)$this->scopeConfig->getValue('newrelicreporting/general/app_id');
156+
return (int)$this->scopeConfig->getValue(self::XML_PATH_APP_ID);
139157
}
140158

141159
/**
@@ -145,7 +163,7 @@ public function getNewRelicAppId()
145163
*/
146164
public function getNewRelicApiKey()
147165
{
148-
return $this->encryptor->decrypt($this->scopeConfig->getValue('newrelicreporting/general/api'));
166+
return $this->encryptor->decrypt($this->scopeConfig->getValue(self::XML_PATH_API_KEY));
149167
}
150168

151169
/**
@@ -155,7 +173,7 @@ public function getNewRelicApiKey()
155173
*/
156174
public function getInsightsInsertKey()
157175
{
158-
return $this->encryptor->decrypt($this->scopeConfig->getValue('newrelicreporting/general/insights_insert_key'));
176+
return $this->encryptor->decrypt($this->scopeConfig->getValue(self::XML_PATH_INSIGHTS_INSERT_KEY));
159177
}
160178

161179
/**
@@ -165,7 +183,7 @@ public function getInsightsInsertKey()
165183
*/
166184
public function getNewRelicAppName()
167185
{
168-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/app_name');
186+
return (string)$this->scopeConfig->getValue(self::XML_PATH_APP_NAME);
169187
}
170188

171189
/**
@@ -175,7 +193,7 @@ public function getNewRelicAppName()
175193
*/
176194
public function isSeparateApps()
177195
{
178-
return (bool)$this->scopeConfig->getValue('newrelicreporting/general/separate_apps');
196+
return (bool)$this->scopeConfig->getValue(self::XML_PATH_SEPARATE_APPS);
179197
}
180198

181199
/**
@@ -185,7 +203,7 @@ public function isSeparateApps()
185203
*/
186204
public function isCronEnabled()
187205
{
188-
return $this->scopeConfig->isSetFlag('newrelicreporting/cron/enable_cron');
206+
return $this->scopeConfig->isSetFlag(self::XML_PATH_CRON_ENABLED);
189207
}
190208

191209
/**
@@ -209,7 +227,7 @@ protected function setConfigValue($pathId, $value, $scope = 'default', $scopeId
209227
*/
210228
public function disableModule()
211229
{
212-
$this->setConfigValue('newrelicreporting/general/enable', 0);
230+
$this->setConfigValue(self::XML_PATH_ENABLED, 0);
213231
}
214232

215233
/**
@@ -219,7 +237,7 @@ public function disableModule()
219237
*/
220238
public function getApiMode()
221239
{
222-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/api_mode');
240+
return (string)$this->scopeConfig->getValue(self::XML_PATH_API_MODE);
223241
}
224242

225243
/**
@@ -229,7 +247,7 @@ public function getApiMode()
229247
*/
230248
public function getEntityGuid()
231249
{
232-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/entity_guid');
250+
return (string)$this->scopeConfig->getValue(self::XML_PATH_ENTITY_GUID);
233251
}
234252

235253
/**
@@ -249,6 +267,6 @@ public function isNerdGraphMode()
249267
*/
250268
public function getNerdGraphUrl()
251269
{
252-
return (string)$this->scopeConfig->getValue('newrelicreporting/general/nerd_graph_api_url');
270+
return (string)$this->scopeConfig->getValue(self::XML_PATH_NERD_GRAPH_API_URL);
253271
}
254272
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function addOptionalFields(
215215
?string $groupId
216216
): void {
217217
if ($changelog) {
218-
$variables['deployment']['changelog'] = $changelog;
218+
$variables['deployment']['change_log'] = $changelog;
219219
}
220220

221221
if ($user) {
@@ -277,7 +277,7 @@ private function processDeploymentResponse(
277277
'entityGuid' => $deploymentData['entityGuid'],
278278
'version' => $deployedVersion,
279279
'description' => $description,
280-
'changelog' => $changelog,
280+
'change_log' => $changelog,
281281
'user' => $user,
282282
'commit' => $commit,
283283
'deepLink' => $deepLink,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testExecuteSuccessWithArrayResultNerdGraphStyle()
181181
'description' => $message,
182182
'user' => $user,
183183
'timestamp' => 1234567890000, // Feb 13, 2009 23:31:30 UTC
184-
'changelog' => 'New features',
184+
'change_log' => 'New features',
185185
'commit' => $commit,
186186
'deepLink' => $deepLink,
187187
'groupId' => $groupId
@@ -330,10 +330,10 @@ public function testExecuteWithLocalizedException()
330330
$this->assertEquals(1, $result);
331331
$outputContent = $this->output->fetch();
332332

333-
// Group related assertions
334-
$expectedStrings = ['Configuration Error!', $exceptionMessage, 'Please check your New Relic configuration'];
333+
// Group related assertions - check for actual error format from DeployMarker command
334+
$expectedStrings = [' Error:', $exceptionMessage];
335335
foreach ($expectedStrings as $expected) {
336-
$this->assertStringContainsString($expected, $outputContent);
336+
$this->assertStringContainsString($expected, $outputContent);
337337
}
338338
$this->assertMatchesRegularExpression('/(✗|ERROR)/', $outputContent);
339339
}
@@ -431,7 +431,7 @@ public function testExecuteSuccessWithPartialDeploymentDataV2RestStyle()
431431
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $outputContent);
432432

433433
// Should show N/A for missing optional fields
434-
$excludedFields = ['Changelog', 'Commit', 'Deep Link', 'Group ID'];
434+
$excludedFields = ['changelog', 'Commit', 'Deep Link', 'Group ID'];
435435
foreach ($excludedFields as $field) {
436436
$this->assertStringNotContainsString($field, $outputContent);
437437
}
@@ -452,7 +452,7 @@ public function testExecuteSuccessWithCompleteDeploymentDataNerdGraphStyle()
452452
'description' => $message,
453453
'user' => 'complete-user',
454454
'timestamp' => 1640995200000, // 2022-01-01 00:00:00 UTC
455-
'changelog' => 'Added new features',
455+
'change_log' => 'Added new features',
456456
'commit' => 'abc123def456',
457457
'deepLink' => 'https://github.com/test/releases/v2.0.0',
458458
'groupId' => 'production'

0 commit comments

Comments
 (0)