/
output_data.go
89 lines (70 loc) · 1.5 KB
/
output_data.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
_ "github.com/elastic/apm-server/include"
"github.com/elastic/apm-server/processor"
)
func main() {
err := generate()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
os.Exit(1)
}
}
func generate() error {
filename := "payload.json"
basepath := "tests/data/valid"
outputPath := "docs/data/elasticsearch/"
processors := processor.Registry.Processors()
var checked = map[string]struct{}{}
for _, p := range processors {
// Remove version from name and and s at the end
name := p.Name()
// Create path to test docs
path := filepath.Join(basepath, name, filename)
f, err := os.Open(path)
if err != nil {
return err
}
data, err := ioutil.ReadAll(f)
if err != nil {
return err
}
err = p.Validate(data)
if err != nil {
return err
}
events, err := p.Transform(data)
if err != nil {
return err
}
for _, d := range events {
n, err := d.GetValue("processor.name")
if err != nil {
return err
}
event, err := d.GetValue("processor.event")
if err != nil {
return err
}
key := n.(string) + "-" + event.(string)
if _, ok := checked[key]; !ok {
checked[key] = struct{}{}
file := filepath.Join(outputPath, event.(string)+".json")
output, err := json.MarshalIndent(d.Fields, "", " ")
if err != nil {
return err
}
err = ioutil.WriteFile(file, output, 0644)
if err != nil {
return err
}
}
}
}
return nil
}