From 14c9d62c1e2f4b84078e4e606e9662c1c448df34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Hejman?= Date: Thu, 21 Nov 2024 13:04:11 +0100 Subject: [PATCH] Remove `quesma/network` (#1024) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related: https://github.com/QuesmaOrg/quesma/issues/1017 Signed-off-by: Przemysław Hejman --- quesma/proxy/l4_proxy.go | 5 ++--- quesma/proxy/l4_proxy_test.go | 16 ++++++++-------- quesma/quesma/config/config.go | 3 +-- quesma/quesma/config/config_v2.go | 8 ++++---- quesma/quesma/dual_write_proxy.go | 4 ++-- quesma/quesma/quesma.go | 3 +-- quesma/{network/types.go => util/port.go} | 3 ++- 7 files changed, 20 insertions(+), 22 deletions(-) rename quesma/{network/types.go => util/port.go} (96%) diff --git a/quesma/proxy/l4_proxy.go b/quesma/proxy/l4_proxy.go index a0cddee4c..be62f4159 100644 --- a/quesma/proxy/l4_proxy.go +++ b/quesma/proxy/l4_proxy.go @@ -12,7 +12,6 @@ import ( "quesma/clickhouse" "quesma/elasticsearch" "quesma/logger" - "quesma/network" "quesma/quesma/config" "quesma/quesma/types" "quesma/stats" @@ -27,7 +26,7 @@ const ( ) type TcpProxy struct { - From network.Port + From util.Port To string inspect bool inspectHttpServer *http.Server @@ -35,7 +34,7 @@ type TcpProxy struct { acceptingConnections atomic.Bool } -func NewTcpProxy(From network.Port, To string, inspect bool) *TcpProxy { +func NewTcpProxy(From util.Port, To string, inspect bool) *TcpProxy { return &TcpProxy{ From: From, To: To, diff --git a/quesma/proxy/l4_proxy_test.go b/quesma/proxy/l4_proxy_test.go index c7c059b7e..f01213840 100644 --- a/quesma/proxy/l4_proxy_test.go +++ b/quesma/proxy/l4_proxy_test.go @@ -10,8 +10,8 @@ import ( "log" "net" "net/http" - "quesma/network" "quesma/stats" + "quesma/util" "slices" "strconv" "testing" @@ -53,7 +53,7 @@ func TestTcpProxy_IngestAndProcess(t *testing.T) { verifyStatistics(t, fromPort) } -func verifyStatistics(t *testing.T, port network.Port) { +func verifyStatistics(t *testing.T, port util.Port) { go func() { _, err := http.Post(fmt.Sprintf("http://localhost:%d/logs/_doc", int(port)), "application/json", bytes.NewBuffer([]byte(exampleLog()))) if err != nil { @@ -73,7 +73,7 @@ func verifyStatistics(t *testing.T, port network.Port) { t.Fatal("Statistics not updated") } -func verifyTCPProxy(t1 *testing.T, data string, fromPort network.Port, toPort network.Port) { +func verifyTCPProxy(t1 *testing.T, data string, fromPort util.Port, toPort util.Port) { conn, err := net.Dial("tcp", ":"+strconv.Itoa(int(fromPort))) if err != nil { t1.Fatal("Error dialing to port:", err) @@ -106,22 +106,22 @@ func verifyTCPProxy(t1 *testing.T, data string, fromPort network.Port, toPort ne } } -var allocatedPorts = make([]network.Port, 0) +var allocatedPorts = make([]util.Port, 0) -func findFreePort() network.Port { +func findFreePort() util.Port { port := 11000 for { - if slices.Contains(allocatedPorts, network.Port(port)) { + if slices.Contains(allocatedPorts, util.Port(port)) { port++ continue } listener, err := net.Listen("tcp", ":"+strconv.Itoa(port)) if err == nil { _ = listener.Close() - allocatedPorts = append(allocatedPorts, network.Port(port)) + allocatedPorts = append(allocatedPorts, util.Port(port)) log.Println("Allocated port:", port) - return network.Port(port) + return util.Port(port) } port++ } diff --git a/quesma/quesma/config/config.go b/quesma/quesma/config/config.go index 15ea69dbf..99b875f47 100644 --- a/quesma/quesma/config/config.go +++ b/quesma/quesma/config/config.go @@ -11,7 +11,6 @@ import ( "log" "os" "quesma/elasticsearch/elasticsearch_field_types" - "quesma/network" "quesma/util" "strings" ) @@ -38,7 +37,7 @@ type QuesmaConfiguration struct { Elasticsearch ElasticsearchConfiguration IndexConfig map[string]IndexConfiguration Logging LoggingConfiguration - PublicTcpPort network.Port + PublicTcpPort util.Port IngestStatistics bool QuesmaInternalTelemetryUrl *Url DisableAuth bool diff --git a/quesma/quesma/config/config_v2.go b/quesma/quesma/config/config_v2.go index 345c39e4e..997ea2c52 100644 --- a/quesma/quesma/config/config_v2.go +++ b/quesma/quesma/config/config_v2.go @@ -10,7 +10,7 @@ import ( "github.com/knadh/koanf/v2" "github.com/rs/zerolog" "log" - "quesma/network" + "quesma/util" "reflect" "slices" "strings" @@ -72,8 +72,8 @@ type FrontendConnector struct { } type FrontendConnectorConfiguration struct { - ListenPort network.Port `koanf:"listenPort"` - DisableAuth bool `koanf:"disableAuth"` + ListenPort util.Port `koanf:"listenPort"` + DisableAuth bool `koanf:"disableAuth"` } type BackendConnector struct { @@ -849,7 +849,7 @@ END: return conf } -func (c *QuesmaNewConfiguration) getPublicTcpPort() (network.Port, error) { +func (c *QuesmaNewConfiguration) getPublicTcpPort() (util.Port, error) { // per validation, there's always at least one frontend connector, // even if there's a second one, it has to listen on the same port return c.FrontendConnectors[0].Config.ListenPort, nil diff --git a/quesma/quesma/dual_write_proxy.go b/quesma/quesma/dual_write_proxy.go index a56506be4..34b96208c 100644 --- a/quesma/quesma/dual_write_proxy.go +++ b/quesma/quesma/dual_write_proxy.go @@ -10,7 +10,6 @@ import ( "quesma/clickhouse" "quesma/elasticsearch" "quesma/logger" - "quesma/network" "quesma/quesma/async_search_storage" "quesma/quesma/config" "quesma/quesma/mux" @@ -18,6 +17,7 @@ import ( "quesma/quesma/ui" "quesma/schema" "quesma/telemetry" + "quesma/util" "strconv" "sync/atomic" "time" @@ -58,7 +58,7 @@ type dualWriteHttpProxy struct { elasticRouter *mux.PathRouter indexManagement elasticsearch.IndexManagement logManager *clickhouse.LogManager - publicPort network.Port + publicPort util.Port asyncQueriesEvictor *async_search_storage.AsyncQueriesEvictor queryRunner *QueryRunner schemaRegistry schema.Registry diff --git a/quesma/quesma/quesma.go b/quesma/quesma/quesma.go index 7d69daebe..bd828cf3e 100644 --- a/quesma/quesma/quesma.go +++ b/quesma/quesma/quesma.go @@ -16,7 +16,6 @@ import ( "quesma/feature" "quesma/ingest" "quesma/logger" - "quesma/network" "quesma/proxy" "quesma/queryparser" "quesma/quesma/config" @@ -39,7 +38,7 @@ import ( type ( Quesma struct { processor engine - publicTcpPort network.Port + publicTcpPort util.Port quesmaManagementConsole *ui.QuesmaManagementConsole config *config.QuesmaConfiguration telemetryAgent telemetry.PhoneHomeAgent diff --git a/quesma/network/types.go b/quesma/util/port.go similarity index 96% rename from quesma/network/types.go rename to quesma/util/port.go index 508774b8f..4e0207bd7 100644 --- a/quesma/network/types.go +++ b/quesma/util/port.go @@ -1,6 +1,7 @@ // Copyright Quesma, licensed under the Elastic License 2.0. // SPDX-License-Identifier: Elastic-2.0 -package network + +package util import ( "fmt"