diff --git a/old/provider/ecs/ecs.go b/old/provider/ecs/ecs.go index a9afc9ab6..32dccc3dd 100644 --- a/old/provider/ecs/ecs.go +++ b/old/provider/ecs/ecs.go @@ -19,9 +19,11 @@ import ( "github.com/containous/traefik/old/provider" "github.com/containous/traefik/old/types" "github.com/containous/traefik/safe" + "github.com/patrickmn/go-cache" ) var _ provider.Provider = (*Provider)(nil) +var existingTaskDefCache = cache.New(30*time.Minute, 5*time.Minute) // Provider holds configurations of the provider. type Provider struct { @@ -394,16 +396,22 @@ func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, cl func (p *Provider) lookupTaskDefinitions(ctx context.Context, client *awsClient, taskDefArns map[string]*ecs.Task) (map[string]*ecs.TaskDefinition, error) { taskDef := make(map[string]*ecs.TaskDefinition) for arn, task := range taskDefArns { - resp, err := client.ecs.DescribeTaskDefinitionWithContext(ctx, &ecs.DescribeTaskDefinitionInput{ - TaskDefinition: task.TaskDefinitionArn, - }) + if definition, ok := existingTaskDefCache.Get(arn); ok { + taskDef[arn] = definition.(*ecs.TaskDefinition) + log.Debugf("Found cached task definition for %s. Skipping the call", arn) + } else { + resp, err := client.ecs.DescribeTaskDefinitionWithContext(ctx, &ecs.DescribeTaskDefinitionInput{ + TaskDefinition: task.TaskDefinitionArn, + }) - if err != nil { - log.Errorf("Unable to describe task definition: %s", err) - return nil, err + if err != nil { + log.Errorf("Unable to describe task definition: %s", err) + return nil, err + } + + taskDef[arn] = resp.TaskDefinition + existingTaskDefCache.Set(arn, resp.TaskDefinition, cache.DefaultExpiration) } - - taskDef[arn] = resp.TaskDefinition } return taskDef, nil }