This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Improvements on whisper importer #704
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b94da9
change the way cassandra gets initialized in whisper importer
replay 7673c29
initialize index
replay 9e5b8f4
add status url
replay 3776c5f
add auth and error handling to reader
replay 07a2335
add help message
replay 992ad72
reuse connections & rename /status to /healthz
replay 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"encoding/base64" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
|
@@ -63,6 +66,11 @@ var ( | |
1, | ||
"Organization ID the data belongs to ", | ||
) | ||
insecureSSL = flag.Bool( | ||
"insecure-ssl", | ||
false, | ||
"Disables ssl certificate verification", | ||
) | ||
whisperDirectory = flag.String( | ||
"whisper-directory", | ||
"/opt/graphite/storage/whisper", | ||
|
@@ -73,6 +81,11 @@ var ( | |
"*", | ||
"Comma separated list of positive integers or '*' for all archives", | ||
) | ||
httpAuth = flag.String( | ||
"http-auth", | ||
"", | ||
"The credentials used to authenticate in the format \"user:password\"", | ||
) | ||
chunkSpans []uint32 | ||
readArchives map[int]struct{} | ||
printLock sync.Mutex | ||
|
@@ -139,7 +152,10 @@ func log(msg string) { | |
} | ||
|
||
func processFromChan(files chan string, wg *sync.WaitGroup) { | ||
client := &http.Client{} | ||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: *insecureSSL}, | ||
} | ||
client := &http.Client{Transport: tr} | ||
|
||
for file := range files { | ||
fd, err := os.Open(file) | ||
|
@@ -173,11 +189,20 @@ func processFromChan(files chan string, wg *sync.WaitGroup) { | |
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("Content-Encoding", "gzip") | ||
|
||
_, err = client.Do(req) | ||
if len(*httpAuth) > 0 { | ||
req.Header.Add("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(*httpAuth))) | ||
} | ||
|
||
resp, err := client.Do(req) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to drain the resp.Body in order for the connection to be re-used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if err != nil { | ||
throwError(fmt.Sprintf("Error sending request to http endpoint %q: %q", *httpEndpoint, err)) | ||
continue | ||
} | ||
if resp.StatusCode != 200 { | ||
throwError(fmt.Sprintf("Error when submitting data: %s", resp.Status)) | ||
} | ||
io.Copy(ioutil.Discard, resp.Body) | ||
resp.Body.Close() | ||
} | ||
wg.Done() | ||
} | ||
|
@@ -363,7 +388,7 @@ func getFileListIntoChan(fileChan chan string) { | |
filepath.Walk( | ||
*whisperDirectory, | ||
func(path string, info os.FileInfo, err error) error { | ||
if path[len(path)-4:] == ".wsp" { | ||
if len(path) >= 4 && path[len(path)-4:] == ".wsp" { | ||
fileChan <- path | ||
} | ||
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
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.
Rather than manually adding the header, you can call
But as you have the user/pass in a single string, what you are doing is probably easier.
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.
ok thx, i'll leave it then