-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change provides: - A builder class for appending metrics - Default initialization of a metrics builder within command instantiation - Wraps user agent logic into a single middleware class - Adds middlewares into the different features from where metrics can be gather, to acomplish this purpose.
- Loading branch information
1 parent
8cd4349
commit c1ae03a
Showing
19 changed files
with
950 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Aws; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MetricsBuilder | ||
{ | ||
/** @var string */ | ||
const COMMAND_METRICS_BUILDER = "CommandMetricsBuilder"; | ||
const RESOURCE_MODEL = "A"; | ||
const WAITER = "B"; | ||
const PAGINATOR = "C"; | ||
const RETRY_MODE_LEGACY = "D"; | ||
const RETRY_MODE_STANDARD = "E"; | ||
const RETRY_MODE_ADAPTIVE = "F"; | ||
const S3_TRANSFER = "G"; | ||
const S3_CRYPTO_V1N = "H"; | ||
const S3_CRYPTO_V2 = "I"; | ||
const ENDPOINT_OVERRIDE = "N"; | ||
const ACCOUNT_ID_ENDPOINT = "O"; | ||
const ACCOUNT_ID_MODE_PREFERRED = "P"; | ||
const ACCOUNT_ID_MODE_DISABLED = "Q"; | ||
const ACCOUNT_ID_MODE_REQUIRED = "R"; | ||
const SIGV4A_SIGNING = "S"; | ||
const RESOLVED_ACCOUNT_ID = "T"; | ||
const FLEXIBLE_CHECKSUMS_REQ_CRC32 = "U"; | ||
const FLEXIBLE_CHECKSUMS_REQ_CRC32C = "V"; | ||
const FLEXIBLE_CHECKSUMS_REQ_CRC64 = "W"; | ||
const FLEXIBLE_CHECKSUMS_REQ_SHA1 = "X"; | ||
const FLEXIBLE_CHECKSUMS_REQ_SHA256 = "Y"; | ||
|
||
|
||
/** @var int */ | ||
private static $MAX_METRICS_SIZE = 1024; // 1KB or 1024 B | ||
|
||
/** @var array $metrics */ | ||
private $metrics; | ||
/** @var int $metricsSize */ | ||
private $metricsSize; | ||
|
||
public function __construct() | ||
{ | ||
$this->metrics = []; | ||
} | ||
|
||
public function build(): string | ||
{ | ||
if (empty($this->metrics)) { | ||
return ""; | ||
} | ||
|
||
return $this->encode(); | ||
} | ||
|
||
public function append(string $metric): void | ||
{ | ||
if (!$this->canMetricBeAppended($metric)) { | ||
return; | ||
} | ||
|
||
$this->metrics[$metric] = true; | ||
$this->metricsSize += strlen($metric); | ||
} | ||
|
||
private function encode(): string | ||
{ | ||
return implode(',', array_keys($this->metrics)); | ||
} | ||
|
||
private function canMetricBeAppended(string $newMetric): bool | ||
{ | ||
if ((strlen($newMetric) + $this->metricsSize) > | ||
self::$MAX_METRICS_SIZE) { | ||
trigger_error( | ||
'The metric ' . $newMetric | ||
. ' can not be added due to size constraints', | ||
E_USER_WARNING | ||
); | ||
|
||
return false; | ||
} | ||
|
||
if (isset($this->metrics[$newMetric])) { | ||
trigger_error( | ||
'The metric ' . $newMetric. ' is already appended!', | ||
E_USER_WARNING | ||
); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static function fromCommand(CommandInterface $command): MetricsBuilder | ||
{ | ||
return $command['@context'][MetricsBuilder::COMMAND_METRICS_BUILDER]; | ||
} | ||
|
||
public static function appendMetricsCaptureMiddleware( | ||
HandlerList $handlerList, | ||
$metric | ||
): void | ||
{ | ||
$handlerList->appendBuild( | ||
Middleware::tap( | ||
function (CommandInterface $command) use ($metric) { | ||
self::fromCommand($command)->append( | ||
$metric | ||
); | ||
} | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.