mirror of
https://github.com/containous/traefik.git
synced 2025-02-01 05:47:13 +03:00
Cache exising task definitions to avoid rate limiting
This commit is contained in:
parent
85ab0e6e70
commit
0d6f259adc
@ -19,9 +19,11 @@ import (
|
|||||||
"github.com/containous/traefik/old/provider"
|
"github.com/containous/traefik/old/provider"
|
||||||
"github.com/containous/traefik/old/types"
|
"github.com/containous/traefik/old/types"
|
||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
|
"github.com/patrickmn/go-cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ provider.Provider = (*Provider)(nil)
|
var _ provider.Provider = (*Provider)(nil)
|
||||||
|
var existingTaskDefCache = cache.New(30*time.Minute, 5*time.Minute)
|
||||||
|
|
||||||
// Provider holds configurations of the provider.
|
// Provider holds configurations of the provider.
|
||||||
type Provider struct {
|
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) {
|
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)
|
taskDef := make(map[string]*ecs.TaskDefinition)
|
||||||
for arn, task := range taskDefArns {
|
for arn, task := range taskDefArns {
|
||||||
resp, err := client.ecs.DescribeTaskDefinitionWithContext(ctx, &ecs.DescribeTaskDefinitionInput{
|
if definition, ok := existingTaskDefCache.Get(arn); ok {
|
||||||
TaskDefinition: task.TaskDefinitionArn,
|
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 {
|
if err != nil {
|
||||||
log.Errorf("Unable to describe task definition: %s", err)
|
log.Errorf("Unable to describe task definition: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
taskDef[arn] = resp.TaskDefinition
|
||||||
|
existingTaskDefCache.Set(arn, resp.TaskDefinition, cache.DefaultExpiration)
|
||||||
}
|
}
|
||||||
|
|
||||||
taskDef[arn] = resp.TaskDefinition
|
|
||||||
}
|
}
|
||||||
return taskDef, nil
|
return taskDef, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user