1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Improves error logging for Splunk hook (#2966)

* Improved logging of splunk connectivity errors

* Splunk logging

* Moved error logging message

* Bugfix for response body

* Moves response body check, logging of connectivity errors

* Reformatting
This commit is contained in:
ffeldmann 2021-07-14 08:48:48 +02:00 committed by GitHub
parent e9d8175c9b
commit 4922a75ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -174,6 +174,17 @@ func tryPostMessages(telemetryData MonitoringData, messages []log.Message) error
resp, err := SplunkClient.splunkClient.SendRequest(http.MethodPost, SplunkClient.splunkDsn, bytes.NewBuffer(payload), nil, nil)
if resp.StatusCode != http.StatusOK {
// log it to stdout
rdr := io.LimitReader(resp.Body, 1000)
body, errRead := ioutil.ReadAll(rdr)
log.Entry().Infof("%v: Splunk logging failed - %v", resp.Status, string(body))
if errRead != nil {
return errors.Wrap(errRead, "Error reading response body from Splunk.")
}
return errors.Wrapf(err, "%v: Splunk logging failed - %v", resp.Status, string(body))
}
if err != nil {
return errors.Wrap(err, "error sending the requests to Splunk")
}
@ -184,13 +195,6 @@ func tryPostMessages(telemetryData MonitoringData, messages []log.Message) error
errors.Wrap(err, "closing response body failed")
}
}()
if resp.StatusCode != http.StatusOK {
rdr := io.LimitReader(resp.Body, 1000)
body, err := ioutil.ReadAll(rdr)
if err != nil {
return errors.Wrap(err, "Error reading response body")
}
return errors.Wrapf(err, "%v: Splunk logging failed - %v", resp.Status, string(body))
}
return nil
}