Skip to content

Commit

Permalink
AWS: Log all calls at V(4), using a handler
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb authored and RichieEscarez committed Dec 4, 2015
1 parent 4357e2d commit 5dcf336
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/cloudprovider/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -220,6 +232,9 @@ func (p *awsSDKProvider) LoadBalancing(regionName string) (ELB, error) {
Region: &regionName,
Credentials: p.creds,
})

addHandlers(&elbClient.Handlers)

return elbClient, nil
}

Expand All @@ -228,6 +243,9 @@ func (p *awsSDKProvider) Autoscaling(regionName string) (ASG, error) {
Region: &regionName,
Credentials: p.creds,
})

addHandlers(&client.Handlers)

return client, nil
}

Expand Down
34 changes: 34 additions & 0 deletions pkg/cloudprovider/providers/aws/log_handler.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5dcf336

Please sign in to comment.