Skip to content

Commit

Permalink
Merge branch 'main' into pr-ingest-types
Browse files Browse the repository at this point in the history
  • Loading branch information
nablaone authored Dec 30, 2024
2 parents 8354859 + d4745d3 commit 35e492c
Show file tree
Hide file tree
Showing 46 changed files with 2,123 additions and 335 deletions.
45 changes: 42 additions & 3 deletions NOTICE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,45 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------------------------------------------
#### Module : github.com/H0llyW00dzZ/cidr
Version : v1.2.1
Time : 2024-03-27T02:04:51Z
Licence : BSD-3-Clause

Contents of probable licence file $GOMODCACHE/github.com/!h0lly!w00dz!z/[email protected]/LICENSE:

BSD 3-Clause License

Copyright (c) 2024, H0llyW00dzZ
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------------------
#### Module : github.com/antlr4-go/antlr/v4
Version : v4.13.1
Expand Down Expand Up @@ -1564,11 +1603,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------------------
#### Module : github.com/jackc/pgx/v5
Version : v5.7.1
Time : 2024-09-10T12:25:07Z
Version : v5.7.2
Time : 2024-12-21T15:25:36Z
Licence : MIT

Contents of probable licence file $GOMODCACHE/github.com/jackc/pgx/[email protected].1/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/jackc/pgx/[email protected].2/LICENSE:

Copyright (c) 2013-2021 Jack Christensen

Expand Down
6 changes: 5 additions & 1 deletion ci/it/configs/quesma-ab.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: QP
type: quesma-v1-processor-query
Expand Down
5 changes: 5 additions & 0 deletions ci/it/configs/quesma-as-transparent-proxy.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ backendConnectors:
url: "http://{{ .elasticsearch_host }}:{{ .elasticsearch_port }}"
user: elastic
password: quesmaquesma
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: noop-query-processor
type: quesma-v1-processor-noop
Expand Down
6 changes: 5 additions & 1 deletion ci/it/configs/quesma-ingest.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: my-query-processor
type: quesma-v1-processor-query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: my-query-processor
type: quesma-v1-processor-query
Expand Down
6 changes: 5 additions & 1 deletion ci/it/configs/quesma-wildcard-clickhouse.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: my-query-processor
type: quesma-v1-processor-query
Expand Down
6 changes: 5 additions & 1 deletion ci/it/configs/quesma-wildcard-disabled.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: my-query-processor
type: quesma-v1-processor-query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: QP
type: quesma-v1-processor-query
Expand Down
6 changes: 5 additions & 1 deletion ci/it/configs/quesma-with-two-pipelines.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ backendConnectors:
type: clickhouse-os
config:
url: clickhouse://{{ .clickhouse_host }}:{{ .clickhouse_port }}
ingestStatistics: true
logging:
path: "logs"
level: "info"
disableFileLogging: false
enableSQLTracing: true
processors:
- name: my-query-processor
type: quesma-v1-processor-query
Expand Down
4 changes: 2 additions & 2 deletions ci/it/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module quesma.com/its

go 1.21.6
go 1.23.2

require (
github.com/ClickHouse/clickhouse-go/v2 v2.20.0
Expand Down Expand Up @@ -61,7 +61,7 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
Expand Down
4 changes: 2 additions & 2 deletions ci/it/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
4 changes: 3 additions & 1 deletion ci/it/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

func runIntegrationTest(t *testing.T, testCase testcases.TestCase) {
ctx := context.Background()
defer testCase.Cleanup(ctx, t)
t.Cleanup(func() {
testCase.Cleanup(ctx, t)
})
if err := testCase.SetupContainers(ctx); err != nil {
t.Fatalf("Failed to setup containers: %s", err)
}
Expand Down
38 changes: 38 additions & 0 deletions quesma/frontend_connectors/basic_http_frontend_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type BasicHTTPFrontendConnector struct {
phoneHomeClient diag.PhoneHomeClient
debugInfoCollector diag.DebugInfoCollector
logger quesma_api.QuesmaLogger
middlewares []http.Handler
}

func (h *BasicHTTPFrontendConnector) GetChildComponents() []interface{} {
Expand Down Expand Up @@ -66,6 +67,7 @@ func NewBasicHTTPFrontendConnector(endpoint string, config *config.QuesmaConfigu
responseMutator: func(w http.ResponseWriter) http.ResponseWriter {
return w
},
middlewares: make([]http.Handler, 0),
}
}

Expand All @@ -81,7 +83,39 @@ func (h *BasicHTTPFrontendConnector) GetRouter() quesma_api.Router {
return h.router
}

type ResponseWriterWithStatusCode struct {
http.ResponseWriter
statusCode int
}

func (w *ResponseWriterWithStatusCode) WriteHeader(statusCode int) {
w.statusCode = statusCode
w.ResponseWriter.WriteHeader(statusCode)
}

func (h *BasicHTTPFrontendConnector) ServeHTTP(w http.ResponseWriter, req *http.Request) {
index := 0
var runMiddleware func()

runMiddleware = func() {
if index < len(h.middlewares) {
middleware := h.middlewares[index]
index++
responseWriter := &ResponseWriterWithStatusCode{w, 0}
middleware.ServeHTTP(responseWriter, req) // Automatically proceeds to the next middleware
// Only if the middleware did not set a status code, we proceed to the next middleware
if responseWriter.statusCode == 0 {
runMiddleware()
}

} else {
h.finalHandler(w, req)
}
}
runMiddleware()
}

func (h *BasicHTTPFrontendConnector) finalHandler(w http.ResponseWriter, req *http.Request) {
reqBody, err := PeekBodyV2(req)
if err != nil {
http.Error(w, "Error reading request body", http.StatusInternalServerError)
Expand Down Expand Up @@ -144,3 +178,7 @@ func ReadRequestBody(request *http.Request) ([]byte, error) {
func (h *BasicHTTPFrontendConnector) GetRouterInstance() *RouterV2 {
return h.routerInstance
}

func (h *BasicHTTPFrontendConnector) AddMiddleware(middleware http.Handler) {
h.middlewares = append(h.middlewares, middleware)
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
// Copyright Quesma, licensed under the Elastic License 2.0.
// SPDX-License-Identifier: Elastic-2.0

package quesma
package frontend_connectors

import (
"context"
"net/http"
"quesma/clickhouse"
"quesma/frontend_connectors"
"quesma/quesma/config"
"quesma/schema"
quesma_api "quesma_v2/core"
"quesma_v2/core/diag"
)

type ElasticHttpIngestFrontendConnector struct {
*frontend_connectors.BasicHTTPFrontendConnector

Config *config.QuesmaConfiguration

phoneHomeClient diag.PhoneHomeClient
*BasicHTTPFrontendConnector
}

func NewElasticHttpIngestFrontendConnector(endpoint string,
Expand All @@ -28,7 +22,7 @@ func NewElasticHttpIngestFrontendConnector(endpoint string,
config *config.QuesmaConfiguration, router quesma_api.Router) *ElasticHttpIngestFrontendConnector {

fc := &ElasticHttpIngestFrontendConnector{
BasicHTTPFrontendConnector: frontend_connectors.NewBasicHTTPFrontendConnector(endpoint, config),
BasicHTTPFrontendConnector: NewBasicHTTPFrontendConnector(endpoint, config),
}
fallback := func(ctx context.Context, req *quesma_api.Request, writer http.ResponseWriter) (*quesma_api.Result, error) {
fc.BasicHTTPFrontendConnector.GetRouterInstance().ElasticFallback(req.Decision, ctx, writer, req.OriginalRequest, []byte(req.Body), logManager, registry)
Expand All @@ -41,23 +35,8 @@ func NewElasticHttpIngestFrontendConnector(endpoint string,
return fc
}

func (h *ElasticHttpIngestFrontendConnector) GetChildComponents() []interface{} {
components := make([]interface{}, 0)
if h.BasicHTTPFrontendConnector != nil {
components = append(components, h.BasicHTTPFrontendConnector)
}

return components
}

func (h *ElasticHttpIngestFrontendConnector) SetDependencies(deps quesma_api.Dependencies) {
h.phoneHomeClient = deps.PhoneHomeAgent()
}

type ElasticHttpQueryFrontendConnector struct {
*frontend_connectors.BasicHTTPFrontendConnector

phoneHomeClient diag.PhoneHomeClient
*BasicHTTPFrontendConnector
}

func NewElasticHttpQueryFrontendConnector(endpoint string,
Expand All @@ -66,7 +45,7 @@ func NewElasticHttpQueryFrontendConnector(endpoint string,
config *config.QuesmaConfiguration, router quesma_api.Router) *ElasticHttpIngestFrontendConnector {

fc := &ElasticHttpIngestFrontendConnector{
BasicHTTPFrontendConnector: frontend_connectors.NewBasicHTTPFrontendConnector(endpoint, config),
BasicHTTPFrontendConnector: NewBasicHTTPFrontendConnector(endpoint, config),
}
fallback := func(ctx context.Context, req *quesma_api.Request, writer http.ResponseWriter) (*quesma_api.Result, error) {
fc.BasicHTTPFrontendConnector.GetRouterInstance().ElasticFallback(req.Decision, ctx, writer, req.OriginalRequest, []byte(req.Body), logManager, registry)
Expand All @@ -76,15 +55,3 @@ func NewElasticHttpQueryFrontendConnector(endpoint string,
fc.AddRouter(router)
return fc
}

func (h *ElasticHttpQueryFrontendConnector) GetChildComponents() []interface{} {
components := make([]interface{}, 0)
if h.BasicHTTPFrontendConnector != nil {
components = append(components, h.BasicHTTPFrontendConnector)
}
return components
}

func (h *ElasticHttpQueryFrontendConnector) SetDependencies(deps quesma_api.Dependencies) {
h.phoneHomeClient = deps.PhoneHomeAgent()
}
3 changes: 2 additions & 1 deletion quesma/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/gorilla/sessions v1.4.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jackc/pgx/v4 v4.18.3
github.com/jackc/pgx/v5 v5.7.1
github.com/jackc/pgx/v5 v5.7.2
github.com/k0kubun/pp v3.0.1+incompatible
github.com/knadh/koanf/parsers/json v0.1.0
github.com/knadh/koanf/parsers/yaml v0.1.0
Expand All @@ -40,6 +40,7 @@ require (

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/H0llyW00dzZ/cidr v1.2.1 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions quesma/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/ClickHouse/clickhouse-go/v2 v2.30.0 h1:AG4D/hW39qa58+JHQIFOSnxyL46H6h
github.com/ClickHouse/clickhouse-go/v2 v2.30.0/go.mod h1:i9ZQAojcayW3RsdCb3YR+n+wC2h65eJsZCscZ1Z1wyo=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/H0llyW00dzZ/cidr v1.2.1 h1:DfRHX+RqVVKZijQGO1aJSaWvN9Saan8sycK/4wrfY5g=
github.com/H0llyW00dzZ/cidr v1.2.1/go.mod h1:S+EgYkMandSAN27mGNG/CB3jeoXDAyalsvvVFpWdnXc=
github.com/DataDog/go-sqllexer v0.0.18 h1:ErBvoO7/srJLdA2ebwd+HPqD4g1kN++BP64A8qvmh9U=
github.com/DataDog/go-sqllexer v0.0.18/go.mod h1:KwkYhpFEVIq+BfobkTC1vfqm4gTi65skV/DpDBXtexc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
Expand Down Expand Up @@ -116,8 +118,8 @@ github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQ
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA=
github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw=
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
Expand Down
Loading

0 comments on commit 35e492c

Please sign in to comment.