fix: re-use connections in webhook/elasticsearch (#9461)

- elasticsearch client should rely on the SDK helpers
  instead of pure HTTP calls.
- webhook shouldn't need to check for IsActive() for
  all notifications, failure should be delayed.
- Remove DialHTTP as its never used properly

Fixes #9460
This commit is contained in:
Harshavardhana
2020-04-28 13:57:56 -07:00
committed by GitHub
parent 1b122526aa
commit 7a5271ad96
6 changed files with 104 additions and 274 deletions

View File

@@ -20,14 +20,10 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"path"
"strings"
"time"
)
// URL - improved JSON friendly url.URL.
@@ -85,34 +81,6 @@ func (u *URL) UnmarshalJSON(data []byte) (err error) {
return nil
}
// DialHTTP - dials the url to check the connection.
func (u URL) DialHTTP(transport *http.Transport) error {
if transport == nil {
transport = &http.Transport{
DialContext: (&net.Dialer{
Timeout: 2 * time.Second,
}).DialContext,
}
}
var client = &http.Client{
Transport: transport,
}
req, err := http.NewRequest("POST", u.String(), nil)
if err != nil {
return err
}
resp, err := client.Do(req)
if err != nil {
return err
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
return nil
}
// ParseHTTPURL - parses a string into HTTP URL, string is
// expected to be of form http:// or https://
func ParseHTTPURL(s string) (u *URL, err error) {