From 63db3adca9ead65f1c85590d8a939b5bc4d1d152 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 19 Nov 2017 18:32:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B0=D0=BD=D0=BD=D0=BE=D1=82=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B1=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B8=D0=B7=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20Yii2=20=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/aop/AspectKernel.php | 1 + api/aop/annotations/CollectModelMetrics.php | 19 +++++++++ api/aop/aspects/CollectMetricsAspect.php | 41 +++++++++++++++++++ .../authentication/ConfirmEmailForm.php | 2 + .../authentication/ForgotPasswordForm.php | 6 +++ api/models/authentication/LoginForm.php | 2 + api/models/authentication/LogoutForm.php | 8 +++- .../authentication/RecoverPasswordForm.php | 2 + .../authentication/RefreshTokenForm.php | 2 + .../authentication/RegistrationForm.php | 2 + .../RepeatAccountActivationForm.php | 6 +++ 11 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 api/aop/annotations/CollectModelMetrics.php create mode 100644 api/aop/aspects/CollectMetricsAspect.php diff --git a/api/aop/AspectKernel.php b/api/aop/AspectKernel.php index 79cc8ed..fc30542 100644 --- a/api/aop/AspectKernel.php +++ b/api/aop/AspectKernel.php @@ -9,6 +9,7 @@ class AspectKernel extends BaseAspectKernel { protected function configureAop(AspectContainer $container): void { $container->registerAspect(new aspects\MockDataAspect()); + $container->registerAspect(new aspects\CollectMetricsAspect()); } } diff --git a/api/aop/annotations/CollectModelMetrics.php b/api/aop/annotations/CollectModelMetrics.php new file mode 100644 index 0000000..4614c91 --- /dev/null +++ b/api/aop/annotations/CollectModelMetrics.php @@ -0,0 +1,19 @@ +getMethod()->getAnnotation(CollectModelMetrics::class); + $prefix = trim($annotation->prefix, '.'); + + Yii::$app->statsd->inc($prefix . '.attempt'); + $result = $invocation->proceed(); + if ($result !== false) { + Yii::$app->statsd->inc($prefix . '.success'); + return $result; + } + + /** @var \yii\base\Model $model */ + $model = $invocation->getThis(); + $errors = array_values($model->getFirstErrors()); + if (!isset($errors[0])) { + Yii::error('Unsuccess result with empty errors list'); + return false; + } + + Yii::$app->statsd->inc($prefix . '.' . $errors[0]); + + return false; + } + +} diff --git a/api/models/authentication/ConfirmEmailForm.php b/api/models/authentication/ConfirmEmailForm.php index ac5f78f..c813ac0 100644 --- a/api/models/authentication/ConfirmEmailForm.php +++ b/api/models/authentication/ConfirmEmailForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/models/authentication/LoginForm.php b/api/models/authentication/LoginForm.php index 1e51eed..c5a2948 100644 --- a/api/models/authentication/LoginForm.php +++ b/api/models/authentication/LoginForm.php @@ -1,6 +1,7 @@ user; + $component = Yii::$app->user; $session = $component->getActiveSession(); if ($session === null) { return true; diff --git a/api/models/authentication/RecoverPasswordForm.php b/api/models/authentication/RecoverPasswordForm.php index ce21498..358fec0 100644 --- a/api/models/authentication/RecoverPasswordForm.php +++ b/api/models/authentication/RecoverPasswordForm.php @@ -1,6 +1,7 @@ validate()) { return false;