AWS: Log all calls at V(4), using a handler

Fixes #12122
This commit is contained in:
Justin Santa Barbara 2015-10-19 18:54:59 -04:00
parent cadb6c06be
commit c465e91681
2 changed files with 56 additions and 4 deletions

View File

@ -34,6 +34,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elb"
@ -205,12 +206,23 @@ type awsSDKProvider struct {
creds *credentials.Credentials
}
func addHandlers(h *request.Handlers) {
h.Sign.PushFrontNamed(request.NamedHandler{
Name: "k8s/logger",
Fn: awsHandlerLogger,
})
}
func (p *awsSDKProvider) Compute(regionName string) (EC2, error) {
service := ec2.New(&aws.Config{
Region: &regionName,
Credentials: p.creds,
})
addHandlers(&service.Handlers)
ec2 := &awsSdkEC2{
ec2: ec2.New(&aws.Config{
Region: &regionName,
Credentials: p.creds,
}),
ec2: service,
}
return ec2, nil
}
@ -220,6 +232,9 @@ func (p *awsSDKProvider) LoadBalancing(regionName string) (ELB, error) {
Region: &regionName,
Credentials: p.creds,
})
addHandlers(&elbClient.Handlers)
return elbClient, nil
}
@ -228,6 +243,9 @@ func (p *awsSDKProvider) Autoscaling(regionName string) (ASG, error) {
Region: &regionName,
Credentials: p.creds,
})
addHandlers(&client.Handlers)
return client, nil
}

View File

@ -0,0 +1,34 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package aws
import (
"github.com/aws/aws-sdk-go/aws/request"
"github.com/golang/glog"
)
// Handler for aws-sdk-go that logs all requests
func awsHandlerLogger(req *request.Request) {
service := req.Service.ServiceName
name := "?"
if req.Operation != nil {
name = req.Operation.Name
}
glog.V(4).Infof("AWS request: %s %s", service, name)
}