New logger for the Traefik logs
This commit is contained in:
parent
27c02b5a56
commit
56f7515ecd
297 changed files with 2337 additions and 1934 deletions
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/config/label"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/constraints"
|
||||
)
|
||||
|
@ -22,17 +22,16 @@ func (p *Provider) buildConfiguration(ctx context.Context, instances []ecsInstan
|
|||
|
||||
for _, instance := range instances {
|
||||
instanceName := getServiceName(instance) + "-" + instance.ID
|
||||
ctxContainer := log.With(ctx, log.Str("ecs-instance", instanceName))
|
||||
logger := log.Ctx(ctx).With().Str("ecs-instance", instanceName).Logger()
|
||||
ctxContainer := logger.WithContext(ctx)
|
||||
|
||||
if !p.filterInstance(ctxContainer, instance) {
|
||||
continue
|
||||
}
|
||||
|
||||
logger := log.FromContext(ctxContainer)
|
||||
|
||||
confFromLabel, err := label.DecodeConfiguration(instance.Labels)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,7 @@ func (p *Provider) buildConfiguration(ctx context.Context, instances []ecsInstan
|
|||
|
||||
err := p.buildTCPServiceConfiguration(instance, confFromLabel.TCP)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
provider.BuildTCPRouterConfiguration(ctxContainer, confFromLabel.TCP)
|
||||
|
@ -53,7 +52,7 @@ func (p *Provider) buildConfiguration(ctx context.Context, instances []ecsInstan
|
|||
|
||||
err := p.buildUDPServiceConfiguration(instance, confFromLabel.UDP)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
provider.BuildUDPRouterConfiguration(ctxContainer, confFromLabel.UDP)
|
||||
|
@ -68,7 +67,7 @@ func (p *Provider) buildConfiguration(ctx context.Context, instances []ecsInstan
|
|||
|
||||
err = p.buildServiceConfiguration(ctxContainer, instance, confFromLabel.HTTP)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -156,40 +155,40 @@ func (p *Provider) buildServiceConfiguration(_ context.Context, instance ecsInst
|
|||
}
|
||||
|
||||
func (p *Provider) filterInstance(ctx context.Context, instance ecsInstance) bool {
|
||||
logger := log.FromContext(ctx)
|
||||
logger := log.Ctx(ctx)
|
||||
|
||||
if instance.machine == nil {
|
||||
logger.Debug("Filtering ecs instance with nil machine")
|
||||
logger.Debug().Msg("Filtering ecs instance with nil machine")
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.ToLower(instance.machine.state) != ec2.InstanceStateNameRunning {
|
||||
logger.Debugf("Filtering ecs instance with an incorrect state %s (%s) (state = %s)", instance.Name, instance.ID, instance.machine.state)
|
||||
logger.Debug().Msgf("Filtering ecs instance with an incorrect state %s (%s) (state = %s)", instance.Name, instance.ID, instance.machine.state)
|
||||
return false
|
||||
}
|
||||
|
||||
if instance.machine.healthStatus == "UNHEALTHY" {
|
||||
logger.Debugf("Filtering unhealthy ecs instance %s (%s)", instance.Name, instance.ID)
|
||||
logger.Debug().Msgf("Filtering unhealthy ecs instance %s (%s)", instance.Name, instance.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(instance.machine.privateIP) == 0 {
|
||||
logger.Debugf("Filtering ecs instance without an ip address %s (%s)", instance.Name, instance.ID)
|
||||
logger.Debug().Msgf("Filtering ecs instance without an ip address %s (%s)", instance.Name, instance.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
if !instance.ExtraConf.Enable {
|
||||
logger.Debugf("Filtering disabled ecs instance %s (%s)", instance.Name, instance.ID)
|
||||
logger.Debug().Msgf("Filtering disabled ecs instance %s (%s)", instance.Name, instance.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
matches, err := constraints.MatchLabels(instance.Labels, p.Constraints)
|
||||
if err != nil {
|
||||
logger.Errorf("Error matching constraint expression: %v", err)
|
||||
logger.Error().Err(err).Msg("Error matching constraint expression")
|
||||
return false
|
||||
}
|
||||
if !matches {
|
||||
logger.Debugf("Container pruned by constraint expression: %q", p.Constraints)
|
||||
logger.Debug().Msgf("Container pruned by constraint expression: %q", p.Constraints)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue