From 101934dc274ee8f6e29c48a72dd6d8aeab437086 Mon Sep 17 00:00:00 2001 From: Matt Devy <32791943+MattDevy@users.noreply.github.com> Date: Wed, 26 Nov 2025 13:06:31 +0000 Subject: [PATCH] feat: add Close method to BaseClient (#1056) (cherry picked from commit 9d9d1911ef368906e09dd872ae641620eb9d3d53) --- .doc/typedapi/esql.asciidoc | 8 + Makefile | 14 +- _benchmarks/benchmarks/go.mod | 2 +- _examples/bulk/benchmarks/go.mod | 4 +- _examples/bulk/benchmarks/go.sum | 8 +- _examples/bulk/default.go | 8 + _examples/bulk/go.mod | 2 +- _examples/bulk/go.sum | 4 +- _examples/bulk/kafka/go.mod | 2 +- _examples/bulk/kafka/go.sum | 4 +- _examples/cloudfunction/go.mod | 2 +- _examples/cloudfunction/go.sum | 4 +- _examples/encoding/easyjson.go | 8 + _examples/encoding/gjson.go | 9 + _examples/encoding/go.mod | 2 +- _examples/encoding/go.sum | 4 +- _examples/encoding/jsonreader.go | 10 ++ _examples/extension/go.mod | 2 +- _examples/extension/go.sum | 4 +- _examples/extension/main.go | 9 + _examples/fasthttp/cmd/main.go | 8 + _examples/fasthttp/go.mod | 2 +- _examples/fasthttp/go.sum | 10 +- _examples/go.mod | 2 +- _examples/go.sum | 4 +- _examples/instrumentation/go.mod | 2 +- _examples/instrumentation/go.sum | 39 +---- _examples/instrumentation/opencensus.go | 7 + _examples/logging/custom.go | 8 + _examples/logging/default.go | 6 + _examples/logging/go.mod | 2 +- _examples/logging/go.sum | 8 +- _examples/main.go | 9 +- _examples/security/go.mod | 2 +- _examples/security/go.sum | 4 +- _examples/security/tls_configure_ca.go | 9 + _examples/security/tls_with_ca.go | 9 + .../xkcdsearch/cmd/xkcd/commands/index.go | 8 + .../xkcdsearch/cmd/xkcd/commands/search.go | 9 + .../xkcdsearch/cmd/xkcd/commands/server.go | 10 +- _examples/xkcdsearch/go.mod | 2 +- _examples/xkcdsearch/go.sum | 8 +- doc.go | 46 ++--- elasticsearch.go | 59 ++++++- elasticsearch_internal_test.go | 161 +++++++++++++++++- esapi/esapi.request.go | 2 - esapi/esapi.response.go | 6 - esutil/bulk_indexer.go | 1 + esutil/bulk_indexer_benchmark_test.go | 3 + esutil/bulk_indexer_example_test.go | 7 + esutil/doc.go | 1 - esutil/json_reader.go | 5 - go.mod | 2 +- go.sum | 4 +- .../e2e/bulk_indexer_integration_test.go | 4 + .../e2e/elasticsearch_integration_test.go | 53 +++++- .../testing/e2e/esapi_integration_test.go | 15 ++ .../e2e/json_reader_integration_test.go | 12 +- internal/testing/go.mod | 2 +- internal/testing/go.sum | 4 +- 60 files changed, 508 insertions(+), 157 deletions(-) diff --git a/.doc/typedapi/esql.asciidoc b/.doc/typedapi/esql.asciidoc index c7c2700c1b..e85c2654d4 100644 --- a/.doc/typedapi/esql.asciidoc +++ b/.doc/typedapi/esql.asciidoc @@ -77,6 +77,7 @@ import ( "context" "fmt" "log" + "time" "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/typedapi/esql/query" @@ -94,6 +95,13 @@ func main() { if err != nil { log.Fatal(err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + if err := client.Close(ctx); err != nil { + log.Fatal(err) + } + } () queryAuthor := `from library | where author == "Isaac Asimov" diff --git a/Makefile b/Makefile index 4e4633f504..5996e207f0 100644 --- a/Makefile +++ b/Makefile @@ -127,19 +127,7 @@ test-examples: ## Execute the _examples false; \ ); \ done; \ - );\ -# \ -# for f in _examples/*/; do \ -# printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \ -# printf "\033[1m$$f\033[0m\n"; \ -# printf "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \ -# (cd $$f && make test && true) || \ -# ( \ -# printf "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \ -# printf "\033[31;1m⨯ ERROR\033[0m\n"; \ -# false; \ -# ); \ -# done; \ + ); \ printf "\033[32m────────────────────────────────────────────────────────────────────────────────\033[0m\n"; \ \ printf "\033[32;1mSUCCESS\033[0m\n"; \ diff --git a/_benchmarks/benchmarks/go.mod b/_benchmarks/benchmarks/go.mod index a72bf139d4..29115c24ef 100644 --- a/_benchmarks/benchmarks/go.mod +++ b/_benchmarks/benchmarks/go.mod @@ -7,7 +7,7 @@ toolchain go1.24.1 replace github.com/elastic/go-elasticsearch/v8 => ../../ require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 github.com/elastic/go-elasticsearch/v8 v8.0.0-20200408073057-6f36a473b19f github.com/fatih/color v1.7.0 github.com/montanaflynn/stats v0.6.3 diff --git a/_examples/bulk/benchmarks/go.mod b/_examples/bulk/benchmarks/go.mod index 434ff4c9d9..86f51181fb 100644 --- a/_examples/bulk/benchmarks/go.mod +++ b/_examples/bulk/benchmarks/go.mod @@ -9,13 +9,11 @@ replace github.com/elastic/go-elasticsearch/v8 => ../../.. require ( github.com/dustin/go-humanize v1.0.0 github.com/elastic/go-elasticsearch/v8 v8.0.0-20210817150010-57d659deaca7 - github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e - github.com/mailru/easyjson v0.7.1 github.com/montanaflynn/stats v0.6.3 ) require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect diff --git a/_examples/bulk/benchmarks/go.sum b/_examples/bulk/benchmarks/go.sum index 0f36e2a371..af14f9f2e0 100644 --- a/_examples/bulk/benchmarks/go.sum +++ b/_examples/bulk/benchmarks/go.sum @@ -2,10 +2,8 @@ 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/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= -github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e h1:03JFpKZ9QocRhW3CdOJxxQBAZJxlXQEXVf7Fo4mcQPE= -github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e/go.mod h1:2PB5YQPpY5tWbF65MRqzEXA31PZOdXCkloQSOZtU14I= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -13,8 +11,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8= -github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/montanaflynn/stats v0.6.3 h1:F8446DrvIF5V5smZfZ8K9nrmmix0AFgevPdLruGOmzk= github.com/montanaflynn/stats v0.6.3/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/_examples/bulk/default.go b/_examples/bulk/default.go index 5a285a8111..41896d61c6 100644 --- a/_examples/bulk/default.go +++ b/_examples/bulk/default.go @@ -33,6 +33,7 @@ package main import ( "bytes" + "context" "encoding/json" "flag" "fmt" @@ -125,6 +126,13 @@ func main() { if err != nil { log.Fatalf("Error creating the client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s", err) + } + }() // Generate the articles collection // diff --git a/_examples/bulk/go.mod b/_examples/bulk/go.mod index 001cf776fc..805a99be89 100644 --- a/_examples/bulk/go.mod +++ b/_examples/bulk/go.mod @@ -13,7 +13,7 @@ require ( ) require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/otel v1.28.0 // indirect diff --git a/_examples/bulk/go.sum b/_examples/bulk/go.sum index 1d8600a20d..fd52f985f2 100644 --- a/_examples/bulk/go.sum +++ b/_examples/bulk/go.sum @@ -4,8 +4,8 @@ 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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/_examples/bulk/kafka/go.mod b/_examples/bulk/kafka/go.mod index 23d171ca8b..24f275c7f9 100644 --- a/_examples/bulk/kafka/go.mod +++ b/_examples/bulk/kafka/go.mod @@ -14,7 +14,7 @@ require ( require ( github.com/armon/go-radix v1.0.0 // indirect - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/elastic/go-licenser v0.3.1 // indirect github.com/elastic/go-sysinfo v1.1.1 // indirect github.com/elastic/go-windows v1.0.0 // indirect diff --git a/_examples/bulk/kafka/go.sum b/_examples/bulk/kafka/go.sum index 0b53ec3c4b..5e7aae6c05 100644 --- a/_examples/bulk/kafka/go.sum +++ b/_examples/bulk/kafka/go.sum @@ -5,8 +5,8 @@ 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/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/elastic/go-licenser v0.3.1 h1:RmRukU/JUmts+rpexAw0Fvt2ly7VVu6mw8z4HrEzObU= github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ= github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI= diff --git a/_examples/cloudfunction/go.mod b/_examples/cloudfunction/go.mod index 8eb5d0e7bb..cb4d61fa9c 100644 --- a/_examples/cloudfunction/go.mod +++ b/_examples/cloudfunction/go.mod @@ -9,7 +9,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../.. require github.com/elastic/go-elasticsearch/v8 v8.0.0-20210817150010-57d659deaca7 require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/otel v1.28.0 // indirect diff --git a/_examples/cloudfunction/go.sum b/_examples/cloudfunction/go.sum index 9df41c3fc3..8c76c70289 100644 --- a/_examples/cloudfunction/go.sum +++ b/_examples/cloudfunction/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/_examples/encoding/easyjson.go b/_examples/encoding/easyjson.go index a98904b99c..ab1c76f9dc 100644 --- a/_examples/encoding/easyjson.go +++ b/_examples/encoding/easyjson.go @@ -19,6 +19,7 @@ package main import ( "bytes" + "context" "fmt" "math/rand" "os" @@ -56,6 +57,13 @@ func main() { fmt.Printf("Error creating the client: %s\n", err) os.Exit(2) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Printf("Error closing the client: %s\n", err) + } + }() fnames = []string{"Alice", "John", "Mary"} diff --git a/_examples/encoding/gjson.go b/_examples/encoding/gjson.go index 6e3d648a3e..a3a9bbb778 100644 --- a/_examples/encoding/gjson.go +++ b/_examples/encoding/gjson.go @@ -19,10 +19,12 @@ package main import ( "bytes" + "context" "fmt" "io" "log" "strings" + "time" "github.com/elastic/go-elasticsearch/v8" "github.com/fatih/color" @@ -43,6 +45,13 @@ func main() { if err != nil { log.Fatalf("Error creating client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Printf("Error closing the client: %s\n", err) + } + }() res, err := es.Cluster.Stats(es.Cluster.Stats.WithHuman()) if err != nil { diff --git a/_examples/encoding/go.mod b/_examples/encoding/go.mod index 62cf2b5b42..e90efa5249 100644 --- a/_examples/encoding/go.mod +++ b/_examples/encoding/go.mod @@ -14,7 +14,7 @@ require ( ) require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/josharian/intern v1.0.0 // indirect diff --git a/_examples/encoding/go.sum b/_examples/encoding/go.sum index e1321e7470..c27a08c34a 100644 --- a/_examples/encoding/go.sum +++ b/_examples/encoding/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= diff --git a/_examples/encoding/jsonreader.go b/_examples/encoding/jsonreader.go index dc24c6c682..261ecb514b 100644 --- a/_examples/encoding/jsonreader.go +++ b/_examples/encoding/jsonreader.go @@ -18,7 +18,10 @@ package main import ( + "context" + "fmt" "log" + "time" "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" @@ -39,6 +42,13 @@ func main() { if err != nil { log.Fatalf("Error creating the client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Printf("Error closing the client: %s\n", err) + } + }() doc := struct { Title string `json:"title"` diff --git a/_examples/extension/go.mod b/_examples/extension/go.mod index 9e173ae89d..8764167246 100644 --- a/_examples/extension/go.mod +++ b/_examples/extension/go.mod @@ -7,7 +7,7 @@ toolchain go1.24.2 replace github.com/elastic/go-elasticsearch/v8 => ../.. require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000 github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e ) diff --git a/_examples/extension/go.sum b/_examples/extension/go.sum index 68166cae13..62ebdc8622 100644 --- a/_examples/extension/go.sum +++ b/_examples/extension/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e h1:03JFpKZ9QocRhW3CdOJxxQBAZJxlXQEXVf7Fo4mcQPE= github.com/elastic/go-elasticsearch/v9 v9.0.0-20250416133943-b5adae5afb7e/go.mod h1:2PB5YQPpY5tWbF65MRqzEXA31PZOdXCkloQSOZtU14I= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= diff --git a/_examples/extension/main.go b/_examples/extension/main.go index a49c804050..af4171fd47 100644 --- a/_examples/extension/main.go +++ b/_examples/extension/main.go @@ -23,6 +23,7 @@ package main import ( + "context" "io" "log" "net" @@ -30,6 +31,7 @@ import ( "net/http/httputil" "net/url" "os" + "time" "github.com/elastic/elastic-transport-go/v8/elastictransport" "github.com/elastic/go-elasticsearch/v8" @@ -80,6 +82,13 @@ func main() { if err != nil { log.Fatalf("Error creating the client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := esclient.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s\n", err) + } + }() es := ExtendedClient{Client: esclient, Custom: &ExtendedAPI{esclient}} <-started diff --git a/_examples/fasthttp/cmd/main.go b/_examples/fasthttp/cmd/main.go index d359b9a57a..9d7c2aa93a 100644 --- a/_examples/fasthttp/cmd/main.go +++ b/_examples/fasthttp/cmd/main.go @@ -19,6 +19,7 @@ package main import ( "context" + "fmt" "log" "os" "sort" @@ -56,6 +57,13 @@ func main() { if err != nil { log.Fatalf("Error creating the client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Printf("Error closing the client: %s\n", err) + } + }() // Test sending the body as POST // diff --git a/_examples/fasthttp/go.mod b/_examples/fasthttp/go.mod index c00431bcaf..28031efd45 100644 --- a/_examples/fasthttp/go.mod +++ b/_examples/fasthttp/go.mod @@ -13,7 +13,7 @@ require ( require ( github.com/andybalholm/brotli v1.0.4 // indirect - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/klauspost/compress v1.15.0 // indirect diff --git a/_examples/fasthttp/go.sum b/_examples/fasthttp/go.sum index 14139827df..18efdb6299 100644 --- a/_examples/fasthttp/go.sum +++ b/_examples/fasthttp/go.sum @@ -2,8 +2,8 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -21,7 +21,6 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.34.0 h1:d3AAQJ2DRcxJYHm7OXNXtXt2as1vMDfxeIcFvhmGGm4= github.com/valyala/fasthttp v1.34.0/go.mod h1:epZA5N+7pY6ZaEKRmstzOuYJx9HI8DI1oaCGZpdH4h0= -github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= @@ -31,10 +30,8 @@ go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZ go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= -golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -44,12 +41,9 @@ golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/_examples/go.mod b/_examples/go.mod index 85fd18a8c3..9059758da5 100644 --- a/_examples/go.mod +++ b/_examples/go.mod @@ -9,7 +9,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../ require github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000 require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/otel v1.28.0 // indirect diff --git a/_examples/go.sum b/_examples/go.sum index 9df41c3fc3..8c76c70289 100644 --- a/_examples/go.sum +++ b/_examples/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/_examples/instrumentation/go.mod b/_examples/instrumentation/go.mod index 3eb348255e..6241a1130f 100644 --- a/_examples/instrumentation/go.mod +++ b/_examples/instrumentation/go.mod @@ -7,7 +7,7 @@ toolchain go1.21.0 replace github.com/elastic/go-elasticsearch/v8 => ../.. require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 github.com/elastic/go-elasticsearch/v8 v8.0.0-20191002063538-b491ce54d752 github.com/fatih/color v1.7.0 go.elastic.co/apm v1.11.0 diff --git a/_examples/instrumentation/go.sum b/_examples/instrumentation/go.sum index 916884666f..d2371ba4f9 100644 --- a/_examples/instrumentation/go.sum +++ b/_examples/instrumentation/go.sum @@ -1,21 +1,17 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.apache.org/thrift.git v0.0.0-20181218151757-9b75e4fe745a h1:GnKpWvJXysBGdcWMEibN//UeRRJeLDUgsXjKXjagFLg= git.apache.org/thrift.git v0.0.0-20181218151757-9b75e4fe745a/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cucumber/godog v0.8.1 h1:lVb+X41I4YDreE+ibZ50bdXmySxgRviYFgKY6Aw4XE8= github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA= 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/elastic/go-sysinfo v1.0.1/go.mod h1:O/D5m1VpYLwGjCYzEt63g3Z1uO3jXfwyzzjiW90t8cY= github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI= github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0= @@ -23,60 +19,44 @@ github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7 github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 h1:2hRPrmiwPrp3fQX967rNJIhQPtiGXdlQWAxKbKw3VHA= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 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/grpc-ecosystem/grpc-gateway v1.6.2 h1:8KyC64BiO8ndiGHY5DlFWWdangUPC9QHPakFRre/Ud0= github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= -github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/openzipkin/zipkin-go v0.1.3 h1:36hTtUTQR/vPX7YVJo2PYexSbHdAJiAkDrjuXw/YlYQ= github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 h1:z6tvbDJ5OLJ48FFmnksv04a78maSTRBUIhkdHYV5Y98= github.com/prometheus/common v0.0.0-20181218105931-67670fe90761/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -84,13 +64,11 @@ github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURm github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.1.27 h1:nqDD4MMMQA0lmWq03Z2/myGPYLQoXtmi0rGVs95ntbo= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.elastic.co/apm v1.5.0/go.mod h1:OdB9sPtM6Vt7oz3VXt7+KR96i9li74qrxBGHTQygFvk= go.elastic.co/apm v1.11.0 h1:uJyt6nCW9880sZhfl1tB//Jy/5TadNoAd8edRUtgb3w= @@ -118,9 +96,7 @@ golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 h1:rJm0LuqUjoDhSk2zO9ISMSToQxGz7Os2jRiOL8AWu4c= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -134,13 +110,11 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -162,33 +136,24 @@ golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/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.0.0-20200509030707-2212a7e161a5 h1:MeC2gMlMdkd67dn17MEby3rGXRxZtWeiRXOnISfTQ74= golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 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-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.0.0-20181220000619-583d854617af h1:iQMS7JKv/0w/iiWf1M49Cg3dmOkBoBZT5KheqPDpaac= google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb h1:dQshZyyJ5W/Xk8myF4GKBak1pZW6EywJuQ8+44EQhGA= google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= 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= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3 h1:LyX67rVB0kBUFoROrQfzKwdrYLH1cRzHibxdJW85J1c= honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= diff --git a/_examples/instrumentation/opencensus.go b/_examples/instrumentation/opencensus.go index bddad490cc..fecbe6e642 100644 --- a/_examples/instrumentation/opencensus.go +++ b/_examples/instrumentation/opencensus.go @@ -141,6 +141,13 @@ func main() { if err != nil { log.Fatalf("ERROR: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Printf("Error closing the client: %s\n", err) + } + }() // Set up the "done" channel // diff --git a/_examples/logging/custom.go b/_examples/logging/custom.go index 898ae4d750..272278e362 100644 --- a/_examples/logging/custom.go +++ b/_examples/logging/custom.go @@ -24,6 +24,7 @@ package main import ( + "context" "io" "io/ioutil" "net/http" @@ -116,6 +117,13 @@ func main() { es, _ := elasticsearch.NewClient(elasticsearch.Config{ Logger: &CustomLogger{log}, }) + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatal().Err(err).Msg("Error closing the client") + } + }() // ---------------------------------------------------------------------------------------------- { diff --git a/_examples/logging/default.go b/_examples/logging/default.go index b0e11fc52d..6d08dfaec5 100644 --- a/_examples/logging/default.go +++ b/_examples/logging/default.go @@ -27,6 +27,7 @@ package main import ( + "context" "fmt" "log" "os" @@ -49,6 +50,7 @@ func main() { Logger: &elastictransport.TextLogger{Output: os.Stdout}, }) run(es, "Text") + _ = es.Close(context.Background()) // ============================================================================================== // @@ -58,6 +60,7 @@ func main() { Logger: &elastictransport.ColorLogger{Output: os.Stdout}, }) run(es, "Color") + _ = es.Close(context.Background()) // ============================================================================================== // @@ -71,6 +74,7 @@ func main() { }, }) run(es, "Request/Response Body") + _ = es.Close(context.Background()) // ============================================================================================== // @@ -81,6 +85,7 @@ func main() { Logger: &elastictransport.CurlLogger{Output: os.Stdout, EnableRequestBody: true, EnableResponseBody: true}, }) run(es, "Curl") + _ = es.Close(context.Background()) // ============================================================================================== // @@ -90,6 +95,7 @@ func main() { Logger: &elastictransport.JSONLogger{Output: os.Stdout}, }) run(es, "JSON") + _ = es.Close(context.Background()) } // ------------------------------------------------------------------------------------------------ diff --git a/_examples/logging/go.mod b/_examples/logging/go.mod index 8b4d5c3024..227df4420b 100644 --- a/_examples/logging/go.mod +++ b/_examples/logging/go.mod @@ -7,7 +7,7 @@ toolchain go1.21.0 replace github.com/elastic/go-elasticsearch/v8 => ../.. require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000 github.com/rs/zerolog v1.32.0 ) diff --git a/_examples/logging/go.sum b/_examples/logging/go.sum index ccd957a385..2d234e63e7 100644 --- a/_examples/logging/go.sum +++ b/_examples/logging/go.sum @@ -1,15 +1,13 @@ -github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -18,11 +16,9 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= diff --git a/_examples/main.go b/_examples/main.go index 5503202de2..b00d180b70 100644 --- a/_examples/main.go +++ b/_examples/main.go @@ -33,6 +33,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" @@ -54,7 +55,13 @@ func main() { if err != nil { log.Fatalf("Error creating the client: %s", err) } - + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s\n", err) + } + }() // 1. Get cluster info // res, err := es.Info() diff --git a/_examples/security/go.mod b/_examples/security/go.mod index 3984b7fc86..daf1866022 100644 --- a/_examples/security/go.mod +++ b/_examples/security/go.mod @@ -9,7 +9,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../.. require github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000 require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/otel v1.28.0 // indirect diff --git a/_examples/security/go.sum b/_examples/security/go.sum index 9df41c3fc3..8c76c70289 100644 --- a/_examples/security/go.sum +++ b/_examples/security/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/_examples/security/tls_configure_ca.go b/_examples/security/tls_configure_ca.go index 78d7722b93..0164d2dc5f 100644 --- a/_examples/security/tls_configure_ca.go +++ b/_examples/security/tls_configure_ca.go @@ -21,11 +21,13 @@ package main import ( + "context" "crypto/x509" "flag" "io/ioutil" "log" "net/http" + "time" "github.com/elastic/go-elasticsearch/v8" ) @@ -78,6 +80,13 @@ func main() { if err != nil { log.Fatalf("ERROR: Unable to create client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s\n", err) + } + }() res, err := es.Info() if err != nil { diff --git a/_examples/security/tls_with_ca.go b/_examples/security/tls_with_ca.go index 2abca15c2e..680ef42eea 100644 --- a/_examples/security/tls_with_ca.go +++ b/_examples/security/tls_with_ca.go @@ -21,9 +21,11 @@ package main import ( + "context" "flag" "io/ioutil" "log" + "time" "github.com/elastic/go-elasticsearch/v8" ) @@ -61,6 +63,13 @@ func main() { if err != nil { log.Fatalf("ERROR: Unable to create client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s\n", err) + } + }() res, err := es.Info() if err != nil { diff --git a/_examples/xkcdsearch/cmd/xkcd/commands/index.go b/_examples/xkcdsearch/cmd/xkcd/commands/index.go index 6c67b4ed95..c3122ce30e 100644 --- a/_examples/xkcdsearch/cmd/xkcd/commands/index.go +++ b/_examples/xkcdsearch/cmd/xkcd/commands/index.go @@ -18,6 +18,7 @@ package commands import ( + "context" "encoding/json" "fmt" "math/rand" @@ -82,6 +83,13 @@ var indexCmd = &cobra.Command{ if err != nil { crawler.log.Fatal().Err(err).Msg("Error creating Elasticsearch client") } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + crawler.log.Fatal().Err(err).Msg("Error closing the client") + } + }() config := xkcdsearch.StoreConfig{Client: es, IndexName: IndexName} store, err := xkcdsearch.NewStore(config) diff --git a/_examples/xkcdsearch/cmd/xkcd/commands/search.go b/_examples/xkcdsearch/cmd/xkcd/commands/search.go index b35effc408..97a662da66 100644 --- a/_examples/xkcdsearch/cmd/xkcd/commands/search.go +++ b/_examples/xkcdsearch/cmd/xkcd/commands/search.go @@ -18,11 +18,13 @@ package commands import ( + "context" "fmt" "io" "os" "regexp" "strings" + "time" "github.com/spf13/cobra" @@ -48,6 +50,13 @@ var searchCmd = &cobra.Command{ if err != nil { fmt.Fprintf(os.Stderr, "\x1b[1;107;41mERROR: %s\x1b[0m\n", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + fmt.Fprintf(os.Stderr, "Error closing the client: %s\n", err) + } + }() config := xkcdsearch.StoreConfig{Client: es, IndexName: IndexName} store, err := xkcdsearch.NewStore(config) diff --git a/_examples/xkcdsearch/cmd/xkcd/commands/server.go b/_examples/xkcdsearch/cmd/xkcd/commands/server.go index 90a4bb1aca..0823288dcc 100644 --- a/_examples/xkcdsearch/cmd/xkcd/commands/server.go +++ b/_examples/xkcdsearch/cmd/xkcd/commands/server.go @@ -18,8 +18,10 @@ package commands import ( + "context" "net/http" "os" + "time" "github.com/rs/zerolog" "github.com/spf13/cobra" @@ -62,7 +64,13 @@ var serverCmd = &cobra.Command{ if err != nil { log.Fatal().Err(err).Msg("Error creating Elasticsearch client") } - + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatal().Err(err).Msg("Error closing the client") + } + }() config := xkcdsearch.StoreConfig{Client: es, IndexName: IndexName} store, err := xkcdsearch.NewStore(config) if err != nil { diff --git a/_examples/xkcdsearch/go.mod b/_examples/xkcdsearch/go.mod index da47234f88..5e69a9b153 100644 --- a/_examples/xkcdsearch/go.mod +++ b/_examples/xkcdsearch/go.mod @@ -14,7 +14,7 @@ require ( ) require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect + github.com/elastic/elastic-transport-go/v8 v8.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect diff --git a/_examples/xkcdsearch/go.sum b/_examples/xkcdsearch/go.sum index 2f7ef238bc..fa46ac7627 100644 --- a/_examples/xkcdsearch/go.sum +++ b/_examples/xkcdsearch/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -31,13 +31,9 @@ go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+ go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/doc.go b/doc.go index 59a77ba7e4..801becc759 100644 --- a/doc.go +++ b/doc.go @@ -20,31 +20,31 @@ Package elasticsearch provides a Go client for Elasticsearch. Create the client with the NewDefaultClient function: - elasticsearch.NewDefaultClient() + elasticsearch.NewDefaultClient() The ELASTICSEARCH_URL environment variable is used instead of the default URL, when set. Use a comma to separate multiple URLs. To configure the client, pass a Config object to the NewClient function: - cfg := elasticsearch.Config{ - Addresses: []string{ - "http://localhost:9200", - "http://localhost:9201", - }, - Username: "foo", - Password: "bar", - Transport: &http.Transport{ - MaxIdleConnsPerHost: 10, - ResponseHeaderTimeout: time.Second, - DialContext: (&net.Dialer{Timeout: time.Second}).DialContext, - TLSClientConfig: &tls.Config{ - MinVersion: tls.VersionTLS12, - }, - }, - } + cfg := elasticsearch.Config{ + Addresses: []string{ + "http://localhost:9200", + "http://localhost:9201", + }, + Username: "foo", + Password: "bar", + Transport: &http.Transport{ + MaxIdleConnsPerHost: 10, + ResponseHeaderTimeout: time.Second, + DialContext: (&net.Dialer{Timeout: time.Second}).DialContext, + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + }, + }, + } - elasticsearch.NewClient(cfg) + elasticsearch.NewClient(cfg) When using the Elastic Service (https://elastic.co/cloud), you can use CloudID instead of Addresses. When either Addresses or CloudID is set, the ELASTICSEARCH_URL environment variable is ignored. @@ -53,12 +53,12 @@ See the elasticsearch_integration_test.go file and the _examples folder for more Call the Elasticsearch APIs by invoking the corresponding methods on the client: - res, err := es.Info() - if err != nil { - log.Fatalf("Error getting response: %s", err) - } + res, err := es.Info() + if err != nil { + log.Fatalf("Error getting response: %s", err) + } - log.Println(res) + log.Println(res) See the github.com/elastic/go-elasticsearch/esapi package for more information about using the API. diff --git a/elasticsearch.go b/elasticsearch.go index e244e32e89..410fa66881 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -18,10 +18,10 @@ package elasticsearch import ( + "context" "encoding/base64" "errors" "fmt" - "go.opentelemetry.io/otel/trace" "net/http" "net/url" "os" @@ -30,8 +30,11 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" + "go.opentelemetry.io/otel/trace" + "github.com/elastic/go-elasticsearch/v8/typedapi" "github.com/elastic/go-elasticsearch/v8/esapi" @@ -62,6 +65,14 @@ var ( reMetaVersion = regexp.MustCompile("([0-9.]+)(.*)") ) +var ( + // ErrClosed is returned when the client is closed. + ErrClosed = errors.New("client is closed") + + // ErrAlreadyClosed is returned by the Close method when the client is already closed. + ErrAlreadyClosed = errors.New("client is already closed") +) + func init() { userAgent = initUserAgent() } @@ -140,6 +151,8 @@ type BaseClient struct { disableMetaHeader bool productCheckMu sync.RWMutex productCheckSuccess bool + + closeDone uint32 } // Client represents the Functional Options API. @@ -344,6 +357,10 @@ func newTransport(cfg Config) (*elastictransport.Client, error) { // Perform delegates to Transport to execute a request and return a response. func (c *BaseClient) Perform(req *http.Request) (*http.Response, error) { + if c.isClosed() { + return nil, ErrClosed + } + // Compatibility Header if c.compatibilityHeader { if req.Body != nil { @@ -434,12 +451,52 @@ func (c *BaseClient) Metrics() (elastictransport.Metrics, error) { // DiscoverNodes reloads the client connections by fetching information from the cluster. func (c *BaseClient) DiscoverNodes() error { + if c.isClosed() { + return ErrClosed + } if dt, ok := c.Transport.(elastictransport.Discoverable); ok { return dt.DiscoverNodes() } return errors.New("transport is missing method DiscoverNodes()") } +func (c *BaseClient) isClosed() bool { + return atomic.LoadUint32(&c.closeDone) != 0 +} + +// Close closes the client. If the underlying Transport is elastictransport.Closeable, it is closed as well. +// Close should only be called once. Later calls to Close will return ErrAlreadyClosed. +// Once closed, future calls to the client will return ErrClosed. +// Existing requests may continue to run but may return: +// - elastictransport.ErrClosed +// - errors.New("connection pool is closed") +func (c *BaseClient) Close(ctx context.Context) error { + if ctx == nil { + ctx = context.Background() + } + + if atomic.CompareAndSwapUint32(&c.closeDone, 0, 1) { + closeable, ok := c.Transport.(elastictransport.Closeable) + if ok { + transportClosed := make(chan error, 1) + go func() { + transportClosed <- closeable.Close(context.Background()) + }() + + select { + case err := <-transportClosed: + return err + case <-ctx.Done(): + return ctx.Err() + } + } + + return nil + } else { + return ErrAlreadyClosed + } +} + // addrsFromEnvironment returns a list of addresses by splitting // the ELASTICSEARCH_URL environment variable with comma, or an empty list. func addrsFromEnvironment() []string { diff --git a/elasticsearch_internal_test.go b/elasticsearch_internal_test.go index 952f1a0930..6691d177b7 100644 --- a/elasticsearch_internal_test.go +++ b/elasticsearch_internal_test.go @@ -27,8 +27,6 @@ import ( "crypto/x509" "encoding/base64" "errors" - "github.com/elastic/go-elasticsearch/v8/esapi" - "github.com/elastic/go-elasticsearch/v8/typedapi/types" "io" "io/ioutil" "net/http" @@ -40,6 +38,10 @@ import ( "strconv" "strings" "testing" + "time" + + "github.com/elastic/go-elasticsearch/v8/esapi" + "github.com/elastic/go-elasticsearch/v8/typedapi/types" "github.com/elastic/elastic-transport-go/v8/elastictransport" ) @@ -1265,5 +1267,160 @@ func TestInstrumentation(t *testing.T) { }) }) } +} + +func TestClose(t *testing.T) { + type closeable interface { + esapi.Transport + elastictransport.Closeable + } + + tests := []struct { + name string + c func() closeable + }{ + {name: "BaseClient", c: func() closeable { + c, _ := NewBaseClient(Config{Transport: &mockTransp{}}) + return c + }}, + {name: "Client", c: func() closeable { + c, _ := NewClient(Config{Transport: &mockTransp{}}) + return c + }}, + {name: "TypedClient", c: func() closeable { + c, _ := NewTypedClient(Config{Transport: &mockTransp{}}) + return c + }}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Run("close", func(t *testing.T) { + c := tt.c() + err := c.Close(context.Background()) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + }) + + t.Run("closed twice", func(t *testing.T) { + c := tt.c() + _ = c.Close(context.Background()) + err := c.Close(context.Background()) + if err != nil { + if !errors.Is(err, ErrAlreadyClosed) { + t.Errorf("unexpected error: %v", err) + } + } + }) + + t.Run("performing a request after close", func(t *testing.T) { + c := tt.c() + if err := c.Close(context.Background()); err != nil { + t.Fatalf("unexpected error: %v", err) + } + req, err := http.NewRequest(http.MethodGet, "http://localhost:9200", nil) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if _, err := c.Perform(req); err != nil { + if !errors.Is(err, ErrClosed) { + t.Fatalf("unexpected error: %v", err) + } + } else { + t.Fatal("expected error") + } + }) + + t.Run("transport close called", func(t *testing.T) { + c := tt.c() + transportCloseCalled := false + mockTransport := &mockESTransport{CloseFunc: func(ctx context.Context) error { + transportCloseCalled = true + return nil + }} + switch c := c.(type) { + case *BaseClient: + c.Transport = mockTransport + case *Client: + c.Transport = mockTransport + case *TypedClient: + c.Transport = mockTransport + } + + err := c.Close(context.Background()) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if !transportCloseCalled { + t.Fatal("transport close not called") + } + }) + + t.Run("close timed out, transport close unresponsive", func(t *testing.T) { + done := make(chan struct{}) + t.Cleanup(func() { close(done) }) + mockTransport := &mockESTransport{CloseFunc: func(ctx context.Context) error { + <-done + return nil + }} + c := tt.c() + switch c := c.(type) { + case *BaseClient: + c.Transport = mockTransport + case *Client: + c.Transport = mockTransport + case *TypedClient: + c.Transport = mockTransport + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) + defer cancel() + if err := c.Close(ctx); !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("unexpected error: %v", err) + } + }) + + t.Run("close timed out, transport close responsive", func(t *testing.T) { + mockTransport := &mockESTransport{CloseFunc: func(ctx context.Context) error { + <-ctx.Done() + return ctx.Err() + }} + c := tt.c() + switch c := c.(type) { + case *BaseClient: + c.Transport = mockTransport + case *Client: + c.Transport = mockTransport + case *TypedClient: + c.Transport = mockTransport + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) + defer cancel() + if err := c.Close(ctx); !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("unexpected error: %v", err) + } + }) + + }) + } +} +type mockESTransport struct { + PerformFunc func(*http.Request) (*http.Response, error) + CloseFunc func(context.Context) error +} + +func (m mockESTransport) Perform(req *http.Request) (*http.Response, error) { + if m.PerformFunc != nil { + return m.PerformFunc(req) + } + t := &mockTransp{} + return t.RoundTrip(req) +} + +func (m mockESTransport) Close(ctx context.Context) error { + if m.CloseFunc != nil { + return m.CloseFunc(ctx) + } + return nil } diff --git a/esapi/esapi.request.go b/esapi/esapi.request.go index 234983615e..8b43d8eca9 100644 --- a/esapi/esapi.request.go +++ b/esapi/esapi.request.go @@ -32,13 +32,11 @@ var ( ) // Request defines the API request. -// type Request interface { Do(ctx context.Context, transport Transport) (*Response, error) } // newRequest creates an HTTP request. -// func newRequest(method, path string, body io.Reader) (*http.Request, error) { return http.NewRequest(method, path, body) } diff --git a/esapi/esapi.response.go b/esapi/esapi.response.go index a657b5ee9e..b6991f1029 100644 --- a/esapi/esapi.response.go +++ b/esapi/esapi.response.go @@ -28,7 +28,6 @@ import ( ) // Response represents the API response. -// type Response struct { StatusCode int Header http.Header @@ -38,7 +37,6 @@ type Response struct { // String returns the response as a string. // // The intended usage is for testing or debugging only. -// func (r *Response) String() string { var ( out = new(bytes.Buffer) @@ -75,7 +73,6 @@ func (r *Response) String() string { } // Status returns the response status as a string. -// func (r *Response) Status() string { var b strings.Builder if r != nil { @@ -87,19 +84,16 @@ func (r *Response) Status() string { } // IsError returns true when the response status indicates failure. -// func (r *Response) IsError() bool { return r.StatusCode > 299 } // Warnings returns the deprecation warnings from response headers. -// func (r *Response) Warnings() []string { return r.Header["Warning"] } // HasWarnings returns true when the response headers contain deprecation warnings. -// func (r *Response) HasWarnings() bool { return len(r.Warnings()) > 0 } diff --git a/esutil/bulk_indexer.go b/esutil/bulk_indexer.go index fb5eeefe56..2158ba438c 100644 --- a/esutil/bulk_indexer.go +++ b/esutil/bulk_indexer.go @@ -343,6 +343,7 @@ func (bi *bulkIndexer) Add(ctx context.Context, item BulkIndexerItem) error { // Close stops the periodic flush, closes the indexer queue channel, // which triggers the workers to flush and stop. +// Note: it is the user's responsibility to call Close on the elasticsearch Client passed in to the BulkIndexerConfig. func (bi *bulkIndexer) Close(ctx context.Context) error { close(bi.queue) diff --git a/esutil/bulk_indexer_benchmark_test.go b/esutil/bulk_indexer_benchmark_test.go index 8ec356cedf..694306bafe 100644 --- a/esutil/bulk_indexer_benchmark_test.go +++ b/esutil/bulk_indexer_benchmark_test.go @@ -65,6 +65,9 @@ func BenchmarkBulkIndexer(b *testing.B) { b.ResetTimer() es, _ := elasticsearch.NewClient(elasticsearch.Config{Transport: &mockTransp{}}) + defer func() { + _ = es.Close(context.Background()) + }() bi, _ := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{ Client: es, FlushBytes: 1024, diff --git a/esutil/bulk_indexer_example_test.go b/esutil/bulk_indexer_example_test.go index 31e6209240..b6653de829 100644 --- a/esutil/bulk_indexer_example_test.go +++ b/esutil/bulk_indexer_example_test.go @@ -52,6 +52,13 @@ func ExampleNewBulkIndexer() { if err != nil { log.Fatalf("Error creating the client: %s", err) } + defer func() { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := es.Close(ctx); err != nil { + log.Fatalf("Error closing the client: %s", err) + } + }() // Create the indexer // diff --git a/esutil/doc.go b/esutil/doc.go index 494a019e85..b00cb0440c 100644 --- a/esutil/doc.go +++ b/esutil/doc.go @@ -17,6 +17,5 @@ /* Package esutil provides helper utilities to the Go client for Elasticsearch. - */ package esutil diff --git a/esutil/json_reader.go b/esutil/json_reader.go index 36673a4ca4..049b828800 100644 --- a/esutil/json_reader.go +++ b/esutil/json_reader.go @@ -24,20 +24,17 @@ import ( ) // NewJSONReader encodes v into JSON and returns it as an io.Reader. -// func NewJSONReader(v interface{}) io.Reader { return &JSONReader{val: v, buf: nil} } // JSONEncoder defines the interface for custom JSON encoders. -// type JSONEncoder interface { EncodeJSON(io.Writer) error } // JSONReader represents a reader which takes an interface value, // encodes it into JSON, and wraps it in an io.Reader. -// type JSONReader struct { val interface{} buf interface { @@ -47,7 +44,6 @@ type JSONReader struct { } // Read implements the io.Reader interface. -// func (r *JSONReader) Read(p []byte) (int, error) { if r.buf == nil { r.buf = new(bytes.Buffer) @@ -60,7 +56,6 @@ func (r *JSONReader) Read(p []byte) (int, error) { } // WriteTo implements the io.WriterTo interface. -// func (r *JSONReader) WriteTo(w io.Writer) (int64, error) { cw := countingWriter{Writer: w} err := r.encode(&cw) diff --git a/go.mod b/go.mod index 6c38e42f76..a308a6a688 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.21.0 require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 go.opentelemetry.io/otel/trace v1.28.0 ) diff --git a/go.sum b/go.sum index 9df41c3fc3..8c76c70289 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ 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/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/internal/testing/e2e/bulk_indexer_integration_test.go b/internal/testing/e2e/bulk_indexer_integration_test.go index 97e4375a2e..8cfe3bf70a 100644 --- a/internal/testing/e2e/bulk_indexer_integration_test.go +++ b/internal/testing/e2e/bulk_indexer_integration_test.go @@ -100,6 +100,7 @@ func TestBulkIndexerIntegration(t *testing.T) { PoolCompressor: tt.PoolCompressor, Logger: &elastictransport.ColorLogger{Output: os.Stdout}, }) + defer es.Close(context.Background()) es.Indices.Delete([]string{indexName}, es.Indices.Delete.WithIgnoreUnavailable(true)) es.Indices.Create( @@ -171,6 +172,7 @@ func TestBulkIndexerIntegration(t *testing.T) { PoolCompressor: tt.PoolCompressor, Logger: &elastictransport.ColorLogger{Output: os.Stdout}, }) + defer es.Close(context.Background()) bi, _ := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{ Index: "test-index-a", @@ -245,6 +247,7 @@ func TestBulkIndexerIntegration(t *testing.T) { PoolCompressor: tt.PoolCompressor, Logger: &elastictransport.ColorLogger{Output: os.Stdout}, }) + defer es.Close(context.Background()) es.Indices.Delete([]string{index}, es.Indices.Delete.WithIgnoreUnavailable(true)) es.Indices.Create(index, es.Indices.Create.WithWaitForActiveShards("1")) @@ -312,6 +315,7 @@ func TestBulkIndexerIntegration(t *testing.T) { PoolCompressor: tt.PoolCompressor, Logger: &elastictransport.ColorLogger{Output: os.Stdout, EnableRequestBody: true, EnableResponseBody: true}, }) + defer es.Close(context.Background()) es.Indices.Delete([]string{index}, es.Indices.Delete.WithIgnoreUnavailable(true)) es.Indices.Create(index, es.Indices.Create.WithWaitForActiveShards("1")) diff --git a/internal/testing/e2e/elasticsearch_integration_test.go b/internal/testing/e2e/elasticsearch_integration_test.go index 218d675139..d204706f87 100644 --- a/internal/testing/e2e/elasticsearch_integration_test.go +++ b/internal/testing/e2e/elasticsearch_integration_test.go @@ -48,9 +48,10 @@ import ( "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/result" "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder" + "testing/containertest" + "github.com/testcontainers/testcontainers-go" tces "github.com/testcontainers/testcontainers-go/modules/elasticsearch" - "testing/containertest" ) func TestElasticsearchIntegration(t *testing.T) { @@ -77,6 +78,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() var total int @@ -129,6 +135,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() for i := 0; i < 101; i++ { wg.Add(1) @@ -152,6 +163,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond) defer cancel() @@ -188,6 +204,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() res, err := es.Info() if err == nil { @@ -209,6 +230,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() res, err := es.Info().Do(context.Background()) if err != nil { @@ -231,6 +257,11 @@ func TestElasticsearchIntegration(t *testing.T) { if err != nil { t.Fatalf("error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() // If the index doesn't exist we create it with a mapping. indexName := "test-index" @@ -524,6 +555,11 @@ func TestElasticsearchInsecureIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() for i := 0; i < 10; i++ { res, err := es.Info() @@ -550,6 +586,11 @@ func TestElasticsearchInsecureIntegration(t *testing.T) { }, API: esapi.New(tp), } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() for i := 0; i < 10; i++ { res, err := es.Info() @@ -575,6 +616,11 @@ func TestElasticsearchInsecureIntegration(t *testing.T) { }, API: esapi.New(tr), } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() for i := 0; i < 10; i++ { res, err := es.Info() @@ -596,6 +642,11 @@ func TestElasticsearchInsecureIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s\n", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() res, err := es.Info() if err != nil { diff --git a/internal/testing/e2e/esapi_integration_test.go b/internal/testing/e2e/esapi_integration_test.go index 3136ccb43e..cc38f6cb31 100644 --- a/internal/testing/e2e/esapi_integration_test.go +++ b/internal/testing/e2e/esapi_integration_test.go @@ -58,6 +58,11 @@ func TestAPI(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s\n", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() es.Cluster.Health(es.Cluster.Health.WithWaitForStatus("yellow")) res, err := es.Search(es.Search.WithTimeout(500 * time.Millisecond)) @@ -83,6 +88,11 @@ func TestAPI(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s\n", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() res, err := es.Info(es.Info.WithHeader(map[string]string{"Accept": "application/yaml"})) if err != nil { @@ -113,6 +123,11 @@ func TestAPI(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s\n", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() // Prepare indices // diff --git a/internal/testing/e2e/json_reader_integration_test.go b/internal/testing/e2e/json_reader_integration_test.go index 297671573b..3f562da94f 100644 --- a/internal/testing/e2e/json_reader_integration_test.go +++ b/internal/testing/e2e/json_reader_integration_test.go @@ -22,13 +22,14 @@ package e2e_test import ( "context" - "github.com/elastic/go-elasticsearch/v8" - "github.com/elastic/go-elasticsearch/v8/esapi" - "github.com/elastic/go-elasticsearch/v8/esutil" "os" "strings" "testing" + "github.com/elastic/go-elasticsearch/v8" + "github.com/elastic/go-elasticsearch/v8/esapi" + "github.com/elastic/go-elasticsearch/v8/esutil" + "testing/containertest" ) @@ -60,6 +61,11 @@ func TestJSONReaderIntegration(t *testing.T) { if err != nil { t.Fatalf("Error creating the client: %s\n", err) } + defer func() { + if err := es.Close(context.Background()); err != nil { + t.Fatalf("Error closing the client: %s", err) + } + }() es.Indices.Delete([]string{"test"}, es.Indices.Delete.WithIgnoreUnavailable(true)) diff --git a/internal/testing/go.mod b/internal/testing/go.mod index d0d6fd4ed8..55afb6361b 100644 --- a/internal/testing/go.mod +++ b/internal/testing/go.mod @@ -5,7 +5,7 @@ go 1.22.0 replace github.com/elastic/go-elasticsearch/v8 => ./../.. require ( - github.com/elastic/elastic-transport-go/v8 v8.7.0 + github.com/elastic/elastic-transport-go/v8 v8.8.0 github.com/elastic/go-elasticsearch/v8 v8.14.0 github.com/testcontainers/testcontainers-go v0.34.0 github.com/testcontainers/testcontainers-go/modules/elasticsearch v0.34.0 diff --git a/internal/testing/go.sum b/internal/testing/go.sum index 2d9af69c7f..da58f6444a 100644 --- a/internal/testing/go.sum +++ b/internal/testing/go.sum @@ -30,8 +30,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE= -github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= +github.com/elastic/elastic-transport-go/v8 v8.8.0 h1:7k1Ua+qluFr6p1jfJjGDl97ssJS/P7cHNInzfxgBQAo= +github.com/elastic/elastic-transport-go/v8 v8.8.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=