chore: enhanced http_client to support customizable configurations. (#61)
* chore: update http client * chore: update release notes
This commit is contained in:
parent
59e88f7b03
commit
29bef5e129
|
@ -23,7 +23,8 @@ Information about release notes of INFINI Console is provided here.
|
||||||
- Adapter metrics query with cluster id and cluster uuid
|
- Adapter metrics query with cluster id and cluster uuid
|
||||||
- Optimize metric query bucket size (#59)
|
- Optimize metric query bucket size (#59)
|
||||||
- Add suggestion to chart in monitor if is no data because the time interval is less than the collection interval.
|
- Add suggestion to chart in monitor if is no data because the time interval is less than the collection interval.
|
||||||
- check if the cluster version supports metric transport_outbound_comnections in monitor.
|
- Check if the cluster version supports metric transport_outbound_comnections in monitor.
|
||||||
|
- Enhanced http_client to support customizable configurations.
|
||||||
|
|
||||||
|
|
||||||
## 1.27.0 (2024-12-09)
|
## 1.27.0 (2024-12-09)
|
||||||
|
|
|
@ -26,7 +26,6 @@ package api
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/buger/jsonparser"
|
"github.com/buger/jsonparser"
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -34,15 +33,12 @@ import (
|
||||||
"infini.sh/framework/core/api"
|
"infini.sh/framework/core/api"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/global"
|
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"infini.sh/framework/lib/fasthttp"
|
"infini.sh/framework/lib/fasthttp"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpPool = fasthttp.NewRequestResponsePool("proxy_search")
|
var httpPool = fasthttp.NewRequestResponsePool("proxy_search")
|
||||||
|
@ -211,7 +207,7 @@ func (h *APIHandler) HandleProxyAction(w http.ResponseWriter, req *http.Request,
|
||||||
}
|
}
|
||||||
defer req.Body.Close()
|
defer req.Body.Close()
|
||||||
|
|
||||||
err = getHttpClient().Do(freq, fres)
|
err = api.GetFastHttpClient("elasticsearch_proxy").Do(freq, fres)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["error"] = err.Error()
|
resBody["error"] = err.Error()
|
||||||
h.WriteJSON(w, resBody, http.StatusInternalServerError)
|
h.WriteJSON(w, resBody, http.StatusInternalServerError)
|
||||||
|
@ -283,24 +279,4 @@ func rewriteTableNamesOfSqlRequest(req *http.Request, distribution string) (stri
|
||||||
return strings.Join(unescapedTableNames, ","), nil
|
return strings.Join(unescapedTableNames, ","), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
client *fasthttp.Client
|
|
||||||
clientOnce sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
func getHttpClient() *fasthttp.Client {
|
|
||||||
clientOnce.Do(func() {
|
|
||||||
clientCfg := global.Env().SystemConfig.HTTPClientConfig
|
|
||||||
client = &fasthttp.Client{
|
|
||||||
MaxConnsPerHost: clientCfg.MaxConnectionPerHost,
|
|
||||||
TLSConfig: &tls.Config{InsecureSkipVerify: clientCfg.TLSConfig.TLSInsecureSkipVerify},
|
|
||||||
ReadTimeout: util.GetDurationOrDefault(clientCfg.ReadTimeout, 60*time.Second),
|
|
||||||
WriteTimeout: util.GetDurationOrDefault(clientCfg.ReadTimeout, 60*time.Second),
|
|
||||||
DialDualStack: true,
|
|
||||||
ReadBufferSize: clientCfg.ReadBufferSize,
|
|
||||||
WriteBufferSize: clientCfg.WriteBufferSize,
|
|
||||||
//Dial: fasthttpproxy.FasthttpProxyHTTPDialerTimeout(time.Second * 2),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return client
|
|
||||||
}
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (h TestAPI) HandleTestConnectionAction(w http.ResponseWriter, req *http.Req
|
||||||
freq.SetBasicAuth(config.BasicAuth.Username, config.BasicAuth.Password.Get())
|
freq.SetBasicAuth(config.BasicAuth.Username, config.BasicAuth.Password.Get())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = getHttpClient().DoTimeout(freq, fres, 10*time.Second)
|
err = api.GetFastHttpClient("elasticsearch_test_connection").DoTimeout(freq, fres, 10*time.Second)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -145,7 +145,7 @@ func (h TestAPI) HandleTestConnectionAction(w http.ResponseWriter, req *http.Req
|
||||||
//fetch cluster health info
|
//fetch cluster health info
|
||||||
freq.SetRequestURI(fmt.Sprintf("%s/_cluster/health", config.Endpoint))
|
freq.SetRequestURI(fmt.Sprintf("%s/_cluster/health", config.Endpoint))
|
||||||
fres.Reset()
|
fres.Reset()
|
||||||
err = getHttpClient().Do(freq, fres)
|
err = api.GetFastHttpClient().Do(freq, fres)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["error"] = fmt.Sprintf("error on get cluster health: %v", err)
|
resBody["error"] = fmt.Sprintf("error on get cluster health: %v", err)
|
||||||
h.WriteJSON(w, resBody, http.StatusInternalServerError)
|
h.WriteJSON(w, resBody, http.StatusInternalServerError)
|
||||||
|
|
|
@ -96,7 +96,7 @@ func ProxyAgentRequest(tag, endpoint string, req *util.Request, responseObjectTo
|
||||||
var res *util.Result
|
var res *util.Result
|
||||||
|
|
||||||
initOnce.Do(func() {
|
initOnce.Do(func() {
|
||||||
cfg := global.Env().GetClientConfigByEndpoint(tag, endpoint)
|
cfg := global.Env().GetHTTPClientConfig(tag, endpoint)
|
||||||
if cfg != nil {
|
if cfg != nil {
|
||||||
hClient, err := api.NewHTTPClient(cfg)
|
hClient, err := api.NewHTTPClient(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue