Skip to content

Commit 85863af

Browse files
author
Oleksii Korshenko
authored
MAGETWO-84764: NewRelic: Disables Module Deployments, Creates new Deploy Marker Command #12477
2 parents 76b16b3 + 8f42543 commit 85863af

File tree

5 files changed

+122
-29
lines changed

5 files changed

+122
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Console\Command;
7+
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Magento\NewRelicReporting\Model\Apm\DeploymentsFactory;
13+
use Magento\NewRelicReporting\Model\ServiceShellUser;
14+
15+
class DeployMarker extends Command
16+
{
17+
/**
18+
* @var DeploymentsFactory
19+
*/
20+
protected $deploymentsFactory;
21+
22+
/**
23+
* @var ServiceShellUser
24+
*/
25+
protected $serviceShellUser;
26+
27+
/**
28+
* Initialize dependencies.
29+
*
30+
* @param DeploymentsFactory $deploymentsFactory
31+
* @param ServiceShellUser $serviceShellUser
32+
* @param null $name
33+
*/
34+
public function __construct(
35+
DeploymentsFactory $deploymentsFactory,
36+
ServiceShellUser $serviceShellUser,
37+
$name = null
38+
) {
39+
$this->deploymentsFactory = $deploymentsFactory;
40+
$this->serviceShellUser = $serviceShellUser;
41+
parent::__construct($name);
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
protected function configure()
48+
{
49+
$this->setName("newrelic:create:deploy-marker");
50+
$this->setDescription("Check the deploy queue for entries and create an appropriate deploy marker.")
51+
->addArgument(
52+
'message',
53+
InputArgument::REQUIRED,
54+
'Deploy Message?'
55+
)
56+
->addArgument(
57+
'changelog',
58+
InputArgument::REQUIRED,
59+
'Change Log?'
60+
)
61+
->addArgument(
62+
'user',
63+
InputArgument::OPTIONAL,
64+
'Deployment User'
65+
);
66+
parent::configure();
67+
}
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
protected function execute(InputInterface $input, OutputInterface $output)
73+
{
74+
$this->deploymentsFactory->create()->setDeployment(
75+
$input->getArgument('message'),
76+
$input->getArgument('changelog'),
77+
$this->serviceShellUser->get($input->getArgument('user'))
78+
);
79+
$output->writeln('<info>NewRelic deployment information sent</info>');
80+
}
81+
}

app/code/Magento/NewRelicReporting/Model/Cron/ReportNewRelicCron.php

-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ protected function reportCounts()
175175
public function report()
176176
{
177177
if ($this->config->isNewRelicEnabled()) {
178-
$this->reportModules();
179178
$this->reportCounts();
180179
}
181180

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Model;
7+
8+
class ServiceShellUser
9+
{
10+
/**
11+
* Default user name;
12+
*/
13+
const DEFAULT_USER = 'cron';
14+
15+
/**
16+
* Get use name.
17+
*
18+
* @param bool $userFromArgument
19+
* @return string
20+
*/
21+
public function get($userFromArgument = false)
22+
{
23+
if ($userFromArgument) {
24+
return $userFromArgument;
25+
}
26+
27+
$user = `echo \$USER`;
28+
if ($user) {
29+
return $user;
30+
}
31+
32+
return self::DEFAULT_USER;
33+
}
34+
}

app/code/Magento/NewRelicReporting/Test/Unit/Model/Cron/ReportNewRelicCronTest.php

-28
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,10 @@ public function testReportNewRelicCronModuleDisabledFromConfig()
144144
*/
145145
public function testReportNewRelicCron()
146146
{
147-
$testModuleData = [
148-
'changes' => [
149-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
150-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
151-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
152-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
153-
],
154-
'enabled' => 1,
155-
'disabled' => 1,
156-
'installed' => 1,
157-
];
158147

159148
$this->config->expects($this->once())
160149
->method('isNewRelicEnabled')
161150
->willReturn(true);
162-
$this->collect->expects($this->once())
163-
->method('getModuleData')
164-
->willReturn($testModuleData);
165151
$this->counter->expects($this->once())
166152
->method('getAllProductsCount');
167153
$this->counter->expects($this->once())
@@ -198,24 +184,10 @@ public function testReportNewRelicCron()
198184
*/
199185
public function testReportNewRelicCronRequestFailed()
200186
{
201-
$testModuleData = [
202-
'changes' => [
203-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
204-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
205-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
206-
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
207-
],
208-
'enabled' => 1,
209-
'disabled' => 1,
210-
'installed' => 1,
211-
];
212187

213188
$this->config->expects($this->once())
214189
->method('isNewRelicEnabled')
215190
->willReturn(true);
216-
$this->collect->expects($this->once())
217-
->method('getModuleData')
218-
->willReturn($testModuleData);
219191
$this->counter->expects($this->once())
220192
->method('getAllProductsCount');
221193
$this->counter->expects($this->once())

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

+7
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@
3030
<type name="Magento\Framework\App\Http">
3131
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
3232
</type>
33+
<type name="Magento\Framework\Console\CommandListInterface">
34+
<arguments>
35+
<argument name="commands" xsi:type="array">
36+
<item name="newrelicreporting_deploy_marker" xsi:type="object">Magento\NewRelicReporting\Console\Command\DeployMarker</item>
37+
</argument>
38+
</arguments>
39+
</type>
3340
</config>

0 commit comments

Comments
 (0)