The AWS providers addr method accepts a logger in its call. However, the ECS code introduced to find ECS instances does not utilise the passed in logger but instead just makes a call to the build in log package. This causes formatting issues in the output
Example
package main
import (
"github.com/hashicorp/go-discover"
"go.uber.org/zap"
)
func main() {
d := discover.Discover{
Providers: map[string]discover.Provider{
"aws": discover.Providers["aws"],
},
}
logger, _ := zap.NewProduction()
defer logger.Sync()
l := zap.NewStdLog(logger)
cfg := "provider=aws region=eu-west-1 tag_key=foo tag_value=bar service=ecs"
d.Addrs(cfg, l)
}
$ go run main.go
{"level":"info","ts":1746121177.872697,"caller":"go-discover@v1.0.0/discover.go:178","msg":"[DEBUG] discover: Using provider \"aws\""}
{"level":"info","ts":1746121177.872697,"caller":"aws/aws_discover.go:89","msg":"[INFO] discover-aws: Address Type is not supported for ECS. Valid values are {private_v4}. Falling back to 'private_v4'"}
{"level":"info","ts":1746121177.872697,"caller":"aws/aws_discover.go:103","msg":"[DEBUG] discover-aws: Using region=eu-west-1 tag_key=foo tag_value=bar addr_type=private_v4"}
{"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:105","msg":"[DEBUG] discover-aws: No static credentials"}
{"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:106","msg":"[DEBUG] discover-aws: Using environment variables, shared credentials or instance role"}
{"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:135","msg":"[INFO] discover-aws: Region is eu-west-1"}
{"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:137","msg":"[DEBUG] discover-aws: Creating session..."}
{"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:149","msg":"[INFO] discover-aws: Using default credential chain"}
2025/05/01 18:39:37 [INFO] discover-aws: Filter ECS tasks with foo=bar
2025/05/01 18:39:38 [DEBUG] discover-aws: Retrieved 0 ClusterArns
2025/05/01 18:39:38 [DEBUG] discover-aws: Discovered ECS Task IPs: []
This call to log should be using l not log so it will use the passed in logger
log.Printf("[INFO] discover-aws: Filter ECS tasks with %s=%s", tagKey, tagValue)
var clusterArns []string
The AWS providers
addrmethod accepts a logger in its call. However, the ECS code introduced to find ECS instances does not utilise the passed in logger but instead just makes a call to the build inlogpackage. This causes formatting issues in the outputExample
$ go run main.go {"level":"info","ts":1746121177.872697,"caller":"go-discover@v1.0.0/discover.go:178","msg":"[DEBUG] discover: Using provider \"aws\""} {"level":"info","ts":1746121177.872697,"caller":"aws/aws_discover.go:89","msg":"[INFO] discover-aws: Address Type is not supported for ECS. Valid values are {private_v4}. Falling back to 'private_v4'"} {"level":"info","ts":1746121177.872697,"caller":"aws/aws_discover.go:103","msg":"[DEBUG] discover-aws: Using region=eu-west-1 tag_key=foo tag_value=bar addr_type=private_v4"} {"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:105","msg":"[DEBUG] discover-aws: No static credentials"} {"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:106","msg":"[DEBUG] discover-aws: Using environment variables, shared credentials or instance role"} {"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:135","msg":"[INFO] discover-aws: Region is eu-west-1"} {"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:137","msg":"[DEBUG] discover-aws: Creating session..."} {"level":"info","ts":1746121177.8732376,"caller":"aws/aws_discover.go:149","msg":"[INFO] discover-aws: Using default credential chain"} 2025/05/01 18:39:37 [INFO] discover-aws: Filter ECS tasks with foo=bar 2025/05/01 18:39:38 [DEBUG] discover-aws: Retrieved 0 ClusterArns 2025/05/01 18:39:38 [DEBUG] discover-aws: Discovered ECS Task IPs: []This call to log should be using
lnotlogso it will use the passed in logger