From 08dfb172403c67765be864b8762a0255dad1e14b Mon Sep 17 00:00:00 2001 From: Matt McFarland <783024+vanetix@users.noreply.github.com> Date: Thu, 25 Jan 2018 18:36:49 -0600 Subject: [PATCH] Add some error output where it was missing, add trailing new line to bulk body --- bushwack/log_entry.go | 3 ++- main.go | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bushwack/log_entry.go b/bushwack/log_entry.go index 1d00a54..5225789 100644 --- a/bushwack/log_entry.go +++ b/bushwack/log_entry.go @@ -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 diff --git a/main.go b/main.go index 85b574d..1ede0a7 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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))