Skip to content

Commit 2397069

Browse files
committed
Merge branch 'newrelic-api' of github.com:comwrap/magento2 into 2.4-develop
2 parents 6fcb52f + 5a9d272 commit 2397069

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected function configure()
6262
'user',
6363
InputArgument::OPTIONAL,
6464
'Deployment User'
65+
)->addArgument(
66+
'revision',
67+
InputArgument::OPTIONAL,
68+
'Revision'
6569
);
6670
parent::configure();
6771
}
@@ -74,7 +78,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7478
$this->deploymentsFactory->create()->setDeployment(
7579
$input->getArgument('message'),
7680
$input->getArgument('change_log'),
77-
$this->serviceShellUser->get($input->getArgument('user'))
81+
$this->serviceShellUser->get($input->getArgument('user')),
82+
$input->getArgument('revision')
7883
);
7984
$output->writeln('<info>NewRelic deployment information sent</info>');
8085
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Deployments
1515
/**
1616
* API URL for New Relic deployments
1717
*/
18-
const API_URL = 'https://api.newrelic.com/deployments.xml';
18+
const API_URL = 'https://api.newrelic.com/v2/applications/%s/deployments.json';
1919

2020
/**
2121
* @var \Magento\NewRelicReporting\Model\Config
@@ -58,28 +58,39 @@ public function __construct(
5858
*
5959
* @return bool|string
6060
*/
61-
public function setDeployment($description, $change = false, $user = false)
61+
public function setDeployment($description, $change = false, $user = false, $revision = null)
6262
{
6363
$apiUrl = $this->config->getNewRelicApiUrl();
64-
6564
if (empty($apiUrl)) {
6665
$this->logger->notice('New Relic API URL is blank, using fallback URL');
6766
$apiUrl = self::API_URL;
6867
}
6968

69+
$apiUrl = sprintf($apiUrl, $this->config->getNewRelicAppId());
70+
7071
/** @var \Magento\Framework\HTTP\ZendClient $client */
7172
$client = $this->clientFactory->create();
7273
$client->setUri($apiUrl);
7374
$client->setMethod(ZendClient::POST);
7475

75-
$client->setHeaders(['x-api-key' => $this->config->getNewRelicApiKey()]);
76+
$client->setHeaders(
77+
[
78+
'Api-Key' => $this->config->getNewRelicApiKey(),
79+
'Content-Type' => 'application/json'
80+
]
81+
);
82+
83+
if (!$revision) {
84+
$revision = hash('sha256', time());
85+
}
7686

7787
$params = [
78-
'deployment[app_name]' => $this->config->getNewRelicAppName(),
79-
'deployment[application_id]' => $this->config->getNewRelicAppId(),
80-
'deployment[description]' => $description,
81-
'deployment[changelog]' => $change,
82-
'deployment[user]' => $user
88+
'deployment' => [
89+
'description' => $description,
90+
'changelog' => $change,
91+
'user' => $user,
92+
'revision' => $revision
93+
]
8394
];
8495

8596
$client->setParameterPost($params);

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function setUp(): void
5959
->getMockForAbstractClass();
6060

6161
$this->configMock = $this->getMockBuilder(Config::class)
62-
->setMethods(['getNewRelicApiUrl', 'getNewRelicApiKey', 'getNewRelicAppName', 'getNewRelicAppId'])
62+
->setMethods(['getNewRelicApiUrl', 'getNewRelicApiKey', 'getNewRelicAppId'])
6363
->disableOriginalConstructor()
6464
->getMock();
6565

@@ -109,10 +109,6 @@ public function testSetDeploymentRequestOk()
109109
->method('getNewRelicApiKey')
110110
->willReturn($data['api_key']);
111111

112-
$this->configMock->expects($this->once())
113-
->method('getNewRelicAppName')
114-
->willReturn($data['app_name']);
115-
116112
$this->configMock->expects($this->once())
117113
->method('getNewRelicAppId')
118114
->willReturn($data['app_id']);
@@ -130,7 +126,7 @@ public function testSetDeploymentRequestOk()
130126
->method('create')
131127
->willReturn($this->zendClientMock);
132128

133-
$this->assertIsString($this->model->setDeployment($data['description'], $data['change'], $data['user']));
129+
$this->assertIsString($this->model->setDeployment($data['description'], $data['change'], $data['user'], $data['revision']));
134130
}
135131

136132
/**
@@ -170,10 +166,6 @@ public function testSetDeploymentBadStatus()
170166
->method('getNewRelicApiKey')
171167
->willReturn($data['api_key']);
172168

173-
$this->configMock->expects($this->once())
174-
->method('getNewRelicAppName')
175-
->willReturn($data['app_name']);
176-
177169
$this->configMock->expects($this->once())
178170
->method('getNewRelicAppId')
179171
->willReturn($data['app_id']);
@@ -191,7 +183,7 @@ public function testSetDeploymentBadStatus()
191183
->method('create')
192184
->willReturn($this->zendClientMock);
193185

194-
$this->assertIsBool($this->model->setDeployment($data['description'], $data['change'], $data['user']));
186+
$this->assertIsBool($this->model->setDeployment($data['description'], $data['change'], $data['user'], $data['revision']));
195187
}
196188

197189
/**
@@ -229,10 +221,6 @@ public function testSetDeploymentRequestFail()
229221
->method('getNewRelicApiKey')
230222
->willReturn($data['api_key']);
231223

232-
$this->configMock->expects($this->once())
233-
->method('getNewRelicAppName')
234-
->willReturn($data['app_name']);
235-
236224
$this->configMock->expects($this->once())
237225
->method('getNewRelicAppId')
238226
->willReturn($data['app_id']);
@@ -246,7 +234,7 @@ public function testSetDeploymentRequestFail()
246234
->method('create')
247235
->willReturn($this->zendClientMock);
248236

249-
$this->assertIsBool($this->model->setDeployment($data['description'], $data['change'], $data['user']));
237+
$this->assertIsBool($this->model->setDeployment($data['description'], $data['change'], $data['user'], $data['revision']));
250238
}
251239

252240
/**
@@ -258,23 +246,26 @@ private function getDataVariables()
258246
$change = 'flush the cache username';
259247
$user = 'username';
260248
$uri = 'https://example.com/listener';
261-
$selfUri = 'https://api.newrelic.com/deployments.xml';
249+
$selfUri = 'https://api.newrelic.com/v2/applications/%s/deployments.json';
262250
$apiKey = '1234';
263251
$appName = 'app_name';
264252
$appId = 'application_id';
265253
$method = ZendClient::POST;
266-
$headers = ['x-api-key' => $apiKey];
254+
$headers = ['Api-Key' => $apiKey, 'Content-Type' => 'application/json'];
267255
$responseBody = 'Response body content';
268256
$statusOk = '200';
269257
$statusBad = '401';
258+
$revision = 'f81d42327219e17b1427096c354e9b8209939d4dd586972f12f0352f8343b91b';
270259
$params = [
271-
'deployment[app_name]' => $appName,
272-
'deployment[application_id]' => $appId,
273-
'deployment[description]' => $description,
274-
'deployment[changelog]' => $change,
275-
'deployment[user]' => $user
260+
'deployment' => [
261+
'description' => $description,
262+
'changelog' => $change,
263+
'user' => $user,
264+
'revision' => $revision
265+
]
276266
];
277267

268+
$selfUri = sprintf($selfUri, $appId);
278269
return ['description' => $description,
279270
'change' => $change,
280271
'user' => $user,
@@ -288,7 +279,8 @@ private function getDataVariables()
288279
'status_ok' => $statusOk,
289280
'status_bad' => $statusBad,
290281
'response_body' => $responseBody,
291-
'params' => $params
282+
'params' => $params,
283+
'revision' => $revision
292284
];
293285
}
294286
}

app/code/Magento/NewRelicReporting/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<newrelicreporting>
1111
<general>
1212
<enable>0</enable>
13-
<api_url>https://api.newrelic.com/deployments.xml</api_url>
13+
<api_url>https://api.newrelic.com/v2/applications/%s/deployments.json</api_url>
1414
<insights_api_url>https://insights-collector.newrelic.com/v1/accounts/%s/events</insights_api_url>
1515
</general>
1616
<cron>

0 commit comments

Comments
 (0)