Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
Add new configuration to show only one project
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-schi committed Sep 22, 2016
1 parent af2a64c commit e001099
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `sentry-monitor` collect the events (mostly exceptions) from sentry and plot

Download the `monitor.phar` file.

$ curl -OsL https://github.com/mi-schi/sentry-monitor/releases/download/1.1.0/monitor.phar
$ curl -OsL https://github.com/mi-schi/sentry-monitor/releases/download/stable/monitor.phar
$ chmod +x monitor.phar
## Usage
Expand All @@ -40,4 +40,4 @@ Start the build-in server with the default address `http://localhost:8006`:

monitor.phar run

Go to `http://localhost:8006/[organisation-slug]/3/hour`. The three defines the days on the x-axis that will be displayed. You can define `hour` or `day` as x-axis scale.
Go to `http://localhost:8006/[organisation-slug],3,hour,[project-name]`. The three defines the days on the x-axis that will be displayed. You can define `hour` or `day` as x-axis scale. The parameter `[project-name]` is optional.
3 changes: 0 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Silex\Application as BaseApplication;
use Silex\Provider\DoctrineServiceProvider;

/**
* @package MS\Sentry\Monitor
*/
class Application extends BaseApplication
{
/**
Expand Down
3 changes: 0 additions & 3 deletions src/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @package MS\Sentry\Monitor\Command
*/
class ImportCommand extends Command
{
/**
Expand Down
3 changes: 0 additions & 3 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\ProcessBuilder;

/**
* @package MS\Sentry\Monitor\Command
*/
class RunCommand extends Command
{
/**
Expand Down
3 changes: 0 additions & 3 deletions src/Migration/EventTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Doctrine\DBAL\Connection;

/**
* @package MS\Sentry\Monitor\Migration
*/
class EventTable
{
/**
Expand Down
3 changes: 0 additions & 3 deletions src/Model/SentryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace MS\Sentry\Monitor\Model;

/**
* @package MS\Sentry\Monitor\Model
*/
class SentryRequest
{
/**
Expand Down
41 changes: 41 additions & 0 deletions src/Service/Diagram/ProjectFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace MS\Sentry\Monitor\Service\Diagram;

use Doctrine\DBAL\Connection;

class ProjectFinder
{
/**
* @var Connection
*/
private $connection;

/**
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}

/**
* @param string $organisation
* @param string $project
*
* @return array
*/
public function getProjects($organisation, $project)
{
if (false === empty($project)) {
return [$project];
}

$projects = $this->connection->fetchAll(
'SELECT project FROM events WHERE organisation = ? GROUP BY project',
[$organisation]
);

return array_column($projects, 'project');
}
}
14 changes: 3 additions & 11 deletions src/Service/Diagram/SequenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Doctrine\DBAL\Connection;

/**
* @package MS\Sentry\Monitor\Diagram
*/
class SequenceProvider
{
/**
Expand All @@ -23,13 +20,13 @@ public function __construct(Connection $connection)
}

/**
* @param string $organisation
* @param array $projects
* @param string $days
* @param string $scale
*
* @return array
*/
public function getSequences($organisation, $days, $scale)
public function getSequences(array $projects, $days, $scale)
{
if (false === filter_var($days, FILTER_VALIDATE_INT)) {
throw new \InvalidArgumentException(sprintf('The days parameter "%s" should be an integer', $days));
Expand All @@ -43,12 +40,7 @@ public function getSequences($organisation, $days, $scale)
$datetimeFormat = $this->getDatetimeFormat($scale);
$points = $this->getZeroSizedPoints($days, $scale);

$projects = $this->connection->fetchAll(
'SELECT project FROM events WHERE organisation = ? GROUP BY project',
[$organisation]
);

foreach (array_column($projects, 'project') as $project) {
foreach ($projects as $project) {
$data[] = [
'label' => $project,
'data' => $this->getFilledPoints($points, $datetimeFormat, $project)
Expand Down
3 changes: 0 additions & 3 deletions src/Service/Import/EventCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
use MS\Sentry\Monitor\Model\SentryRequest;
use MS\Sentry\Monitor\Service\SentryClient;

/**
* @package MS\Sentry\Monitor\Service\Import
*/
class EventCollector
{
const EVENTS_PATTERN = '/api/0/projects/%s/%s/events/';
Expand Down
3 changes: 0 additions & 3 deletions src/Service/Import/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Doctrine\DBAL\Connection;

/**
* @package MS\Sentry\Monitor\Service\Import
*/
class Importer
{
/**
Expand Down
3 changes: 0 additions & 3 deletions src/Service/Import/ProjectCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
use MS\Sentry\Monitor\Model\SentryRequest;
use MS\Sentry\Monitor\Service\SentryClient;

/**
* @package MS\Sentry\Monitor\Service\Import
*/
class ProjectCollector
{
const PROJECTS_PATTERN = '/api/0/organizations/%s/projects/';
Expand Down
3 changes: 0 additions & 3 deletions src/Service/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
use MS\Sentry\Monitor\Model\SentryRequest;
use GuzzleHttp\Client;

/**
* @package MS\Sentry\Monitor\Service
*/
class SentryClient
{
/**
Expand Down
14 changes: 11 additions & 3 deletions web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@

use MS\Sentry\Monitor\Application as App;
use MS\Sentry\Monitor\Service\Diagram\SequenceProvider;
use MS\Sentry\Monitor\Service\Diagram\ProjectFinder;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\HttpFoundation\JsonResponse;

$app = new App;
$app['debug'] = true;

$app['diagram.project.finder'] = $app->share(function ($app) {
return new ProjectFinder($app['db']);
});

$app['diagram.sequence.provider'] = $app->share(function ($app) {
return new SequenceProvider($app['db']);
});
Expand All @@ -24,12 +29,15 @@
'twig.path' => __DIR__ . '/../resources/views',
]);

$app->get('/{organisation}/{days}/{scale}', function () use ($app) {
$app->get('/{configuration}', function () use ($app) {
return $app['twig']->render('index.twig');
});

$app->get('/api/{organisation}/{days}/{scale}', function ($organisation, $days, $scale) use ($app) {
return new JsonResponse($app['diagram.sequence.provider']->getSequences($organisation, $days, $scale));
$app->get('/api/{configuration}', function ($configuration) use ($app) {
list($organisation, $days, $scale, $project) = explode(',', $configuration);
$projects = $app['diagram.project.finder']->getProjects($organisation, $project);

return new JsonResponse($app['diagram.sequence.provider']->getSequences($projects, $days, $scale));
});

$app->run();

0 comments on commit e001099

Please sign in to comment.