Open lvijnck opened 11 months ago
sample.go
package requestlogger import ( "fmt" awsConfig "github.com/aws/aws-sdk-go-v2/config" "bytes" "context" "io" "log" "net/http" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/aws/aws-sdk-go-v2/service/sqs/types" ) // Config the plugin configuration. type Config struct { QueueURL string `json:"redisAddr,omitempty"` AWSEndpoint string `json:"awsEndpoint,omitempty"` AWSRegion string `json:"awsRegion,omitempty"` } // CreateConfig creates the default plugin configuration. func CreateConfig() *Config { return &Config{ QueueURL: "http://0.0.0.0:4566/000000000000/test", AWSEndpoint: "http://0.0.0.0:4566", AWSRegion: "eu-central-1", } } // RequestLogger middleware that logs incoming requests. type RequestLogger struct { next http.Handler name string queueURL string sqsClient sqs.Client } // New created a new Demo plugin. func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { // Instantiate client customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { return aws.Endpoint{ PartitionID: "aws", URL: config.AWSEndpoint, SigningRegion: config.AWSRegion, }, nil }) cfg, err := awsConfig.LoadDefaultConfig(context.TODO(), awsConfig.WithEndpointResolverWithOptions(customResolver)) if err != nil { log.Printf("Error creating config %s", err) } return &RequestLogger{ next: next, name: name, queueURL: config.QueueURL, sqsClient: *sqs.NewFromConfig(cfg), }, nil } // ServeHTTP handles the incoming request and logs it. func (r *RequestLogger) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Log the incoming request details log.Printf("Request: %s %s %s", req.Method, req.URL.Path, req.RemoteAddr) // Send message input := &sqs.SendMessageInput{ DelaySeconds: 0, MessageAttributes: map[string]types.MessageAttributeValue{ "instanceId": { DataType: aws.String("String"), StringValue: aws.String("test"), }, }, MessageBody: aws.String("Information about the NY Times fiction bestseller for the week of 12/11/2016."), QueueUrl: &r.queueURL, } _, err := r.sqsClient.SendMessage(context.Background(), input) if err != nil { fmt.Print("Got an error sending the message:") fmt.Println(err) return } // Read request body and log it if req.Body != nil { body, err := io.ReadAll(req.Body) if err == nil { req.Body = io.NopCloser(bytes.NewReader(body)) log.Printf("Request Body: %s", body) } else { log.Printf("Request does not contain a body") } } // Call the next middleware/handler in the chain r.next.ServeHTTP(w, req) }
message pushed to queue
Plugin was vendored before launching Traefik
traefik_1 | time="2023-08-08T12:19:55Z" level=info msg="Configuration loaded from file: /traefik.yml" traefik_1 | panic: reflect: embedded type with methods not implemented if there is more than one field [recovered] traefik_1 | panic: plugins-local/src/ai-gateway/requestlogger/vendor/github.com/aws/smithy-go/transport/http/checksum_middleware.go:34:2: CFG post-order panic: reflect: embedded type with methods not implemented if there is more than one field traefik_1 | traefik_1 | goroutine 1 [running]: traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1() traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/cfg.go:601 +0x78 traefik_1 | panic({0x3fbf620, 0x59ebd60}) traefik_1 | runtime/panic.go:890 +0x263 traefik_1 | reflect.StructOf({0xc0001bfba0, 0x4, 0xc000129520?}) traefik_1 | reflect/type.go:2551 +0x2709 traefik_1 | github.com/traefik/yaegi/interp.(*itype).refType(0xc001d15900?, 0x0?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/type.go:2151 +0xd2a traefik_1 | github.com/traefik/yaegi/interp.(*itype).TypeOf(...) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/type.go:2196 traefik_1 | github.com/traefik/yaegi/interp.(*itype).frameType(0x10?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/type.go:2223 +0x18a traefik_1 | github.com/traefik/yaegi/interp.(*itype).frameType(0x416837?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/type.go:2221 +0x136 traefik_1 | github.com/traefik/yaegi/interp.(*scope).add(0xc001328cf0, 0xc001a19f90?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/scope.go:210 +0x7b traefik_1 | github.com/traefik/yaegi/interp.compDefineX(0xc001328cf0, 0xc001385e00) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/cfg.go:2328 +0x6a8 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc001385e00) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/cfg.go:840 +0x1993 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc001385e00, 0xc001a1aaa8, 0xc001a1aaf0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:294 +0xad traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc001385cc0, 0xc001a1aaa8, 0xc001a1aaf0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc001376b40, 0xc001a1aaa8, 0xc001a1aaf0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc0012d5a40, 0xc001a1aaa8, 0xc001a1aaf0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc0018cefc0, 0xc0012d5a40, 0xc001328cf0, {0xc00016a991, 0x27}, {0xc00184e768, 0x4}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/cfg.go:62 +0x2b4 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0018cefc0, {0xc000545450, 0x44}, {0xc00016a991, 0x27}, 0x1) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/src.go:125 +0xda9 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000d9f040) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x208d traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000d9f040, 0xc001a1b890, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x34 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000d9e780, 0xc001a1b890, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000d9e500, 0xc001a1b890, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0018cefc0, 0xc000d9e500, {0xc000545450, 0x44}, {0xc00016a6f1, 0x24}, {0xc000797d28, 0x6}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0x22b traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0018cefc0, {0xc0018c5940, 0x40}, {0xc00016a6f1, 0x24}, 0x1) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0x9a5 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000cf9040) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x208d traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000cf9040, 0xc001a1c648, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x34 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000cf8c80, 0xc001a1c648, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000cf8a00, 0xc001a1c648, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0018cefc0, 0xc000cf8a00, {0xc0018c5940, 0x40}, {0xc00016a391, 0x20}, {0xc0007979c0, 0x3}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0x22b traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0018cefc0, {0xc001609180, 0x43}, {0xc00016a391, 0x20}, 0x1) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0x9a5 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc000b91b80) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x208d traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000b91b80, 0xc001a1d400, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x34 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000b917c0, 0xc001a1d400, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc000b91540, 0xc001a1d400, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0018cefc0, 0xc000b91540, {0xc001609180, 0x43}, {0xc001931ec1, 0x23}, {0xc000797378, 0x6}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0x22b traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0018cefc0, {0xc00180e798, 0x18}, {0xc001931ec1, 0x23}, 0x1) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0x9a5 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc001938a00) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x208d traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc001938a00, 0xc001a1e1b8, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x34 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc001938640, 0xc001a1e1b8, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc00192de00, 0xc001a1e1b8, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0018cefc0, 0xc00192de00, {0xc00180e798, 0x18}, {0xc0002ef4c1, 0x18}, {0xc000796e30, 0xd}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0x22b traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc0018cefc0, {0xc000796d90, 0x4}, {0xc0002ef4c1, 0x18}, 0x1) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0x9a5 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0xc00192cb40) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x208d traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc00192cb40, 0xc001a1ef70, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x34 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc00192ca00, 0xc001a1ef70, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*node).Walk(0xc00192c640, 0xc001a1ef70, 0x0) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0x75 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gta(0xc0018cefc0, 0xc00192c640, {0xc000796d90, 0x4}, {0xc000796d90, 0x4}, {0xc000796d90, 0x4}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0x22b traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0xc0018cefc0?, {0xc001a1f150?, 0xc000126ea0?, 0xc001a1f098?}, {0xc000796d90, 0x4}, {0xc000796d90, 0x4}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/gta.go:395 +0x15d traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc0018cefc0, {0x5a20fa0?, 0xc000126ea0?}) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/program.go:92 +0x17f traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc0018cefc0, {0xc001931c80?, 0x1?}, {0x0?, 0xc001931c80?}, 0xe0?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/program.go:64 +0xb8 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0018cefc0, {0xc001931c80?, 0xc001a1f3c0?}, {0x0?, 0x1?}, 0x0?) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:556 +0x28 traefik_1 | github.com/traefik/yaegi/interp.(*Interpreter).Eval(...) traefik_1 | github.com/traefik/yaegi@v0.15.1/interp/interp.go:498 traefik_1 | github.com/traefik/traefik/v2/pkg/plugins.NewBuilder(0xc000522e40, 0x0?, 0xc000b44548?) traefik_1 | github.com/traefik/traefik/v2/pkg/plugins/builder.go:104 +0xdc6 traefik_1 | main.createPluginBuilder(0xc0011f7800?) traefik_1 | github.com/traefik/traefik/v2/cmd/traefik/plugins.go:18 +0x35 traefik_1 | main.setupServer(0xc0011f7800) traefik_1 | github.com/traefik/traefik/v2/cmd/traefik/traefik.go:214 +0x537 traefik_1 | main.runCmd(0xc0011f7800) traefik_1 | github.com/traefik/traefik/v2/cmd/traefik/traefik.go:117 +0x3e5 traefik_1 | main.main.func1({0xc000eb5f60?, 0xc0000721a0?, 0x11?}) traefik_1 | github.com/traefik/traefik/v2/cmd/traefik/traefik.go:62 +0x1f traefik_1 | github.com/traefik/paerser/cli.run(0xc0011f7880, {0xc0000721a0?, 0x1, 0x1}) traefik_1 | github.com/traefik/paerser@v0.2.0/cli/commands.go:133 +0x269 traefik_1 | github.com/traefik/paerser/cli.execute(0xc0011f7880, {0xc000072180?, 0x3, 0x3}, 0x0?) traefik_1 | github.com/traefik/paerser@v0.2.0/cli/commands.go:76 +0x74a traefik_1 | github.com/traefik/paerser/cli.Execute(...) traefik_1 | github.com/traefik/paerser@v0.2.0/cli/commands.go:51 traefik_1 | main.main() traefik_1 | github.com/traefik/traefik/v2/cmd/traefik/traefik.go:78 +0x405
traefik traefik:v2.10.4
No response
The following program
sample.go
triggers an unexpected resultExpected result
Got
Plugin was vendored before launching Traefik
Yaegi Version
traefik traefik:v2.10.4
Additional Notes
No response