Skip to content

NewRelic: Disables Module Deployments, Creates new Deploy Marker Command #12477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\NewRelicReporting\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Magento\NewRelicReporting\Model\Apm\DeploymentsFactory;
use Magento\NewRelicReporting\Model\ServiceShellUser;

class DeployMarker extends Command
{
/**
* @var DeploymentsFactory
*/
protected $deploymentsFactory;

/**
* @var ServiceShellUser
*/
protected $serviceShellUser;

/**
* Initialize dependencies.
*
* @param DeploymentsFactory $deploymentsFactory
* @param ServiceShellUser $serviceShellUser
* @param null $name
*/
public function __construct(
DeploymentsFactory $deploymentsFactory,
ServiceShellUser $serviceShellUser,
$name = null
) {
$this->deploymentsFactory = $deploymentsFactory;
$this->serviceShellUser = $serviceShellUser;
parent::__construct($name);
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName("newrelic:create:deploy-marker");
$this->setDescription("Check the deploy queue for entries and create an appropriate deploy marker.")
->addArgument(
'message',
InputArgument::REQUIRED,
'Deploy Message?'
)
->addArgument(
'changelog',
InputArgument::REQUIRED,
'Change Log?'
)
->addArgument(
'user',
InputArgument::OPTIONAL,
'Deployment User'
);
parent::configure();
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->deploymentsFactory->create()->setDeployment(
$input->getArgument('message'),
$input->getArgument('changelog'),
$this->serviceShellUser->get($input->getArgument('user'))
);
$output->writeln('<info>NewRelic deployment information sent</info>');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ protected function reportCounts()
public function report()
{
if ($this->config->isNewRelicEnabled()) {
$this->reportModules();
$this->reportCounts();
}

Expand Down
34 changes: 34 additions & 0 deletions app/code/Magento/NewRelicReporting/Model/ServiceShellUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\NewRelicReporting\Model;

class ServiceShellUser
{
/**
* Default user name;
*/
const DEFAULT_USER = 'cron';

/**
* Get use name.
*
* @param bool $userFromArgument
* @return string
*/
public function get($userFromArgument = false)
{
if ($userFromArgument) {
return $userFromArgument;
}

$user = `echo \$USER`;
if ($user) {
return $user;
}

return self::DEFAULT_USER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,10 @@ public function testReportNewRelicCronModuleDisabledFromConfig()
*/
public function testReportNewRelicCron()
{
$testModuleData = [
'changes' => [
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
],
'enabled' => 1,
'disabled' => 1,
'installed' => 1,
];

$this->config->expects($this->once())
->method('isNewRelicEnabled')
->willReturn(true);
$this->collect->expects($this->once())
->method('getModuleData')
->willReturn($testModuleData);
$this->counter->expects($this->once())
->method('getAllProductsCount');
$this->counter->expects($this->once())
Expand Down Expand Up @@ -198,24 +184,10 @@ public function testReportNewRelicCron()
*/
public function testReportNewRelicCronRequestFailed()
{
$testModuleData = [
'changes' => [
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
],
'enabled' => 1,
'disabled' => 1,
'installed' => 1,
];

$this->config->expects($this->once())
->method('isNewRelicEnabled')
->willReturn(true);
$this->collect->expects($this->once())
->method('getModuleData')
->willReturn($testModuleData);
$this->counter->expects($this->once())
->method('getAllProductsCount');
$this->counter->expects($this->once())
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/NewRelicReporting/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@
<type name="Magento\Framework\App\Http">
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
</type>
<type name="Magento\Framework\Console\CommandListInterface">
<arguments>
<argument name="commands" xsi:type="array">
<item name="newrelicreporting_deploy_marker" xsi:type="object">Magento\NewRelicReporting\Console\Command\DeployMarker</item>
</argument>
</arguments>
</type>
</config>