lib/fog/aws/elasticache.rb in fog-1.23.0 vs lib/fog/aws/elasticache.rb in fog-1.24.0
- old
+ new
@@ -8,11 +8,11 @@
class IdentifierTaken < Fog::Errors::Error; end
class InvalidInstance < Fog::Errors::Error; end
class AuthorizationAlreadyExists < Fog::Errors::Error; end
requires :aws_access_key_id, :aws_secret_access_key
- recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at
+ recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
request_path 'fog/aws/requests/elasticache'
request :create_cache_cluster
request :delete_cache_cluster
@@ -55,10 +55,12 @@
include Fog::AWS::CredentialFetcher::ConnectionMethods
def initialize(options={})
@use_iam_profile = options[:use_iam_profile]
setup_credentials(options)
+ @instrumentor = options[:instrumentor]
+ @instrumentor_name = options[:instrumentor_name] || 'fog.aws.elasticache'
options[:region] ||= 'us-east-1'
@host = options[:host] || "elasticache.#{options[:region]}.amazonaws.com"
@path = options[:path] || '/'
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@@ -99,32 +101,40 @@
:port => @port,
:version => '2013-06-15'
}
)
- begin
- @connection.request({
- :body => body,
- :expects => 200,
- :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
- :idempotent => idempotent,
- :method => 'POST',
- :parser => parser
- })
- rescue Excon::Errors::HTTPStatusError => error
- match = Fog::AWS::Errors.match_error(error)
- raise if match.empty?
- raise case match[:code]
- when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', 'CacheClusterNotFound'
- Fog::AWS::Elasticache::NotFound.slurp(error, match[:message])
- when 'CacheSecurityGroupAlreadyExists'
- Fog::AWS::Elasticache::IdentifierTaken.slurp(error, match[:message])
- when 'InvalidParameterValue'
- Fog::AWS::Elasticache::InvalidInstance.slurp(error, match[:message])
- else
- Fog::AWS::Elasticache::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
- end
+ if @instrumentor
+ @instrumentor.instrument("#{@instrumentor_name}.request", params) do
+ _request(body, idempotent, parser)
+ end
+ else
+ _request(body, idempotent, parser)
end
+ end
+
+ def _request(body, idempotent, parser)
+ @connection.request({
+ :body => body,
+ :expects => 200,
+ :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
+ :idempotent => idempotent,
+ :method => 'POST',
+ :parser => parser
+ })
+ rescue Excon::Errors::HTTPStatusError => error
+ match = Fog::AWS::Errors.match_error(error)
+ raise if match.empty?
+ raise case match[:code]
+ when 'CacheSecurityGroupNotFound', 'CacheParameterGroupNotFound', 'CacheClusterNotFound'
+ Fog::AWS::Elasticache::NotFound.slurp(error, match[:message])
+ when 'CacheSecurityGroupAlreadyExists'
+ Fog::AWS::Elasticache::IdentifierTaken.slurp(error, match[:message])
+ when 'InvalidParameterValue'
+ Fog::AWS::Elasticache::InvalidInstance.slurp(error, match[:message])
+ else
+ Fog::AWS::Elasticache::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
+ end
end
end
class Mock
include Fog::AWS::CredentialFetcher::ConnectionMethods