From 42b6bc561ee0011198be7a3514a12ab53c80b77d Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 16 Nov 2017 19:55:00 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20Yii2=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=20statsd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env-dist | 6 +++ autocompletion.php | 1 + common/components/StatsD.php | 89 ++++++++++++++++++++++++++++++++++++ common/config/config.php | 6 +++ 4 files changed, 102 insertions(+) create mode 100644 common/components/StatsD.php diff --git a/.env-dist b/.env-dist index acc5b32..b9dd499 100644 --- a/.env-dist +++ b/.env-dist @@ -35,6 +35,12 @@ RABBITMQ_USER=ely-accounts-app RABBITMQ_PASS=ely-accounts-app-password RABBITMQ_VHOST=/ely.by +## Параметры Statsd +STATSD_HOST=statsd.ely.by +STATSD_PORT=8125 +# This value can be blank +STATSD_NAMESPACE= + ## Конфигурация для Dev. XDEBUG_CONFIG=remote_host=10.254.254.254 PHP_IDE_CONFIG=serverName=docker diff --git a/autocompletion.php b/autocompletion.php index 3890cc7..1d5fd81 100644 --- a/autocompletion.php +++ b/autocompletion.php @@ -24,6 +24,7 @@ class Yii extends \yii\BaseYii { * @property \common\components\EmailRenderer $emailRenderer * @property \mito\sentry\Component $sentry * @property \api\components\OAuth2\Component $oauth + * @property \common\components\StatsD $statsd */ abstract class BaseApplication extends yii\base\Application { } diff --git a/common/components/StatsD.php b/common/components/StatsD.php new file mode 100644 index 0000000..172de0f --- /dev/null +++ b/common/components/StatsD.php @@ -0,0 +1,89 @@ +getClient()->increment($key); + } + + public function dec(string $key): void { + $this->getClient()->decrement($key); + } + + public function count(string $key, int $value): void { + $this->getClient()->count($key, $value); + } + + public function time(string $key, float $time): void { + $this->getClient()->timing($key, floor($time)); + } + + public function startTiming(string $key): void { + $this->getClient()->startTiming($key); + } + + public function endTiming(string $key): void { + $this->getClient()->endTiming($key); + } + + public function peakMemoryUsage(string $key): void { + $this->getClient()->memory($key); + } + + /** + * Pass delta values as a string. + * Accepts both positive (+11) and negative (-4) delta values. + * $statsd->gauge('foobar', 3); + * $statsd->gauge('foobar', '+11'); + * + * @param string $key + * @param string|int $value + */ + public function gauge(string $key, $value): void { + $this->getClient()->gauge($key, $value); + } + + public function set(string $key, int $value): void { + $this->getClient()->set($key, $value); + } + + public function getClient(): Client { + if ($this->client === null) { + $connection = $this->createConnection(); + $this->client = new Client($connection, $this->namespace); + } + + return $this->client; + } + + protected function createConnection(): Connection { + if (!empty($this->host) && !empty($this->port)) { + return new Connection\UdpSocket($this->host, $this->port); + } + + return new Connection\Blackhole(); + } + +} diff --git a/common/config/config.php b/common/config/config.php index d334a5c..c1e886b 100644 --- a/common/config/config.php +++ b/common/config/config.php @@ -90,6 +90,12 @@ return [ 'itemFile' => '@common/rbac/.generated/items.php', 'ruleFile' => '@common/rbac/.generated/rules.php', ], + 'statsd' => [ + 'class' => common\components\StatsD::class, + 'host' => getenv('STATSD_HOST'), + 'port' => getenv('STATSD_PORT') ?: 8125, + 'namespace' => getenv('STATSD_NAMESPACE') ?: 'ely.accounts.' . gethostname() . '.app', + ], ], 'container' => [ 'definitions' => [ From 72f546c827da04d4515b560db04ed4ac88c89177 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 17 Nov 2017 03:04:14 +0300 Subject: [PATCH 2/8] =?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=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B8=D0=BA=D0=B8=20=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/web/index.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/web/index.php b/api/web/index.php index 09a6f8b..00517a7 100644 --- a/api/web/index.php +++ b/api/web/index.php @@ -4,6 +4,8 @@ use api\aop\AspectKernel; use common\config\ConfigLoader; use yii\web\Application; +$time = microtime(true); + require __DIR__ . '/../../vendor/autoload.php'; defined('YII_DEBUG') or define('YII_DEBUG', in_array(getenv('YII_DEBUG'), ['true', '1'])); @@ -29,3 +31,7 @@ $config = ConfigLoader::load('api'); $application = new Application($config); $application->run(); + +$timeDifference = (microtime(true) - $time) * 1000; +fastcgi_finish_request(); +Yii::$app->statsd->time('request.time', $timeDifference); From 236f0e7d50b44e162ea06ce7738519133e5c1a69 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 19 Nov 2017 15:36:51 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=81=D0=B1=D0=BE=D1=80=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B2=20sessionserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/modules/session/models/HasJoinedForm.php | 12 +++++------ api/modules/session/models/JoinForm.php | 22 +++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/api/modules/session/models/HasJoinedForm.php b/api/modules/session/models/HasJoinedForm.php index 131c1f4..da5a2ee 100644 --- a/api/modules/session/models/HasJoinedForm.php +++ b/api/modules/session/models/HasJoinedForm.php @@ -6,6 +6,7 @@ use api\modules\session\exceptions\IllegalArgumentException; use api\modules\session\models\protocols\HasJoinedInterface; use api\modules\session\Module as Session; use common\models\Account; +use Yii; use yii\base\ErrorException; use yii\base\Model; @@ -19,6 +20,7 @@ class HasJoinedForm extends Model { } public function hasJoined(): Account { + Yii::$app->statsd->inc('sessionserver.hasJoined.attempt'); if (!$this->protocol->validate()) { throw new IllegalArgumentException(); } @@ -26,13 +28,12 @@ class HasJoinedForm extends Model { $serverId = $this->protocol->getServerId(); $username = $this->protocol->getUsername(); - Session::info( - "Server with server_id = '{$serverId}' trying to verify has joined user with username = '{$username}'." - ); + Session::info("Server with server_id = '{$serverId}' trying to verify has joined user with username = '{$username}'."); $joinModel = SessionModel::find($username, $serverId); if ($joinModel === null) { Session::error("Not found join operation for username = '{$username}'."); + Yii::$app->statsd->inc('sessionserver.hasJoined.fail_no_join'); throw new ForbiddenOperationException('Invalid token.'); } @@ -42,9 +43,8 @@ class HasJoinedForm extends Model { throw new ErrorException('Account must exists'); } - Session::info( - "User with username = '{$username}' successfully verified by server with server_id = '{$serverId}'." - ); + Session::info("User with username = '{$username}' successfully verified by server with server_id = '{$serverId}'."); + Yii::$app->statsd->inc('sessionserver.hasJoined.success'); return $account; } diff --git a/api/modules/session/models/JoinForm.php b/api/modules/session/models/JoinForm.php index 2676fb2..c3ec952 100644 --- a/api/modules/session/models/JoinForm.php +++ b/api/modules/session/models/JoinForm.php @@ -53,6 +53,7 @@ class JoinForm extends Model { $serverId = $this->serverId; $accessToken = $this->accessToken; Session::info("User with access_token = '{$accessToken}' trying join to server with server_id = '{$serverId}'."); + Yii::$app->statsd->inc('sessionserver.join.attempts'); if (!$this->validate()) { return false; } @@ -63,10 +64,8 @@ class JoinForm extends Model { throw new ErrorException('Cannot save join session model'); } - Session::info( - "User with access_token = '{$accessToken}' and nickname = '{$account->username}' successfully joined to " . - "server_id = '{$serverId}'." - ); + Session::info("User with access_token = '{$accessToken}' and nickname = '{$account->username}' successfully joined to server_id = '{$serverId}'."); + Yii::$app->statsd->inc('sessionserver.join.success'); return true; } @@ -100,6 +99,7 @@ class JoinForm extends Model { /** @var MinecraftAccessKey|\api\components\OAuth2\Entities\AccessTokenEntity $accessModel */ if ($accessModel->isExpired()) { Session::error("User with access_token = '{$accessToken}' failed join by expired access_token."); + Yii::$app->statsd->inc('sessionserver.join.fail_token_expired'); throw new ForbiddenOperationException('Expired access_token.'); } @@ -113,11 +113,13 @@ class JoinForm extends Model { if ($identity === null) { Session::error("User with access_token = '{$accessToken}' failed join by wrong access_token."); + Yii::$app->statsd->inc('sessionserver.join.fail_wrong_token'); throw new ForbiddenOperationException('Invalid access_token.'); } if (!Yii::$app->user->can(P::MINECRAFT_SERVER_SESSION)) { Session::error("User with access_token = '{$accessToken}' doesn't have enough scopes to make join."); + Yii::$app->statsd->inc('sessionserver.join.fail_not_enough_scopes'); throw new ForbiddenOperationException('The token does not have required scope.'); } @@ -127,18 +129,14 @@ class JoinForm extends Model { $selectedProfile = $this->selectedProfile; $isUuid = StringHelper::isUuid($selectedProfile); if ($isUuid && $account->uuid !== $this->normalizeUUID($selectedProfile)) { - Session::error( - "User with access_token = '{$accessToken}' trying to join with identity = '{$selectedProfile}'," . - " but access_token issued to account with id = '{$account->uuid}'." - ); + Session::error("User with access_token = '{$accessToken}' trying to join with identity = '{$selectedProfile}', but access_token issued to account with id = '{$account->uuid}'."); + Yii::$app->statsd->inc('sessionserver.join.fail_uuid_mismatch'); throw new ForbiddenOperationException('Wrong selected_profile.'); } if (!$isUuid && mb_strtolower($account->username) !== mb_strtolower($selectedProfile)) { - Session::error( - "User with access_token = '{$accessToken}' trying to join with identity = '{$selectedProfile}'," . - " but access_token issued to account with username = '{$account->username}'." - ); + Session::error("User with access_token = '{$accessToken}' trying to join with identity = '{$selectedProfile}', but access_token issued to account with username = '{$account->username}'."); + Yii::$app->statsd->inc('sessionserver.join.fail_username_mismatch'); throw new ForbiddenOperationException('Invalid credentials'); } From 63db3adca9ead65f1c85590d8a939b5bc4d1d152 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 19 Nov 2017 18:32:51 +0300 Subject: [PATCH 4/8] =?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; From 6ee40f3fcc4b51fbaea6b8d4f638c1e36b560b5c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 21 Nov 2017 19:58:55 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=81=D0=B1=D0=BE=D1=80=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B2=20oauth2=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/OauthProcess.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/models/OauthProcess.php b/api/models/OauthProcess.php index c666922..5d50582 100644 --- a/api/models/OauthProcess.php +++ b/api/models/OauthProcess.php @@ -87,6 +87,7 @@ class OauthProcess { */ public function complete(): array { try { + Yii::$app->statsd->inc('oauth.complete.attempt'); $grant = $this->getAuthorizationCodeGrant(); $authParams = $grant->checkAuthorizeParams(); $account = Yii::$app->user->identity->getAccount(); @@ -94,6 +95,7 @@ class OauthProcess { $clientModel = OauthClient::findOne($authParams->getClient()->getId()); if (!$this->canAutoApprove($account, $clientModel, $authParams)) { + Yii::$app->statsd->inc('oauth.complete.approve_required'); $isAccept = Yii::$app->request->post('accept'); if ($isAccept === null) { throw new AcceptRequiredException(); @@ -109,7 +111,12 @@ class OauthProcess { 'success' => true, 'redirectUri' => $redirectUri, ]; + Yii::$app->statsd->inc('oauth.complete.success'); } catch (OAuthException $e) { + if (!$e instanceof AcceptRequiredException) { + Yii::$app->statsd->inc('oauth.complete.fail'); + } + $response = $this->buildErrorResponse($e); } @@ -139,8 +146,11 @@ class OauthProcess { */ public function getToken(): array { try { + Yii::$app->statsd->inc('oauth.issueToken.attempt'); $response = $this->server->issueAccessToken(); + Yii::$app->statsd->inc('oauth.issueToken.success'); } catch (OAuthException $e) { + Yii::$app->statsd->inc('oauth.issueToken.fail'); Yii::$app->response->statusCode = $e->httpStatusCode; $response = [ 'error' => $e->errorType, From a94e7095c88c4567202ff387b173944dbf2ea04b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 21 Nov 2017 20:06:26 +0300 Subject: [PATCH 6/8] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=81=D0=B1=D0=BE=D1=80=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B2=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20=D1=81=20=D0=B0=D0=BA?= =?UTF-8?q?=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/modules/accounts/models/AcceptRulesForm.php | 4 ++++ api/modules/accounts/models/ChangeEmailForm.php | 4 ++++ api/modules/accounts/models/ChangeLanguageForm.php | 4 ++++ api/modules/accounts/models/ChangePasswordForm.php | 4 ++++ api/modules/accounts/models/ChangeUsernameForm.php | 4 ++++ api/modules/accounts/models/DisableTwoFactorAuthForm.php | 4 ++++ api/modules/accounts/models/EnableTwoFactorAuthForm.php | 4 ++++ api/modules/accounts/models/SendEmailVerificationForm.php | 4 ++++ api/modules/accounts/models/SendNewEmailVerificationForm.php | 4 ++++ 9 files changed, 36 insertions(+) diff --git a/api/modules/accounts/models/AcceptRulesForm.php b/api/modules/accounts/models/AcceptRulesForm.php index 83e207a..49ec85a 100644 --- a/api/modules/accounts/models/AcceptRulesForm.php +++ b/api/modules/accounts/models/AcceptRulesForm.php @@ -1,11 +1,15 @@ getAccount(); $account->rules_agreement_version = LATEST_RULES_VERSION; diff --git a/api/modules/accounts/models/ChangeEmailForm.php b/api/modules/accounts/models/ChangeEmailForm.php index d08c848..c1c92c4 100644 --- a/api/modules/accounts/models/ChangeEmailForm.php +++ b/api/modules/accounts/models/ChangeEmailForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/ChangeLanguageForm.php b/api/modules/accounts/models/ChangeLanguageForm.php index e1061de..b9502e3 100644 --- a/api/modules/accounts/models/ChangeLanguageForm.php +++ b/api/modules/accounts/models/ChangeLanguageForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/ChangePasswordForm.php b/api/modules/accounts/models/ChangePasswordForm.php index 48824ff..1782ef2 100644 --- a/api/modules/accounts/models/ChangePasswordForm.php +++ b/api/modules/accounts/models/ChangePasswordForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/ChangeUsernameForm.php b/api/modules/accounts/models/ChangeUsernameForm.php index 193712e..86fa961 100644 --- a/api/modules/accounts/models/ChangeUsernameForm.php +++ b/api/modules/accounts/models/ChangeUsernameForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/DisableTwoFactorAuthForm.php b/api/modules/accounts/models/DisableTwoFactorAuthForm.php index 7a98c44..ce8a429 100644 --- a/api/modules/accounts/models/DisableTwoFactorAuthForm.php +++ b/api/modules/accounts/models/DisableTwoFactorAuthForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/EnableTwoFactorAuthForm.php b/api/modules/accounts/models/EnableTwoFactorAuthForm.php index be86125..0e19639 100644 --- a/api/modules/accounts/models/EnableTwoFactorAuthForm.php +++ b/api/modules/accounts/models/EnableTwoFactorAuthForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/SendEmailVerificationForm.php b/api/modules/accounts/models/SendEmailVerificationForm.php index 47f596f..593215f 100644 --- a/api/modules/accounts/models/SendEmailVerificationForm.php +++ b/api/modules/accounts/models/SendEmailVerificationForm.php @@ -1,6 +1,7 @@ validate()) { return false; diff --git a/api/modules/accounts/models/SendNewEmailVerificationForm.php b/api/modules/accounts/models/SendNewEmailVerificationForm.php index 1c2823e..100c09b 100644 --- a/api/modules/accounts/models/SendNewEmailVerificationForm.php +++ b/api/modules/accounts/models/SendNewEmailVerificationForm.php @@ -1,6 +1,7 @@ validate()) { return false; From 6f7fcf9e44c14ff5c1e67a6c5e2ed499872ce076 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 21 Nov 2017 20:11:28 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D1=83?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D0=BE=20=D1=82=D0=B8=D0=BF=D0=B5=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/modules/session/models/JoinForm.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/modules/session/models/JoinForm.php b/api/modules/session/models/JoinForm.php index c3ec952..f53d7f5 100644 --- a/api/modules/session/models/JoinForm.php +++ b/api/modules/session/models/JoinForm.php @@ -96,10 +96,11 @@ class JoinForm extends Model { /** @var MinecraftAccessKey|null $accessModel */ $accessModel = MinecraftAccessKey::findOne($accessToken); if ($accessModel !== null) { + Yii::$app->statsd->inc('sessionserver.authentication.legacy_minecraft_protocol'); /** @var MinecraftAccessKey|\api\components\OAuth2\Entities\AccessTokenEntity $accessModel */ if ($accessModel->isExpired()) { Session::error("User with access_token = '{$accessToken}' failed join by expired access_token."); - Yii::$app->statsd->inc('sessionserver.join.fail_token_expired'); + Yii::$app->statsd->inc('sessionserver.authentication.legacy_minecraft_protocol_token_expired'); throw new ForbiddenOperationException('Expired access_token.'); } @@ -117,9 +118,10 @@ class JoinForm extends Model { throw new ForbiddenOperationException('Invalid access_token.'); } + Yii::$app->statsd->inc('sessionserver.authentication.oauth2'); if (!Yii::$app->user->can(P::MINECRAFT_SERVER_SESSION)) { Session::error("User with access_token = '{$accessToken}' doesn't have enough scopes to make join."); - Yii::$app->statsd->inc('sessionserver.join.fail_not_enough_scopes'); + Yii::$app->statsd->inc('sessionserver.authentication.oauth2_not_enough_scopes'); throw new ForbiddenOperationException('The token does not have required scope.'); } From 0fee23ac86633c7bc2f76696248f8893f769c571 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 22 Nov 2017 22:45:21 +0300 Subject: [PATCH 8/8] =?UTF-8?q?=D0=A1=D0=B1=D0=BE=D1=80=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=BA=20=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=20=D0=B2=D0=BE=D1=80=D0=BA=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/controllers/AccountQueueController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/console/controllers/AccountQueueController.php b/console/controllers/AccountQueueController.php index be77b59..04ee523 100644 --- a/console/controllers/AccountQueueController.php +++ b/console/controllers/AccountQueueController.php @@ -32,11 +32,14 @@ class AccountQueueController extends AmqpController { } public function routeUsernameChanged(UsernameChanged $body): bool { + Yii::$app->statsd->inc('worker.account.usernameChanged.attempt'); $mojangApi = $this->createMojangApi(); try { $response = $mojangApi->usernameToUUID($body->newUsername); + Yii::$app->statsd->inc('worker.account.usernameChanged.found'); } catch (NoContentException $e) { $response = false; + Yii::$app->statsd->inc('worker.account.usernameChanged.not_found'); } catch (RequestException $e) { return true; }