fluentd icon indicating copy to clipboard operation
fluentd copied to clipboard

in_http plugin with msgpack format input doesn't work if object contains more than one properties

Open yantang-msft opened this issue 8 years ago • 6 comments

Fluentd version: 1.2.0

Configuration:

<source>
  @type http
  port 8887
</source>

<match debug.**>
  @type stdout
</match>

Issue: I want to send this object {"foo":"bar", "foo2":"bar2"} in msgpack format through this command: msgpack=`echo -e "\x82\xA3foo\xA3bar\xA4foo2\xA4bar2"` curl -X POST -d "$msgpack" -H 'Content-Type: application/msgpack' http://localhost:8887/debug.test

And this is what I get: 2018-05-07 13:26:48.681899000 -0700 debug.test: 63. It gives me the weird 63 but not {"foo":"bar", "foo2":"bar2"}. But if the object has only one property, then it works fine.

yantang-msft avatar May 07 '18 20:05 yantang-msft

@yantang-msft Apparently, your msgpack payload got corrupted somehow and it mess up the data parsing logic in msgpack-ruby.

Can you execute the following debug command and post the content of trace.txt here?

$ msgpack=`echo -e "\x82\xA3foo\xA3bar\xA4foo2\xA4bar2"`
$ curl --trace trace.txt -d "$msgpack" -H 'Content-Type: application/msgpack' http://localhost:8887/debug.test

Note

BTW, I can confirm msgpack payloads are working without problems in Fluentd v1.2.0 as follows. So I'm guessing that this issue is an environment-dependent issue...

Configuration

<source>
  @type http
</source>
<match **>
  @type stdout
</match>

Commands

$ msgpack=`echo -e "\x82\xA3foo\xA3bar\xA4foo2\xA4bar2"`
$ curl -X POST -d "$msgpack" -H 'Content-Type: application/msgpack' http://localhost:9880/debug.test

Result

2018-05-23 17:11:01.938428747 +0900 debug.test: {"foo":"bar","foo2":"bar2"}

fujimotos avatar May 23 '18 08:05 fujimotos

Yes, I'm on Windows. And here is the trace:

== Info: STATE: INIT => CONNECT handle 0x4600180; line 1392 (connection #-5000) == Info: Added connection 0. The cache now contains 1 members == Info: STATE: CONNECT => WAITRESOLVE handle 0x4600180; line 1428 (connection #0) == Info: Trying ::1... == Info: TCP_NODELAY set == Info: STATE: WAITRESOLVE => WAITCONNECT handle 0x4600180; line 1509 (connection #0) == Info: Trying 127.0.0.1... == Info: TCP_NODELAY set == Info: Connected to localhost (127.0.0.1) port 8887 (#0) == Info: STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x4600180; line 1561 (connection #0) == Info: Marked for [keep alive]: HTTP default == Info: STATE: SENDPROTOCONNECT => DO handle 0x4600180; line 1579 (connection #0) => Send header, 144 bytes (0x90) 0000: 50 4f 53 54 20 2f 64 65 62 75 67 2e 74 65 73 74 POST /debug.test 0010: 20 48 54 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a HTTP/1.1..Host: 0020: 20 6c 6f 63 61 6c 68 6f 73 74 3a 38 38 38 37 0d localhost:8887. 0030: 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 .User-Agent: cur 0040: 6c 2f 37 2e 35 38 2e 30 0d 0a 41 63 63 65 70 74 l/7.58.0..Accept 0050: 3a 20 2a 2f 2a 0d 0a 43 6f 6e 74 65 6e 74 2d 54 : /..Content-T 0060: 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e ype: application 0070: 2f 6d 73 67 70 61 63 6b 0d 0a 43 6f 6e 74 65 6e /msgpack..Conten 0080: 74 2d 4c 65 6e 67 74 68 3a 20 31 39 0d 0a 0d 0a t-Length: 19.... => Send data, 19 bytes (0x13) 0000: 3f a3 66 6f 6f a3 62 61 72 a4 66 6f 6f 32 a4 62 ?.foo.bar.foo2.b 0010: 61 72 32 ar2 == Info: upload completely sent off: 19 out of 19 bytes == Info: STATE: DO => DO_DONE handle 0x4600180; line 1658 (connection #0) == Info: STATE: DO_DONE => WAITPERFORM handle 0x4600180; line 1783 (connection #0) == Info: STATE: WAITPERFORM => PERFORM handle 0x4600180; line 1799 (connection #0) == Info: HTTP 1.1 or later with persistent connection, pipelining supported <= Recv header, 17 bytes (0x11) 0000: 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK. 0010: 0a . <= Recv header, 26 bytes (0x1a) 0000: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 Content-Type: te 0010: 78 74 2f 70 6c 61 69 6e 0d 0a xt/plain.. <= Recv header, 24 bytes (0x18) 0000: 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 4b 65 65 70 Connection: Keep 0010: 2d 41 6c 69 76 65 0d 0a -Alive.. <= Recv header, 19 bytes (0x13) 0000: 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content-Length: 0010: 30 0d 0a 0.. <= Recv header, 2 bytes (0x2) 0000: 0d 0a .. == Info: STATE: PERFORM => DONE handle 0x4600180; line 1968 (connection #0) == Info: multi_done == Info: Connection #0 to host localhost left intact == Info: Expire cleared

yantang-msft avatar May 23 '18 18:05 yantang-msft

OK. I can confirm your msgpack payload is broken.

Your payload

0000: 3f a3 66 6f 6f a3 62 61 72 a4 66 6f 6f 32 a4 62 ?.foo.bar.foo2.b
0010: 61 72 32                                         ar2

The correct payload

0000: 82 a3 66 6f 6f a3 62 61 72 a4 66 6f 6f 32 a4 62 ..foo.bar.foo2.b
0010: 61 72 32                                        ar2

Look at the first byte of the binary sequence. In your environment, curl is sending 0x3f where it should be 0x82, which in effect makes the whole payload invalid.

So it seems to me that it's not the problem of Fluentd par se.

Additional questions:

  • Which shell/terminal do you use to execute the command? (e.g. bash/cygwin)
  • Which version of windows do you use?

fujimotos avatar May 24 '18 03:05 fujimotos

I'm using git bash on Windows 10 (ver 1709), which is underlying using MINGW64. However I just tried PowerShell Invoke-WebRequest command and get the same result.

yantang-msft avatar May 24 '18 18:05 yantang-msft

However I just tried PowerShell Invoke-WebRequest command and get the same result.

I've set up testing environment (Windows 8) and confirmed that I could send msgpack payload from PowerShell without problems. (The version of Fluentd being tested was v1.2.0)

The following is the script I used for testing:

PS> $hex = '82 a3 66 6f 6f a3 62 61 72 a4 66 6f 6f 32 a4 62 61 72 32'
PS> $hex.split(' ') | foreach {[char]([convert]::toint16($_,16))} | foreach {$data = $data + $_}
PS> curl -Uri http://192.168.10.1:9000/ -Method Post -Body $data -ContentType application/msgpack
StatusCode        : 200
StatusDescription : OK
Content           :
RawContent        : HTTP/1.1 200 OK
                    Connection: Keep-Alive
                    Content-Length: 0
                    Content-Type: text/plain


Forms             : {}
Headers           : {[Connection, Keep-Alive], [Content-Length, 0], [Content-Type, text/plain]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 0

Here is the event record emitted by this request:

2018-05-25 16:55:20.821300530 +0900 : {"foo":"bar","foo2":"bar2"}

So, in short, I cannot reproduce your problem...

fujimotos avatar May 25 '18 08:05 fujimotos

@fujimotos Your script worked for me!

This is what I tried that failed.

$bytes = (0x82, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72, 0xa4, 0x66, 0x6f, 0x6f, 0x32, 0xa4, 0x62, 0x61, 0x72, 0x32)
$data = [System.Text.Encoding]::UTF8.GetString($bytes)
curl -Uri http://localhost:8887/ -Method Post -Body $data -ContentType application/msgpack

Apparently I don't have enough knowledge in encoding. There is simply no encoding in the byte array, and I shouldn't call UTF.GetString().

Don't know why git bash doesn't work, but I confirm the http plugin is indeed working and thus close the issue.
@fujimotos Thank you for the time trying everything, especially the Windows environment, I really appreciate it!

yantang-msft avatar May 25 '18 18:05 yantang-msft