Skip to content

Commit 0491b07

Browse files
authored
Add slash to libhoney paths (#40071)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Adds a slash to the end of the `traces_url_paths:` so that libhoney appending datasets will always work regardless of whether the user adds the slash or not. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #40070 <!--Describe what testing was performed and which tests were added.--> #### Testing curling a simple json object into the libhoney receiver to see that it doesn't return a 404 error. <!--Describe the documentation added.--> #### Documentation No changes to the documentation because it is handled in the configuration parser now. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 66158fb commit 0491b07

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

.chloggen/libhoney_clarify.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
change_type: bug_fix
2+
component: libhoneyreceiver
3+
note: Handle paths without slashes at the end by adding them
4+
issues: [40070]
5+
subtext:
6+
change_logs: [user]

receiver/libhoneyreceiver/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The following setting is required for refinery traffic since:
6767
### Telemetry data types supported
6868
6969
It will subscribe to the Traces and Logs signals but accept traffic destined for either pipeline using one http receiver
70-
component. Libhoney doesnot differentiate between the two so the receiver will identify which pipeline to deliver the
70+
component. Libhoney does not differentiate between the two so the receiver will identify which pipeline to deliver the
7171
spans or log records to.
7272
7373
No support for metrics since they'd look just like logs.

receiver/libhoneyreceiver/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/url"
1010
"path"
11+
"strings"
1112

1213
"go.opentelemetry.io/collector/config/confighttp"
1314
"go.opentelemetry.io/collector/confmap"
@@ -76,5 +77,10 @@ func sanitizeURLPath(urlPath string) (string, error) {
7677
if !path.IsAbs(u.Path) {
7778
u.Path = "/" + u.Path
7879
}
80+
81+
if !strings.HasSuffix(u.Path, "/") {
82+
u.Path += "/"
83+
}
84+
7985
return u.Path, nil
8086
}

receiver/libhoneyreceiver/receiver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (r *libhoneyReceiver) handleEvent(resp http.ResponseWriter, req *http.Reque
253253
}
254254

255255
noErrors := []byte(`{"errors":[]}`)
256-
writeResponse(resp, enc.ContentType(), http.StatusAccepted, noErrors)
256+
writeResponse(resp, enc.ContentType(), http.StatusOK, noErrors)
257257
}
258258

259259
func readContentType(resp http.ResponseWriter, req *http.Request) (encoder.Encoder, bool) {

receiver/libhoneyreceiver/receiver_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func TestNewLibhoneyReceiver(t *testing.T) {
4343
config: nil,
4444
wantError: false,
4545
},
46+
{
47+
name: "config_without_trailing_slashes",
48+
config: &Config{
49+
HTTP: &HTTPConfig{
50+
TracesURLPaths: []string{"/1/events"},
51+
},
52+
},
53+
wantError: false,
54+
},
4655
}
4756

4857
for _, tt := range tests {
@@ -99,7 +108,7 @@ func TestLibhoneyReceiver_HandleEvent(t *testing.T) {
99108
},
100109
},
101110
contentType: "application/json",
102-
expectedStatus: http.StatusAccepted,
111+
expectedStatus: http.StatusOK,
103112
},
104113
{
105114
name: "valid_msgpack_event",
@@ -114,7 +123,7 @@ func TestLibhoneyReceiver_HandleEvent(t *testing.T) {
114123
},
115124
},
116125
contentType: "application/msgpack",
117-
expectedStatus: http.StatusAccepted,
126+
expectedStatus: http.StatusOK,
118127
},
119128
{
120129
name: "invalid_content_type",

0 commit comments

Comments
 (0)