Skip to content

Commit

Permalink
chore: removing unused http.Client
Browse files Browse the repository at this point in the history
* a HTTPS client is not needed to verify clickhouse data
  • Loading branch information
lordvidex committed Jul 22, 2023
1 parent a4cc2ec commit 53b4882
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
17 changes: 4 additions & 13 deletions cmd/e2e-test/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Clickhouse struct {
url string `toml:"-"`
tlsurl string `toml:"-"`
container string `toml:"-"`
client *http.Client
}

func (c *Clickhouse) CheckConfig(rootDir string) error {
Expand Down Expand Up @@ -75,7 +74,6 @@ func (c *Clickhouse) Start() (string, error) {
return "", err
}
port := strings.Split(c.httpAddress, ":")[1]
c.client = http.DefaultClient
c.url = "http://" + c.httpAddress

c.container = ClickhouseContainerName
Expand Down Expand Up @@ -155,11 +153,8 @@ func (c *Clickhouse) URL() string {
return c.url
}

func (c *Clickhouse) TLSURL() (string, bool) {
if c.tlsurl == "" {
return "", false
}
return c.tlsurl, true
func (c *Clickhouse) TLSURL() string {
return c.tlsurl
}

func (c *Clickhouse) Container() string {
Expand All @@ -177,7 +172,7 @@ func (c *Clickhouse) Query(sql string) (string, error) {
return "", err
}

resp, err := c.client.Do(request)
resp, err := http.DefaultClient.Do(request)
if err != nil {
return "", err
}
Expand All @@ -191,15 +186,11 @@ func (c *Clickhouse) Query(sql string) (string, error) {
return string(msg), nil
}

func (c *Clickhouse) SetClient(client *http.Client) {
c.client = client
}

func (c *Clickhouse) Alive() bool {
if len(c.container) == 0 {
return false
}
req, err := http.DefaultClient.Get("http://" + c.httpAddress)
req, err := http.DefaultClient.Get(c.URL())
if err != nil {
return false
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/e2e-test/e2etesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -174,16 +173,17 @@ func testCarbonClickhouse(
ConfigTpl: testDir + "/" + test.ConfigTpl,
TestDir: absoluteDir,
}
var (
tlsurl string
)
if test.HasTLSSettings() {
url, exists := clickhouse.TLSURL()
if exists {
err = cch.Start(clickhouse.URL(), url)
} else {
err = errors.New("test has tls settings but there is no clickhouse tls url")
tlsurl = clickhouse.TLSURL()
if tlsurl == "" {
logger.Error("test has tls settings but there is no clickhouse tls url")
return false
}
} else {
err = cch.Start(clickhouse.URL(), "")
}
err = cch.Start(clickhouse.URL(), tlsurl)
if err != nil {
logger.Error("starting carbon-clickhouse",
zap.String("config", test.name),
Expand Down
23 changes: 1 addition & 22 deletions cmd/e2e-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import (
"flag"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"runtime"
"time"

"go.uber.org/zap"

helpercfg "github.com/lomik/carbon-clickhouse/helper/config"
)

type MainConfig struct {
Expand Down Expand Up @@ -136,8 +133,7 @@ func main() {

failed := 0
total := 0
for chVersion := range chVersions {
ch := chVersions[chVersion]
for chVersion, ch := range chVersions {
if exist, out := containerExist(ClickhouseContainerName); exist {
logger.Error("clickhouse already exist",
zap.String("container", ClickhouseContainerName),
Expand Down Expand Up @@ -170,23 +166,6 @@ func main() {
total++
} else {
for _, config := range configs {
testDir := config.Test.dir
client := &http.Client{Timeout: time.Minute}
if ch.TLSEnabled && config.Test.HasTLSSettings() {
conf, err := helpercfg.ParseClientTLSConfig(&helpercfg.TLS{
Certificates: []helpercfg.CertificatePair{{testDir + "/client.key", testDir + "/client.crt"}},
CACertFiles: []string{testDir + "/ca.crt"},
})
if err != nil {
logger.Error("failed to parse tls")
failed += len(config.Test.InputTypes)
}
client.Transport = &http.Transport{
TLSClientConfig: conf,
DisableKeepAlives: true,
}
}
ch.SetClient(client)
if config.Test.chVersions[chVersion] {
testFailed, testTotal := runTest(config, &ch, rootDir, *verbose, *breakOnError, logger)
failed += testFailed
Expand Down

0 comments on commit 53b4882

Please sign in to comment.