-
Notifications
You must be signed in to change notification settings - Fork 0
/
datadog_exporter.go
99 lines (84 loc) · 3.99 KB
/
datadog_exporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"context"
"fmt"
ddtesting "github.com/DataDog/dd-sdk-go-testing"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
type datadogExporter struct {
configuration *config
}
func newDatadogExporter() Exporter {
return new(datadogExporter)
}
func (de *datadogExporter) SetConfiguration(configuration *config) {
de.configuration = configuration
}
func (de *datadogExporter) IsEnabled() bool {
return de.configuration.EnableDatadog
}
func (de *datadogExporter) Export(resScenario []scenarioResult) {
if len(resScenario) > 0 {
finalizer := ddtesting.Initialize(tracer.WithLogger(myLogger{}), tracer.WithAnalytics(true))
defer finalizer()
cfg := de.configuration
for _, scenario := range resScenario {
var pName string
var pArgs string
var tags map[string]string
if scenario.ProcessName != nil {
pName = *scenario.ProcessName
} else if cfg.ProcessName != nil {
pName = *cfg.ProcessName
}
if scenario.ProcessArguments != nil {
pArgs = *scenario.ProcessArguments
} else if cfg.ProcessArguments != nil {
pArgs = *cfg.ProcessArguments
}
tags = cfg.Tags
for k, v := range scenario.Tags {
tags[k] = v
}
var startSpanOptions []tracer.StartSpanOption
startSpanOptions = append(startSpanOptions, tracer.StartTime(scenario.Start))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.job.description", scenario.Name))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.runs", cfg.Count))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.warmup_count", cfg.WarmUpCount))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.duration.mean", scenario.Mean))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.n", cfg.Count))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.mean", scenario.Mean))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.max", scenario.Max))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.min", scenario.Min))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.std_dev", scenario.Stdev))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.std_err", scenario.StdErr))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.p90", scenario.P90))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.p95", scenario.P95))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.p99", scenario.P99))
startSpanOptions = append(startSpanOptions, tracer.Tag("benchmark.statistics.outliers", len(scenario.Outliers)))
startSpanOptions = append(startSpanOptions, tracer.Tag("process.name", pName))
startSpanOptions = append(startSpanOptions, tracer.Tag("process.arguments", pArgs))
startSpanOptions = append(startSpanOptions, tracer.Tag("test.file.path", cfg.Path))
startSpanOptions = append(startSpanOptions, tracer.Tag("test.file.name", cfg.FileName))
startSpanOptions = append(startSpanOptions, tracer.Tag("test.file.file_path", cfg.FilePath))
startSpanOptions = append(startSpanOptions, tracer.Tag("test.scenario", scenario.Name))
startSpanOptions = append(startSpanOptions, tracer.Tag("test.framework", "time-it"))
for k, v := range tags {
startSpanOptions = append(startSpanOptions, tracer.Tag(k, v))
}
for k, v := range scenario.Metrics {
startSpanOptions = append(startSpanOptions, tracer.Tag(fmt.Sprintf("benchmark.%v", k), v))
}
_, testFinish := ddtesting.StartCustomTestOrBenchmark(context.Background(), ddtesting.TestData{
Type: ddtesting.TypeBenchmark,
Suite: fmt.Sprintf("time-it.%v", scenario.Name),
Name: cfg.FilePath,
Options: []ddtesting.Option{
ddtesting.WithSpanOptions(startSpanOptions...),
ddtesting.WithFinishOptions(tracer.FinishTime(scenario.End), tracer.WithError(scenario.Error)),
},
})
testFinish(ddtesting.StatusPass, nil)
}
}
}