Skip to content

bug: http-logger plugin gives 400 error while pushing the logs to HTTP server #9443

Description

@Revolyssup

Current Behavior

  • curl POSTing the same generated log manually on the Vector server is successful. But the POST request from apisix is failing.
    The successful request
curl http://localhost:3000 -H "Content-Type: application/json" -H "User-Agent: lua-resty-http/0.16.1 (Lua) ngx_lua/10021 "  
-H "Content-Length: 100" -H "Host: localhost"  -X POST -d '{"@timestamp":"2023-05-11T14:05:42+05:30","host":"127.0.0.1","clien
t_ip":"127.0.0.1","route_id":"1"}

Logs from Vector for successful curl

{"message":"{\"@timestamp\":\"2023-05-11T14:05:42+05:30\",\"host\":\"127.0.0.1\",\"client_ip\":\"127.0.0.1\",
\"route_id\":\"1\"}","path":"/","source_type":"http_server","timestamp":"2023-05-11T08:40:00.714802944Z"}
As you can see the Vector server running on port 3000 returns 400
![test](https://github.com/apache/apisix/assets/43276904/d9f4157a-066a-4916-afa5-4ff377607dbb)

Expected Behavior

http-logger should successfully POST the logs on the HTTP server.

Error Logs

2023/05/09 10:39:19 [error] 32037#0: *57331 [lua] batch-processor.lua:95: Batch Processor[http logger] failed to process entries: server returned status code[400] host[localhost] port[3000] body[], context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2023/05/09 10:39:19 [error] 32037#0: *57331 [lua] batch-processor.lua:104: Batch Processor[http logger] exceeded the max_retry_count[1] dropping the entries, context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080

Steps to Reproduce

  1. Run APISIX
  2. Run vector server (either locally or in a container with exposed port) with the following configuration
[sources.log-from-http]
type = "http_server"
address = "0.0.0.0:3000"
[sinks.log-2-console]
inputs = ["log-from-http"]
type = "console"
encoding.codec = "json"
  1. Pass the below configurations to admin API
curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "log_format": {
        "host": "$host",
        "@timestamp": "$time_iso8601",
        "client_ip": "$remote_addr"
    }
}'
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
      "plugins": {
            "http-logger": {
                "uri": "http://localhost:3000"
            }
       },
      "upstream": {
           "type": "roundrobin",
           "nodes": {
               "httpbin.org:80": 1
           }
      },
      "uri": "/"
}'

  1. Send request: curl -i http://127.0.0.1:9080
  2. Check error logs

Environment

  • APISIX version 3.3.0
  • Operating system: Linux 6.2.13-arch1-1
  • nginx version: openresty/1.21.4.1
  • LuaRocks version, for installation issues : 3.8.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions