MCPcopy
hub / github.com/elastic/go-elasticsearch / SaveStats

Method SaveStats

_benchmarks/benchmarks/runner/runner.go:229–313  ·  view source on GitHub ↗

SaveStats stores runner statistics in Elasticsearch.

()

Source from the content-addressed store, hash-verified

227
228// SaveStats stores runner statistics in Elasticsearch.
229func (r *Runner) SaveStats() error {
230 var errs []error
231
232 for _, s := range r.stats {
233 record := record{
234 Timestamp: s.Start,
235 Tags: []string{"bench", "go-elasticsearch"},
236 Labels: map[string]string{
237 "build_id": r.config.BuildID,
238 "client": "go-elasticsearch",
239 "environment": r.config.Environment,
240 },
241 Event: recordEvent{
242 Action: r.config.Action,
243 Duration: s.Duration.Nanoseconds(),
244 Outcome: s.Outcome,
245 },
246 HTTP: recordHTTP{
247 Response: recordHTTPResponse{
248 StatusCode: s.ResponseStatusCode,
249 },
250 },
251 Benchmark: recordBenchmark{
252 BuildID: r.config.BuildID,
253 Category: r.config.Category,
254 Environment: r.config.Environment,
255 Repetitions: r.config.NumRepetitions,
256 Operations: r.config.NumOperations,
257 Runner: recordRunner{
258 Service: recordService{
259 Type: "client",
260 Name: "go-elasticsearch",
261 Version: elasticsearch.Version,
262 Git: recordGit{Branch: r.config.Runner.Service.Git.Branch, Commit: r.config.Runner.Service.Git.Commit},
263 },
264 Runtime: recordRuntime{Name: "go", Version: RuntimeVersion},
265 OS: recordOS{Family: RuntimeOS},
266 },
267 Target: recordTarget{
268 Service: recordService{
269 Type: r.config.Target.Service.Type,
270 Name: r.config.Target.Service.Type,
271 Version: r.config.Target.Service.Version,
272 Git: recordGit{Branch: r.config.Target.Service.Git.Branch, Commit: r.config.Target.Service.Git.Commit},
273 },
274 OS: recordOS{Family: r.config.Target.OS.Family},
275 },
276 },
277 }
278 data, err := json.Marshal(record)
279 if err != nil {
280 return fmt.Errorf("failed to marshal record: %w", err)
281 }
282
283 if err := r.indexer.Add(
284 context.Background(),
285 esutil.BulkIndexerItem{
286 Action: "index",

Callers 1

RunMethod · 0.95

Calls 2

AddMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected