-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhancement: user agent 2.1 #3001
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,11 @@ public function __construct(array $args) | |
if (isset($args['with_resolved'])) { | ||
$args['with_resolved']($config); | ||
} | ||
MetricsBuilder::appendMetricsCaptureMiddleware( | ||
$this->getHandlerList(), | ||
MetricsBuilder::RESOURCE_MODEL | ||
); | ||
$this->addUserAgentMiddleware($config); | ||
} | ||
|
||
public function getHandlerList() | ||
|
@@ -437,6 +442,7 @@ private function addSignatureMiddleware(array $args) | |
$name = $this->config['signing_name']; | ||
$region = $this->config['signing_region']; | ||
$signingRegionSet = $this->signingRegionSet; | ||
$handlerList = $this->getHandlerList(); | ||
|
||
if (isset($args['signature_version']) | ||
|| isset($this->config['configured_signature_version']) | ||
|
@@ -455,7 +461,8 @@ private function addSignatureMiddleware(array $args) | |
$region, | ||
$signatureVersion, | ||
$configuredSignatureVersion, | ||
$signingRegionSet | ||
$signingRegionSet, | ||
$handlerList | ||
) { | ||
if (!$configuredSignatureVersion) { | ||
if (!empty($c['@context']['signing_region'])) { | ||
|
@@ -490,6 +497,11 @@ private function addSignatureMiddleware(array $args) | |
$region = $signingRegionSet | ||
?? $commandSigningRegionSet | ||
?? $region; | ||
|
||
MetricsBuilder::appendMetricsCaptureMiddleware( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: This function is invoked during the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Metrics here will not be collected. I will do a refactor for this type of cases. |
||
$handlerList, | ||
MetricsBuilder::SIGV4A_SIGNING | ||
); | ||
} | ||
|
||
return SignatureProvider::resolve($provider, $signatureVersion, $name, $region); | ||
|
@@ -595,6 +607,14 @@ private function addEndpointV2Middleware() | |
); | ||
} | ||
|
||
private function addUserAgentMiddleware($args) | ||
{ | ||
$this->getHandlerList()->prependSign( | ||
UserAgentMiddleware::wrap($args), | ||
'user-agent' | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves client context param definition from service model, | ||
* creates mapping of client context param names with client-provided | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Aws\Api\Service; | ||
use Aws\Auth\Exception\UnresolvedAuthSchemeException; | ||
use Aws\CommandInterface; | ||
use Aws\MetricsBuilder; | ||
use Closure; | ||
use GuzzleHttp\Promise\Promise; | ||
use function JmesPath\search; | ||
|
@@ -98,8 +99,15 @@ public function __invoke(CommandInterface $command) | |
$operation = $this->api->getOperation($command->getName()); | ||
$commandArgs = $command->toArray(); | ||
$providerArgs = $this->resolveArgs($commandArgs, $operation); | ||
$this->hookAccountIdMetric( | ||
$providerArgs[self::ACCOUNT_ID_PARAM] ?? null, | ||
$command | ||
); | ||
$endpoint = $this->endpointProvider->resolveEndpoint($providerArgs); | ||
|
||
$this->hookAccountIdEndpointMetric( | ||
$endpoint, | ||
$command | ||
); | ||
if (!empty($authSchemes = $endpoint->getProperty('authSchemes'))) { | ||
$this->applyAuthScheme( | ||
$authSchemes, | ||
|
@@ -394,4 +402,23 @@ private function resolveAccountId(): ?string | |
|
||
return $identity->getAccountId(); | ||
} | ||
|
||
private function hookAccountIdMetric($accountId, &$command) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: can we make a generic method on the MetricsBuilder class that will handle this and other things like it i.e. accountidendpointmetric? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can take a look and see if it fits better there. |
||
{ | ||
if (!empty($accountId)) { | ||
MetricsBuilder::fromCommand($command)->append( | ||
MetricsBuilder::RESOLVED_ACCOUNT_ID | ||
); | ||
} | ||
} | ||
|
||
private function hookAccountIdEndpointMetric($endpoint, $command) | ||
{ | ||
$regex = "/^(https?:\/\/\d{12}\.[^\s\/$.?#].\S*)$/"; | ||
if (preg_match($regex, $endpoint->getUrl())) { | ||
MetricsBuilder::fromCommand($command)->append( | ||
MetricsBuilder::ACCOUNT_ID_ENDPOINT | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: do we need to add this (or other static/guaranteed metrics) to our middleware stack?