diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c475e321..94ac403d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Add a new environment variable: IS_PRINT_EVENT. When the value is true, sinsp events can be printed to the stdout. ([#283](https://github.com/CloudDectective-Harmonycloud/kindling/pull/283)) - Declare the 9500 port in the agent's deployment file ([#282](https://github.com/CloudDectective-Harmonycloud/kindling/pull/282)) ### Bug fixes +- Fix the bug where no HTTP headers were got. ([#301](https://github.com/CloudDectective-Harmonycloud/kindling/pull/301)) - Fix the bug that need_trace_as_span options cannot take effect ([#292](https://github.com/CloudDectective-Harmonycloud/kindling/pull/292)) - Fix connection failure rate data lost when change topology layout in the Grafana plugin. ([#289](https://github.com/CloudDectective-Harmonycloud/kindling/pull/289)) - Fix the bug that the external topologys' metric name is named with `kindling_entity_request` prefix. Change the prefix of these metrics to `kindling_topology_request` ([#287](https://github.com/CloudDectective-Harmonycloud/kindling/pull/287)) diff --git a/collector/pkg/component/analyzer/network/protocol/http/http_parser.go b/collector/pkg/component/analyzer/network/protocol/http/http_parser.go index e1eade1c8..f1e614a37 100644 --- a/collector/pkg/component/analyzer/network/protocol/http/http_parser.go +++ b/collector/pkg/component/analyzer/network/protocol/http/http_parser.go @@ -43,8 +43,8 @@ func parseHeaders(message *protocol.PayloadMessage) map[string]string { if data == nil { return header } - if position := strings.Index(string(data), ":"); position > 0 && position < len(data)-1 { - header[strings.ToLower(string(data[0:position]))] = string(data[position+1]) + if position := strings.Index(string(data), ":"); position > 0 && position < len(data)-2 { + header[strings.ToLower(string(data[0:position]))] = string(data[position+2:]) continue } return header diff --git a/collector/pkg/component/analyzer/network/protocol/http/http_parser_test.go b/collector/pkg/component/analyzer/network/protocol/http/http_parser_test.go index 192fe6816..de06a6568 100644 --- a/collector/pkg/component/analyzer/network/protocol/http/http_parser_test.go +++ b/collector/pkg/component/analyzer/network/protocol/http/http_parser_test.go @@ -1,6 +1,7 @@ package http import ( + "reflect" "testing" "github.com/Kindling-project/kindling/collector/pkg/component/analyzer/network/protocol" @@ -138,3 +139,63 @@ func TestParseHttpResponse_GetPayLoad(t *testing.T) { }) } } + +func Test_parseHeaders(t *testing.T) { + type args struct { + message *protocol.PayloadMessage + } + tests := []struct { + name string + args args + want map[string]string + }{ + { + name: "normal case", + args: args{ + message: protocol.NewRequestMessage([]byte("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nAPM-AgentID: TTXvC3EQS6KLwxx3eIqINFjAW2olRm+cr8M+yuvwhkY=\r\nTransfer-Encoding: chunked\r\nContent-Type: application/json\r\nAPM-TransactionID: 5e480579c718a4a6498a9")), + }, + want: map[string]string{ + "connection": "keep-alive", + "apm-agentid": "TTXvC3EQS6KLwxx3eIqINFjAW2olRm+cr8M+yuvwhkY=", + "transfer-encoding": "chunked", + "content-type": "application/json", + "apm-transactionid": "5e480579c718a4a6498a9", + }, + }, + { + name: "no values", + args: args{ + protocol.NewRequestMessage([]byte("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nTransfer-Encoding: ")), + }, + want: map[string]string{ + "connection": "keep-alive", + }, + }, + { + + name: "no spaces", + args: args{ + protocol.NewRequestMessage([]byte("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nTransfer-Encoding:")), + }, + want: map[string]string{ + "connection": "keep-alive", + }, + }, + { + name: "no colon", + args: args{ + protocol.NewRequestMessage([]byte("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nTransfer-Encoding")), + }, + want: map[string]string{ + "connection": "keep-alive", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := parseHeaders(tt.args.message); !reflect.DeepEqual(got, tt.want) { + t.Errorf("parseHeaders() = %v, want %v", got, tt.want) + } + }) + } +}