Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug where no HTTP headers were got #301

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"reflect"
"testing"

"github.com/Kindling-project/kindling/collector/pkg/component/analyzer/network/protocol"
Expand Down Expand Up @@ -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)
}
})
}
}