in main.go [327:393]
func encodeIndexOp(
encoder *json.Encoder,
b benchmark,
pkg, goos, goarch string,
tags map[string]string,
timestamp time.Time,
cfg elasticsearchConfig,
) {
doc := map[string]interface{}{
fieldExecutedAt: timestamp,
fieldName: b.Name,
fieldIterations: b.N,
fieldPkg: pkg,
fieldGoVersion: runtime.Version(),
fieldGOOS: goos,
fieldGOARCH: goarch,
}
if b.Measured&parse.NsPerOp != 0 {
doc[fieldNSPerOp] = b.NsPerOp
}
if b.Measured&parse.MBPerS != 0 {
doc[fieldMBPerS] = b.MBPerS
}
if b.Measured&parse.AllocedBytesPerOp != 0 {
doc[fieldAllocedBytesPerOp] = b.AllocedBytesPerOp
}
if b.Measured&parse.AllocsPerOp != 0 {
doc[fieldAllocsPerOp] = b.AllocsPerOp
}
if len(b.extra) > 0 {
apmbench := b.extra
doc[fieldExtraMetrics] = apmbench
}
addHost(doc)
addVCS(pkg, doc)
for key, value := range tags {
doc[key] = value
}
// Versions of Elasticsearch >= 8.0.0 require no _type field
esVersion, err := getEsVersion(cfg.host, cfg.user, cfg.pass)
if err != nil {
log.Fatal(err)
}
includeTypDoc := esVersion.LT(semver.MustParse("8.0.0"))
type Index struct {
Index string `json:"_index"`
Type string `json:"_type,omitempty"`
}
indexAction := struct {
Index Index `json:"index"`
}{Index: Index{
Index: cfg.index,
}}
if includeTypDoc {
indexAction.Index.Type = "_doc"
}
if err := encoder.Encode(indexAction); err != nil {
log.Fatal(err)
}
if err := encoder.Encode(doc); err != nil {
log.Fatal(err)
}
}