Skip to content

Commit

Permalink
PLAT-3476_remove_statsd_from_talis_php (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aardeedev authored Apr 9, 2020
1 parent 75ea5c6 commit cc87360
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 60 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"require": {
"php": ">=5.3.0",
"monolog/monolog": ">=1.13.1",
"domnikl/statsd": ">=1.0.2 <2.0.0",
"psr/log": ">=1.0.0",
"firebase/php-jwt": "^3.0",
"doctrine/common": "^2.5",
Expand Down
39 changes: 0 additions & 39 deletions src/Talis/Persona/Client/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

use Monolog\Logger;
use Guzzle\Http\Exception\RequestException;
use \Domnikl\Statsd\Connection\Socket;
use \Domnikl\Statsd\Connection\Blackhole;
use \Guzzle\Http\Client as GuzzleClient;
use \Talis\Persona\Client\ClientVersionCache;

abstract class Base
{
use ClientVersionCache;

const STATSD_CONN = 'STATSD_CONN';
const STATSD_PREFIX = 'STATSD_PREFIX';
const LOGGER_NAME = 'PERSONA';
const PERSONA_API_VERSION = '3';

Expand All @@ -24,12 +20,6 @@ abstract class Base
*/
protected $config = null;

/**
* StatsD client
* @var \Domnikl\Statsd\Client
*/
private $statsD;

/**
* @var \Psr\Log\LoggerInterface
*/
Expand Down Expand Up @@ -97,35 +87,6 @@ public function __construct(array $config)
$this->phpVersion = phpversion();
}

/**
* Lazy-load statsD
* @return \Domnikl\Statsd\Client
*/
public function getStatsD()
{
if (is_null($this->statsD)) {
$connStr = getenv(self::STATSD_CONN);

if (!empty($connStr) && !empty(strpos($connStr, ':'))) {
list($host, $port) = explode(':', $connStr);
$conn = new Socket($host, $port);
} else {
$conn = new Blackhole();
}

$this->statsD = new \Domnikl\Statsd\Client($conn);
$prefix = getenv(self::STATSD_PREFIX);

if (empty($prefix)) {
$prefix = 'persona.php.client';
}

$this->statsD->setNamespace($prefix);
}

return $this->statsD;
}

/**
* Checks the supplied config, verifies that all required parameters are present and
* contain a non null value;
Expand Down
6 changes: 0 additions & 6 deletions src/Talis/Persona/Client/Signing.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ protected function checkConfig(array $config)
*/
public function presignUrl($url, $secret, $expiry = null)
{
$this->getStatsD()->increment('presignUrl');

if (empty($url) || empty($secret)) {
throw new \InvalidArgumentException('invalid url or secret');
}
Expand All @@ -44,9 +42,7 @@ public function presignUrl($url, $secret, $expiry = null)
$url .= $expParam;
}

$this->getStatsD()->startTiming('presignUrl.sign');
$sig = $this->getSignature($url, $secret);
$this->getStatsD()->endTiming('presignUrl.sign');

$sigParam = strpos($url, '?') === false ? "?signature=$sig" : "&signature=$sig";

Expand Down Expand Up @@ -83,11 +79,9 @@ public function isPresignedUrlValid($url, $secret)
$signature = $this->getSignature($urlWithoutSignature, $secret);

if ($query['signature'] === $signature) {
$this->getStatsD()->increment('presignUrl.valid');
return true;
}

$this->getStatsD()->increment('presignUrl.invalid');
return false;
}

Expand Down
14 changes: 0 additions & 14 deletions src/Talis/Persona/Client/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,7 @@ protected function retrievePublicKeyFromPersona()
protected function validateTokenUsingPersona($token, array $scopes = [])
{
// verify against persona
$this->getStatsD()->increment('validateToken.cache.miss');

$this->getStatsD()->startTiming('validateToken.rest.get');
$success = $this->personaCheckTokenIsValid($token, $scopes);
$this->getStatsD()->endTiming('validateToken.rest.get');

if ($success === ValidationResults::SUCCESS) {
$this->getStatsD()->increment('validateToken.rest.valid');
} else {
$this->getStatsD()->increment('validateToken.rest.invalid');
}

return $success;
}
Expand All @@ -233,8 +223,6 @@ protected function validateTokenUsingPersona($token, array $scopes = [])
*/
public function obtainNewToken($clientId, $clientSecret, array $params = [])
{
$this->getStatsD()->increment('obtainNewToken');

if (empty($clientId) || empty($clientSecret)) {
throw new \Exception('You must specify clientId, and clientSecret to obtain a new token');
}
Expand All @@ -257,9 +245,7 @@ public function obtainNewToken($clientId, $clientSecret, array $params = [])
}

$url = $this->getPersonaHost() . $this->config['persona_oauth_route'];
$this->getStatsD()->startTiming('obtainNewToken.rest.get');
$token = $this->personaObtainNewToken($url, $query);
$this->getStatsD()->endTiming('obtainNewToken.rest.get');

$this->cacheToken($clientId, $token);
return $token;
Expand Down

0 comments on commit cc87360

Please sign in to comment.