-
Notifications
You must be signed in to change notification settings - Fork 100
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
ship logs to http endpoint #1228
Merged
Merged
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
c756dab
rough http buffer for to use for logger
James-Pickett b6f17ef
splits send buffer into own package, adds httpsenderlog
James-Pickett 15d8ea9
added send mutex unlock after purge failure
James-Pickett 8e1cf84
Merge branch 'main' into james/log-shipping
James-Pickett 14989f9
addes log shipper, subscribes to control server auth token updates
James-Pickett 43d07df
tweaks
James-Pickett 0aa445e
few more tweaks
James-Pickett 99d9661
Merge branch 'main' into james/log-shipping
James-Pickett 73f7a66
add new flag for trace specific ingest url
James-Pickett 6e81014
updates logshipper to use scheme based on obserability tls flag
James-Pickett da1ea15
update mocks
James-Pickett 3fb0ef9
Merge branch 'main' into james/log-shipping
James-Pickett bec6850
drop kvstore from send buffer
James-Pickett ca7dff8
updates var names in send buffer to be more clear
James-Pickett 09d5312
more var renaming
James-Pickett 1e09c8d
fix tests broken by update to trace url name
James-Pickett 11360e1
test clean up
James-Pickett 00f55cf
now using blocking run style for send buffer
James-Pickett 6cc4fd5
adds test for log shipper, updates based on feedback
James-Pickett 4f4ecb9
update misspelled file name
James-Pickett 28513d4
adds some logic to now stop launcher start up if logshipping init errors
James-Pickett 3e28bd2
Merge branch 'main' into james/log-shipping
James-Pickett 8f9df5f
remove context from log shipper constructor
James-Pickett 355a4c8
no creating ctx and cancel func on run call
James-Pickett 4d95623
fix test
James-Pickett edc9ed4
fixing tests
James-Pickett ab8ce04
Merge branch 'main' into james/log-shipping
James-Pickett 850cb1b
only start logshipping if we have observerabiltiy ingest url
James-Pickett 6e16b99
adds flag for log shipping enabled
James-Pickett 847a940
update mocks for log shipper test
James-Pickett b1a3f19
better func names
James-Pickett c16d9fa
update flags mock
James-Pickett 4ed2bd7
add mutext to delete all data, add test
James-Pickett 5152ea7
fix log shipper url parsing
James-Pickett d69267c
fix broken test
James-Pickett 6365497
cache is enabled booleaon on logshipper update
James-Pickett c434308
use explicit log_ingest_url flag instead of observability_ingest_url
James-Pickett ad75750
drop log shipping enabled flag and just rely on presence of log inges…
James-Pickett 40dabe3
feedback
James-Pickett 890a9c0
consolidated endpoint and token updating, added to tests
James-Pickett 11dc04a
fix tests
James-Pickett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package logshipper | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type authedHttpSender struct { | ||
endpoint string | ||
authtoken string | ||
client *http.Client | ||
} | ||
|
||
func newAuthHttpSender(endpoint, authtoken string) *authedHttpSender { | ||
return &authedHttpSender{ | ||
endpoint: endpoint, | ||
authtoken: authtoken, | ||
client: &http.Client{ | ||
Timeout: 30 * time.Second, | ||
}, | ||
} | ||
} | ||
|
||
func (a *authedHttpSender) Send(r io.Reader) error { | ||
req, err := http.NewRequest("POST", a.endpoint, r) | ||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Content-Type", "application/octet-stream") | ||
req.Header.Set("authorization", a.authtoken) | ||
|
||
resp, err := a.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode >= 300 { | ||
bodyData, err := io.ReadAll(resp.Request.Body) | ||
if err != nil { | ||
return fmt.Errorf("received non 200 http status code: %d, error reading body response body %w", resp.StatusCode, err) | ||
} | ||
|
||
return fmt.Errorf("received non 200 http status code: %d, response body: %s", resp.StatusCode, bodyData) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package logshipper | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
"net/http/httptest" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/kolide/kit/ulid" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_authedHttpSender_Send(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
}{ | ||
{ | ||
name: "happy path", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
dataToSend := []byte(ulid.New()) | ||
token := ulid.New() | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
// create http test server with handle func that returns 200 OK | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
require.Equal(t, token, r.Header.Get("authorization")) | ||
w.WriteHeader(http.StatusOK) | ||
wg.Done() | ||
})) | ||
defer ts.Close() | ||
|
||
authedSender := newAuthHttpSender(ts.URL, token) | ||
authedSender.Send(bytes.NewBuffer(dataToSend)) | ||
|
||
wg.Wait() | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably okay to start with it. Interesting question is whether it's possible to enable/disable/change the URL from the control server