()
| 34 | ) |
| 35 | |
| 36 | func init() { |
| 37 | benchmarks.Register( |
| 38 | benchmarks.Action{ |
| 39 | Name: "bulk-helper", |
| 40 | Category: "helpers", |
| 41 | |
| 42 | NumWarmups: 1, |
| 43 | NumRepetitions: 10, |
| 44 | NumOperations: 1000000, |
| 45 | |
| 46 | SetupFunc: func(n int, c runner.Config) (*esapi.Response, error) { |
| 47 | var ( |
| 48 | res *esapi.Response |
| 49 | err error |
| 50 | |
| 51 | indexName = "test-bench-bulk-helper" |
| 52 | indexSettings = `{"settings": { "number_of_shards": 3, "refresh_interval":"5s"}}` |
| 53 | ) |
| 54 | res, _ = c.RunnerClient.Indices.Delete([]string{indexName}) |
| 55 | if res != nil && res.Body != nil { |
| 56 | res.Body.Close() |
| 57 | } |
| 58 | res, err = c.RunnerClient.Indices.Create( |
| 59 | indexName, |
| 60 | c.RunnerClient.Indices.Create.WithBody(strings.NewReader(indexSettings)), |
| 61 | c.RunnerClient.Indices.Create.WithWaitForActiveShards("1")) |
| 62 | if err != nil { |
| 63 | return res, err |
| 64 | } |
| 65 | if res != nil && res.Body != nil { |
| 66 | res.Body.Close() |
| 67 | } |
| 68 | return res, err |
| 69 | }, |
| 70 | |
| 71 | RunnerFunc: func(n int, c runner.Config) (*esapi.Response, error) { |
| 72 | var ( |
| 73 | err error |
| 74 | |
| 75 | indexName = "test-bench-bulk-helper" |
| 76 | ) |
| 77 | |
| 78 | var addresses []string |
| 79 | for _, u := range c.RunnerClient.Transport.(*elastictransport.Client).URLs() { |
| 80 | addresses = append(addresses, u.String()) |
| 81 | } |
| 82 | |
| 83 | es, err := elasticsearch.New( |
| 84 | elasticsearch.WithAddresses(addresses...), |
| 85 | elasticsearch.WithRetry(5, 502, 503, 504, 429), |
| 86 | ) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | |
| 91 | bi, err := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{ |
| 92 | Index: indexName, |
| 93 | Client: es, |
nothing calls this directly
no test coverage detected