mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-09 03:28:29 +00:00
get dataproc logs when jobs fail in test (#2049)
The hadoop test passes for me locally but fails in CI, so this should give some extra debugging information (my user acct doesn't have permissions to read the dataproc logs from the failing test). WIP for now because I want to make sure this method of reading the logs works.
This commit is contained in:
parent
dc27ea8e49
commit
f7630cb5f0
|
@ -2,10 +2,14 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
@ -318,7 +322,32 @@ func testAccCheckDataprocJobCompletesSuccessfully(n string, job *dataproc.Job) r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if completeJob.Status.State != "DONE" {
|
if completeJob.Status.State == "ERROR" {
|
||||||
|
if !strings.HasPrefix(completeJob.DriverOutputResourceUri, "gs://") {
|
||||||
|
return fmt.Errorf("Job completed in ERROR state but no valid log URI found")
|
||||||
|
}
|
||||||
|
u := strings.SplitN(strings.TrimPrefix(completeJob.DriverOutputResourceUri, "gs://"), "/", 2)
|
||||||
|
if len(u) != 2 {
|
||||||
|
return fmt.Errorf("Job completed in ERROR state but no valid log URI found")
|
||||||
|
}
|
||||||
|
l, err := config.clientStorage.Objects.List(u[0]).Prefix(u[1]).Do()
|
||||||
|
if err != nil {
|
||||||
|
return errwrap.Wrapf("Job completed in ERROR state, found error when trying to list logs: {{err}}", err)
|
||||||
|
}
|
||||||
|
for _, item := range l.Items {
|
||||||
|
resp, err := config.clientStorage.Objects.Get(item.Bucket, item.Name).Download()
|
||||||
|
if err != nil {
|
||||||
|
return errwrap.Wrapf("Job completed in ERROR state, found error when trying to read logs: {{err}}", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return errwrap.Wrapf("Job completed in ERROR state, found error when trying to read logs: {{err}}", err)
|
||||||
|
}
|
||||||
|
log.Printf("[ERROR] Job failed, driver logs:\n%s", body)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Job completed in ERROR state, check logs for details")
|
||||||
|
} else if completeJob.Status.State != "DONE" {
|
||||||
return fmt.Errorf("Job did not complete successfully, instead status: %s", completeJob.Status.State)
|
return fmt.Errorf("Job did not complete successfully, instead status: %s", completeJob.Status.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user