Add analytics engine (#3664)

This commit is contained in:
David Bomba 2020-04-30 22:33:57 +10:00 committed by GitHub
parent c503d58505
commit d7b22ba1db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 2 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\DataMapper\Analytics;
class LoginFailure
{
/**
* The type of Sample
*
* Monotonically incrementing counter
*
* - counter
*
* @var string
*/
public $type = 'counter';
/**
* The name of the counter
* @var string
*/
public $name = 'login.failure';
/**
* The datetime of the counter measurement
*
* date("Y-m-d H:i:s")
*
* @var DateTime
*/
public $datetime;
/**
* The increment amount... should always be
* set to 0
*
* @var integer
*/
public $metric = 0;
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\DataMapper\Analytics;
class LoginSuccess
{
/**
* The type of Sample
*
* Monotonically incrementing counter
*
* - counter
*
* @var string
*/
public $type = 'counter';
/**
* The name of the counter
* @var string
*/
public $name = 'login.success';
/**
* The datetime of the counter measurement
*
* date("Y-m-d H:i:s")
*
* @var DateTime
*/
public $datetime;
/**
* The increment amount... should always be
* set to 0
*
* @var integer
*/
public $metric = 0;
}

View File

@ -63,7 +63,7 @@ class Handler extends ExceptionHandler
'email' => "anonymous@example.com",
'name' => "Anonymous User",
]);
} elseif (auth()->guard('user')->user() && auth()->user()->company()->account->report_errors) {
} elseif (auth()->guard('user')->user() && auth()->user()->company() && auth()->user()->company()->account->report_errors) {
$scope->setUser([
'id' => auth()->user()->account->key,
'email' => "anonymous@example.com",

View File

@ -11,6 +11,8 @@
namespace App\Http\Controllers\Auth;
use App\DataMapper\Analytics\LoginFailure;
use App\DataMapper\Analytics\LoginSuccess;
use App\Http\Controllers\BaseController;
use App\Http\Controllers\Controller;
use App\Jobs\Account\CreateAccount;
@ -26,6 +28,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Laravel\Socialite\Facades\Socialite;
use Turbo124\Collector\CollectorFacade as Collector;
class LoginController extends BaseController
{
@ -168,6 +171,11 @@ class LoginController extends BaseController
}
if ($this->attemptLogin($request)) {
Collector::create(new LoginSuccess())
->increment()
->batch();
$user = $this->guard()->user();
$user->setCompany($user->company_user->account->default_company);
@ -177,6 +185,11 @@ class LoginController extends BaseController
return $this->listResponse($ct);
} else {
Collector::create(new LoginFailure())
->increment()
->batch();
$this->incrementLoginAttempts($request);
return response()

View File

@ -59,7 +59,7 @@ class SendFailedEmails implements ShouldQueue
private function processEmails()
{
\Log::error("processing emails");
//info("process emails");
//@todo check that the quota is available for the job

View File

@ -53,6 +53,7 @@
"staudenmeir/eloquent-has-many-deep": "^1.11",
"stripe/stripe-php": "^7.0",
"superbalist/laravel-google-cloud-storage": "^2.2",
"turbo124/collector": "^0.2.0",
"webpatser/laravel-countries": "dev-master#75992ad",
"yajra/laravel-datatables-oracle": "~9.0"
},

View File

@ -236,6 +236,8 @@ return [
'Countries' => 'Webpatser\Countries\CountriesFacade',
'CustomMessage' => App\Utils\ClientPortal\CustomMessage\CustomMessageFacade::class,
'Collector' => Turbo124\Collector\CollectorFacade::class,
],
];

31
config/collector.php Normal file
View File

@ -0,0 +1,31 @@
<?php
return [
/**
* Enable or disable the collector
*/
'enabled' => true,
/**
* The API endpoint for logs
*/
'endpoint' => 'https://app.lightlogs.com/api',
/**
* Your API key
*/
'api_key' => env('COLLECTOR_API_KEY',''),
/**
* Should batch requests
*/
'batch' => true,
/**
* The default key used to store
* metrics for batching
*/
'cache_key' => 'collector',
];

View File

@ -118,6 +118,7 @@ class RandomDataSeeder extends Seeder
'password' => Hash::make(config('ninja.testvars.password')),
'email_verified_at' => now(),
'client_id' =>$client->id,
'user_id' => $user->id,
'is_primary' => true,
'contact_key' => \Illuminate\Support\Str::random(40),
]);