From 07454ce64c2c6319f3b111d50d1738d5e6360845 Mon Sep 17 00:00:00 2001 From: B Date: Wed, 29 May 2024 03:30:28 +0200 Subject: [PATCH 1/5] added support for go 1.22 --- go.mod | 41 ++++++++++---------- go.sum | 117 ++++++++++++++++++++++++--------------------------------- 2 files changed, 71 insertions(+), 87 deletions(-) diff --git a/go.mod b/go.mod index ba32f3b..6512210 100644 --- a/go.mod +++ b/go.mod @@ -1,34 +1,37 @@ module github.com/quickwit-oss/quickwit-go -go 1.18 +go 1.21 + +toolchain go1.22.1 require ( - github.com/imroc/req/v3 v3.33.1 + github.com/imroc/req/v3 v3.43.6 github.com/jarcoal/httpmock v1.3.0 - github.com/stretchr/testify v1.5.1 + github.com/stretchr/testify v1.6.1 ) require ( + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect - github.com/golang/mock v1.6.0 // indirect - github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect + github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/klauspost/compress v1.17.7 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/onsi/ginkgo/v2 v2.2.0 // indirect + github.com/onsi/ginkgo/v2 v2.16.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/qtls-go1-18 v0.2.0 // indirect - github.com/quic-go/qtls-go1-19 v0.2.0 // indirect - github.com/quic-go/qtls-go1-20 v0.1.0 // indirect - github.com/quic-go/quic-go v0.32.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect - golang.org/x/mod v0.8.0 // indirect - golang.org/x/net v0.8.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect - golang.org/x/tools v0.6.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect + github.com/quic-go/quic-go v0.41.0 // indirect + github.com/refraction-networking/utls v1.6.3 // indirect + go.uber.org/mock v0.4.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/mod v0.16.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.19.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index b0ab9fd..0be21b9 100644 --- a/go.sum +++ b/go.sum @@ -1,96 +1,77 @@ -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q= +github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/imroc/req/v3 v3.33.1 h1:BZnyl+K0hXcJlZBHY2CqbPgmVc1pPJDzjn6aJfB6shI= -github.com/imroc/req/v3 v3.33.1/go.mod h1:cZ+7C3L/AYOr4tLGG16hZF90F1WzAdAdzt1xFSlizXY= +github.com/imroc/req/v3 v3.43.6 h1:DDbN6sIBfZliQXbtmhAhlPcCDxmx9awthbVKw29dAyQ= +github.com/imroc/req/v3 v3.43.6/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA= github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc= github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= +github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= +github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= -github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI= -github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= -github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= +github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM= +github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-18 v0.2.0 h1:5ViXqBZ90wpUcZS0ge79rf029yx0dYB0McyPJwqqj7U= -github.com/quic-go/qtls-go1-18 v0.2.0/go.mod h1:moGulGHK7o6O8lSPSZNoOwcLvJKJ85vVNc7oJFD65bc= -github.com/quic-go/qtls-go1-19 v0.2.0 h1:Cvn2WdhyViFUHoOqK52i51k4nDX8EwIh5VJiVM4nttk= -github.com/quic-go/qtls-go1-19 v0.2.0/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.1.0 h1:d1PK3ErFy9t7zxKsG3NXBJXZjp/kMLoIb3y/kV54oAI= -github.com/quic-go/qtls-go1-20 v0.1.0/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.32.0 h1:lY02md31s1JgPiiyfqJijpu/UX/Iun304FI3yUqX7tA= -github.com/quic-go/quic-go v0.32.0/go.mod h1:/fCsKANhQIeD5l76c2JFU+07gVE3KaA0FP+0zMWwfwo= +github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= +github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= +github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc= +github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= +golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 88de29798c92fdbb06cd6a2a193a257b96733f8f Mon Sep 17 00:00:00 2001 From: B Date: Wed, 29 May 2024 04:10:54 +0200 Subject: [PATCH 2/5] base of the rewrite --- client.go | 103 +++++++++++++++++++++++++++++++++++-------------- client_test.go | 73 ++++++++++++++++++++++++++++++++++- 2 files changed, 147 insertions(+), 29 deletions(-) diff --git a/client.go b/client.go index 65f50ff..0151c94 100644 --- a/client.go +++ b/client.go @@ -1,9 +1,12 @@ package quickwit import ( + "bytes" + "encoding/json" "fmt" - - "github.com/imroc/req/v3" + "io" + "net/http" + "strings" ) type ErrorMessage struct { @@ -16,30 +19,15 @@ func (msg *ErrorMessage) Error() string { } type QuickwitClient struct { - *req.Client + endpoint string + client *http.Client } // endpoint is the root url of the quickwit server. func NewQuickwitClient(endpoint string) *QuickwitClient { return &QuickwitClient{ - Client: req.C(). - SetBaseURL(endpoint). - SetCommonErrorResult(&ErrorMessage{}). - EnableDumpEachRequest(). - OnAfterResponse(func(client *req.Client, resp *req.Response) error { - if resp.Err != nil { // There is an underlying error, e.g. network error or unmarshal error. - return nil - } - if errMsg, ok := resp.ErrorResult().(*ErrorMessage); ok { - resp.Err = errMsg // Convert api error into go error - return nil - } - if !resp.IsSuccessState() { - // Neither a success response nor a error response, record details to help troubleshooting - resp.Err = fmt.Errorf("bad status: %s\nraw content:\n%s", resp.Status, resp.Dump()) - } - return nil - }), + endpoint: endpoint, + client: &http.Client{}, } } @@ -60,11 +48,70 @@ type SearchResponse struct { Aggregations interface{} `json:"aggregations,omitempty"` } -func (c *QuickwitClient) Search(indexId string, searchRequest SearchRequest) (searchResponse *SearchResponse, err error) { - _, err = c.R(). - SetPathParam("indexId", indexId). - SetBody(searchRequest). - SetSuccessResult(&searchResponse). - Post("/api/v1/{indexId}/search") - return +type IngestRequest struct { + Documents []interface{} +} + +type IngestResponse struct { + NumDocsForProcessing uint64 `json:"num_docs_for_processing"` +} + +func (c *QuickwitClient) SearchMultiIndex(indexIds []string, searchRequest SearchRequest) (*SearchResponse, error) { + return c.Search(strings.Join(indexIds, ","), searchRequest) +} + +func (c *QuickwitClient) Search(indexId string, searchRequest SearchRequest) (*SearchResponse, error) { + BinaryData, err := json.Marshal(searchRequest) + if err != nil { + return nil, err + } + post, err := c.client.Post(fmt.Sprintf("%s/api/v1/%s/search", c.endpoint, indexId), "application/json", bytes.NewReader(BinaryData)) + if err != nil { + return nil, err + } + defer post.Body.Close() + if post.StatusCode != http.StatusOK { + msg, err := io.ReadAll(post.Body) + if err != nil { + return nil, err + } + var errmsg ErrorMessage + err = json.Unmarshal(msg, &errmsg) + if err != nil { + return nil, fmt.Errorf("bad status:%d\n raw body: %s", post.StatusCode, msg) + } + return nil, &errmsg + } + return &SearchResponse{}, nil +} + +func (c *QuickwitClient) Ingest(indexId string, ingestRequest IngestRequest) (*IngestResponse, error) { + var postdata []byte + for _, doc := range ingestRequest.Documents { + docBytes, err := json.Marshal(doc) + if err != nil { + return nil, err + } + postdata = append(postdata, docBytes...) + postdata = append(postdata, '\n') + + } + post, err := c.client.Post(fmt.Sprintf("%s/api/v1/%s/ingest", c.endpoint, indexId), "application/json", bytes.NewReader(postdata)) + if err != nil { + return nil, err + } + defer post.Body.Close() + if post.StatusCode != http.StatusOK { + msg, err := io.ReadAll(post.Body) + if err != nil { + return nil, err + } + return nil, fmt.Errorf("bad status:%d\n raw body: %s", post.StatusCode, msg) + } + var ingestResponse IngestResponse + err = json.NewDecoder(post.Body).Decode(&ingestResponse) + if err != nil { + return nil, err + } + return &ingestResponse, nil } diff --git a/client_test.go b/client_test.go index 6da1fca..20a7c26 100644 --- a/client_test.go +++ b/client_test.go @@ -10,7 +10,7 @@ import ( func TestClient_Search(t *testing.T) { qClient := NewQuickwitClient("http://localhost:7280") - httpmock.ActivateNonDefault(qClient.GetClient()) + httpmock.ActivateNonDefault(qClient.client) httpmock.RegisterResponder("POST", "http://localhost:7280/api/v1/otel-logs-v0/search", func(request *http.Request) (*http.Response, error) { respBody := `{"hits": [], "num_hits": 0, "elapsed_time_micros": 100}` resp := httpmock.NewStringResponse(http.StatusOK, respBody) @@ -25,3 +25,74 @@ func TestClient_Search(t *testing.T) { require.Equal(t, uint64(0), searchResponse.NumHits) require.Equal(t, 0, len(searchResponse.Hits)) } + +func TestClient_ExpectedError(t *testing.T) { + qClient := NewQuickwitClient("http://localhost:7280") + httpmock.ActivateNonDefault(qClient.client) + httpmock.RegisterResponder("POST", "http://localhost:7280/api/v1/otel-logs-v0/search", func(request *http.Request) (*http.Response, error) { + respBody := `{"message":"test error"}` + resp := httpmock.NewStringResponse(http.StatusInternalServerError, respBody) + resp.Header.Set("Content-Type", "application/json; charset=utf-8") + return resp, nil + }) + _, err := qClient.Search("otel-logs-v0", SearchRequest{Query: "test"}) + require.Error(t, err) + require.Equal(t, "API Error: test error", err.Error()) +} + +func TestClient_UnExpectedError(t *testing.T) { + qClient := NewQuickwitClient("http://localhost:7280") + httpmock.ActivateNonDefault(qClient.client) + httpmock.RegisterResponder("POST", "http://localhost:7280/api/v1/otel-logs-v0/search", func(request *http.Request) (*http.Response, error) { + respBody := `test unexpected error` + resp := httpmock.NewStringResponse(http.StatusInternalServerError, respBody) + resp.Header.Set("Content-Type", "application/json; charset=utf-8") + return resp, nil + }) + _, err := qClient.Search("otel-logs-v0", SearchRequest{Query: "test"}) + require.Error(t, err) + require.Equal(t, "bad status:500\n raw body: test unexpected error", err.Error()) +} + +func TestClient_Ingest(t *testing.T) { + qClient := NewQuickwitClient("http://localhost:7280") + httpmock.ActivateNonDefault(qClient.client) + httpmock.RegisterResponder("POST", "http://localhost:7280/api/v1/otel-logs-v0/ingest", func(request *http.Request) (*http.Response, error) { + respBody := `{"num_docs_for_processing": 3}` + resp := httpmock.NewStringResponse(http.StatusOK, respBody) + resp.Header.Set("Content-Type", "application/json; charset=utf-8") + return resp, nil + }) + type dummy struct { + Url string `json:"url"` + Title string `json:"title"` + Body string `json:"body"` + } + + ingest := IngestRequest{ + Documents: []interface{}{ + dummy{ + Url: "https://en.wikipedia.org/wiki?id=1", + Title: "foo", + Body: "foo", + }, + dummy{ + Url: "https://en.wikipedia.org/wiki?id=2", + Title: "bar", + Body: "bar", + }, + dummy{ + Url: "https://en.wikipedia.org/wiki?id=3", + Title: "baz", + Body: "baz", + }, + }, + } + + ingestResponse, err := qClient.Ingest("otel-logs-v0", ingest) + if err != nil { + t.Error(err) + } + require.NoError(t, err) + require.Equal(t, uint64(3), ingestResponse.NumDocsForProcessing) +} From d8afa1d411f372fefd1a1d31be9327151e221aae Mon Sep 17 00:00:00 2001 From: B Date: Wed, 29 May 2024 04:11:06 +0200 Subject: [PATCH 3/5] base of the rewrite --- go.mod | 21 +-------------------- go.sum | 51 --------------------------------------------------- 2 files changed, 1 insertion(+), 71 deletions(-) diff --git a/go.mod b/go.mod index 6512210..b72a7d9 100644 --- a/go.mod +++ b/go.mod @@ -5,33 +5,14 @@ go 1.21 toolchain go1.22.1 require ( - github.com/imroc/req/v3 v3.43.6 github.com/jarcoal/httpmock v1.3.0 github.com/stretchr/testify v1.6.1 ) require ( - github.com/andybalholm/brotli v1.1.0 // indirect - github.com/cloudflare/circl v1.3.7 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect - github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/klauspost/compress v1.17.7 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/onsi/ginkgo/v2 v2.16.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/quic-go v0.41.0 // indirect - github.com/refraction-networking/utls v1.6.3 // indirect - go.uber.org/mock v0.4.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.19.0 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0be21b9..073c052 100644 --- a/go.sum +++ b/go.sum @@ -1,74 +1,23 @@ -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= -github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= -github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q= -github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/imroc/req/v3 v3.43.6 h1:DDbN6sIBfZliQXbtmhAhlPcCDxmx9awthbVKw29dAyQ= -github.com/imroc/req/v3 v3.43.6/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA= github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc= github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= -github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM= -github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= -github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= -github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= -github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k= -github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA= -github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc= -github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= -go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= -golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= -golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From f3c75491dbcb4eaf4697f26a96080de3c20a776a Mon Sep 17 00:00:00 2001 From: B Date: Wed, 29 May 2024 04:22:25 +0200 Subject: [PATCH 4/5] base of the rewrite --- client.go | 34 ++++++++++++++++++++++++++++++++++ client_test.go | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/client.go b/client.go index 0151c94..215d56d 100644 --- a/client.go +++ b/client.go @@ -48,6 +48,14 @@ type SearchResponse struct { Aggregations interface{} `json:"aggregations,omitempty"` } +type DeleteIndexResponse struct { + SplitId string `json:"split_id"` + NumDocs uint64 `json:"num_docs"` + UncompressedDocsSizeBytes uint64 `json:"uncompressed_docs_size_bytes"` + FileName string `json:"file_name"` + FileSizeBytes uint64 `json:"file_size_bytes"` +} + type IngestRequest struct { Documents []interface{} } @@ -115,3 +123,29 @@ func (c *QuickwitClient) Ingest(indexId string, ingestRequest IngestRequest) (*I } return &ingestResponse, nil } + +func (c *QuickwitClient) DeleteIndex(indexId string) (*[]DeleteIndexResponse, error) { + req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/api/v1/%s", c.endpoint, indexId), nil) + if err != nil { + return nil, err + } + do, err := c.client.Do(req) + if err != nil { + return nil, err + } + defer do.Body.Close() + if do.StatusCode != http.StatusOK { + msg, err := io.ReadAll(do.Body) + if err != nil { + return nil, err + } + return nil, fmt.Errorf("bad status:%d\n raw body: %s", do.StatusCode, msg) + } + var deleteIndexResponse []DeleteIndexResponse + err = json.NewDecoder(do.Body).Decode(&deleteIndexResponse) + if err != nil { + return nil, err + } + return &deleteIndexResponse, nil + +} diff --git a/client_test.go b/client_test.go index 20a7c26..f9791df 100644 --- a/client_test.go +++ b/client_test.go @@ -96,3 +96,22 @@ func TestClient_Ingest(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(3), ingestResponse.NumDocsForProcessing) } + +func TestClient_DeleteIndex(t *testing.T) { + qClient := NewQuickwitClient("http://localhost:7280") + httpmock.ActivateNonDefault(qClient.client) + httpmock.RegisterResponder("DELETE", "http://localhost:7280/api/v1/otel-logs-v0", func(request *http.Request) (*http.Response, error) { + respBody := `[ { "split_id": "01GK1XNAECH7P14850S9VV6P94", "num_docs": 1337, "uncompressed_docs_size_bytes": 23933408, "file_name": "01GK1XNAECH7P14850S9VV6P94.split", "file_size_bytes": 2991676 } ]` + resp := httpmock.NewStringResponse(http.StatusOK, respBody) + resp.Header.Set("Content-Type", "application/json; charset=utf-8") + return resp, nil + }) + deleteResponse, err := qClient.DeleteIndex("otel-logs-v0") + if err != nil { + t.Error(err) + } + require.NoError(t, err) + require.Equal(t, 1, len(*deleteResponse)) + require.Equal(t, "01GK1XNAECH7P14850S9VV6P94", (*deleteResponse)[0].SplitId) + require.Equal(t, uint64(1337), (*deleteResponse)[0].NumDocs) +} From aed88e96f074219d631db619896e575fbd629730 Mon Sep 17 00:00:00 2001 From: B Date: Wed, 29 May 2024 13:45:40 +0200 Subject: [PATCH 5/5] added index creation --- client.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/client.go b/client.go index 215d56d..28b02c8 100644 --- a/client.go +++ b/client.go @@ -48,6 +48,70 @@ type SearchResponse struct { Aggregations interface{} `json:"aggregations,omitempty"` } +type FieldMapping struct { + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + Fast bool `json:"fast,omitempty"` + InputFormat string `json:"input_format,omitempty"` + InputFormats []string `json:"input_formats,omitempty"` + FastPrecision string `json:"fast_precision,omitempty"` + Record string `json:"record,omitempty"` + Description string `json:"description,omitempty"` + Stored bool `json:"stored,omitempty"` + Indexed bool `json:"indexed,omitempty"` + Tokenizer string `json:"tokenizer,omitempty"` + Fieldnorms bool `json:"fieldnorms,omitempty"` + OutputFormat string `json:"output_format,omitempty"` +} + +type DocMapping struct { + FieldMappings []*FieldMapping `json:"field_mappings,omitempty"` + Mode string `json:"mode,omitempty"` + DynamicMapping interface{} `json:"dynamic_mapping,omitempty"` + TagFields []string `json:"tag_fields,omitempty"` + StoreSource bool `json:"store_source,omitempty"` + TimestampField string `json:"timestamp_field,omitempty"` + PartitionKey string `json:"partition_key,omitempty"` + MaxNumPartitions uint64 `json:"max_num_partitions,omitempty"` + IndexFieldPresence bool `json:"index_field_presence,omitempty"` +} +type MergePolicy struct { + Type string `json:"type,omitempty"` + MaxMergeOps uint64 `json:"max_merge_ops,omitempty"` + MergeFactor uint64 `json:"merge_factor,omitempty"` + MaxMergeFactor uint64 `json:"max_merge_factor,omitempty"` +} +type Resources struct { + HeapSize string `json:"heap_size,omitempty"` + MaxMergeWriteThroughput uint64 `json:"max_merge_write_throughput,omitempty"` +} +type IndexSettings struct { + CommitTimeoutSecs uint64 `json:"commit_timeout_secs,omitempty"` + SplitNumDocsTarget uint64 `json:"split_num_docs_target,omitempty"` + MergePolicy *MergePolicy `json:"merge_policy,omitempty"` + Resources *Resources `json:"resources,omitempty"` + DocstoreCompressionLevel uint64 `json:"docstore_compression_level,omitempty"` + DocstoreBlocksize uint64 `json:"docstore_blocksize,omitempty"` +} +type SearchSettings struct { + DefaultSearchFields []string `json:"default_search_fields,omitempty"` +} + +type Retention struct { + Period string `json:"period,omitempty"` + Schedule string `json:"schedule,omitempty"` +} + +type CreateIndexRequest struct { + Version string `json:"version,omitempty"` + IndexId string `json:"index_id,omitempty"` + IndexUri string `json:"index_uri,omitempty"` + DocMapping *DocMapping `json:"doc_mapping,omitempty"` + IndexingSettings *IndexSettings `json:"indexing_settings,omitempty"` + SearchSettings *SearchSettings `json:"search_settings,omitempty"` + Retention *Retention `json:"retention,omitempty"` +} + type DeleteIndexResponse struct { SplitId string `json:"split_id"` NumDocs uint64 `json:"num_docs"` @@ -149,3 +213,28 @@ func (c *QuickwitClient) DeleteIndex(indexId string) (*[]DeleteIndexResponse, er return &deleteIndexResponse, nil } + +func (c *QuickwitClient) CreateIndex(createIndexRequest CreateIndexRequest) error { + BinaryData, err := json.Marshal(createIndexRequest) + if err != nil { + return err + } + post, err := c.client.Post(fmt.Sprintf("%s/api/v1/indexes", c.endpoint), "application/json", bytes.NewReader(BinaryData)) + if err != nil { + return err + } + defer post.Body.Close() + if post.StatusCode != http.StatusOK { + msg, err := io.ReadAll(post.Body) + if err != nil { + return err + } + var errmsg ErrorMessage + err = json.Unmarshal(msg, &errmsg) + if err != nil { + return fmt.Errorf("bad status:%d\n raw body: %s", post.StatusCode, msg) + } + return &errmsg + } + return nil +}