Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Add some error output where it was missing, add trailing new line to …
Browse files Browse the repository at this point in the history
…bulk body
  • Loading branch information
vanetix committed Jan 26, 2018
1 parent 234b783 commit 08dfb17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bushwack/log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (entries LogEntries) SerializeBulkBody() (string, error) {
lines = append(lines, string(j))
}

return strings.Join(lines, "\n"), nil
// Dont forget the last \n for the bulk api
return fmt.Sprintf("%s\n", strings.Join(lines, "\n")), nil
}

// 2018-01-22T23:55:03.306727Z
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func processLog(filename string) {
log.Fatal(err)
}

if len(entries) == 0 {
log.Println("No entries to index.")
return
}

body, err := entries.SerializeBulkBody()
if err != nil {
log.Fatal(err)
Expand All @@ -106,7 +111,10 @@ func processLog(filename string) {
}

if resp.StatusCode != 200 {
log.Println("Yikes, looks like we had a request return a non-200 status")
log.Printf("Received unexpected status code %d.\n", resp.StatusCode)

reason, _ := ioutil.ReadAll(resp.Body)
log.Fatalf("Reason: %s", reason)
}

log.Printf("Sent off %d log entries.", len(entries))
Expand Down

0 comments on commit 08dfb17

Please sign in to comment.