From c465e91681b6ce309001757d65ad7fd8e8ef735b Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 19 Oct 2015 18:54:59 -0400 Subject: [PATCH] AWS: Log all calls at V(4), using a handler Fixes #12122 --- pkg/cloudprovider/providers/aws/aws.go | 26 +++++++++++--- .../providers/aws/log_handler.go | 34 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 pkg/cloudprovider/providers/aws/log_handler.go diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index f646c8557e6..eafea2bfab5 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -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: ®ionName, + Credentials: p.creds, + }) + + addHandlers(&service.Handlers) + ec2 := &awsSdkEC2{ - ec2: ec2.New(&aws.Config{ - Region: ®ionName, - Credentials: p.creds, - }), + ec2: service, } return ec2, nil } @@ -220,6 +232,9 @@ func (p *awsSDKProvider) LoadBalancing(regionName string) (ELB, error) { Region: ®ionName, Credentials: p.creds, }) + + addHandlers(&elbClient.Handlers) + return elbClient, nil } @@ -228,6 +243,9 @@ func (p *awsSDKProvider) Autoscaling(regionName string) (ASG, error) { Region: ®ionName, Credentials: p.creds, }) + + addHandlers(&client.Handlers) + return client, nil } diff --git a/pkg/cloudprovider/providers/aws/log_handler.go b/pkg/cloudprovider/providers/aws/log_handler.go new file mode 100644 index 00000000000..656d212ce77 --- /dev/null +++ b/pkg/cloudprovider/providers/aws/log_handler.go @@ -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) +}