Skip to content

Commit ff851cd

Browse files
author
Ron cohen
committed
Move generated schemas into sub-folders
1 parent 46bc977 commit ff851cd

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

processor/error/schema.go renamed to processor/error/generated-schemas/payload.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
package error
1+
package schemas
22

3-
func Schema() string {
4-
return errorSchema
5-
}
6-
7-
var errorSchema = `{
3+
const PayloadSchema = `{
84
"$schema": "http://json-schema.org/draft-04/schema#",
95
"$id": "docs/spec/errors/payload.json",
106
"title": "Errors payload",

processor/error/processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/santhosh-tekuri/jsonschema"
55

66
pr "github.com/elastic/apm-server/processor"
7+
generatedschemas "github.com/elastic/apm-server/processor/error/generated-schemas"
78
"github.com/elastic/beats/libbeat/monitoring"
89
)
910

@@ -20,7 +21,7 @@ const (
2021
errorDocType = "error"
2122
)
2223

23-
var schema = pr.CreateSchema(errorSchema, processorName)
24+
var schema = pr.CreateSchema(generatedschemas.PayloadSchema, processorName)
2425

2526
func NewProcessor() pr.Processor {
2627
return &processor{schema: schema}

processor/sourcemap/schema.go renamed to processor/sourcemap/generated-schemas/payload.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
package sourcemap
1+
package schemas
22

3-
func Schema() string {
4-
return sourcemapSchema
5-
}
6-
7-
var sourcemapSchema = `{
3+
const SourcemapSchema = `{
84
"$schema": "http://json-schema.org/draft-04/schema#",
95
"$id": "docs/spec/sourcemaps/sourcemap-metadata.json",
106
"title": "Sourcemap Metadata",

processor/sourcemap/processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
parser "github.com/go-sourcemap/sourcemap"
1010

1111
pr "github.com/elastic/apm-server/processor"
12+
generatedschemas "github.com/elastic/apm-server/processor/sourcemap/generated-schemas"
1213
"github.com/elastic/apm-server/utility"
1314
"github.com/elastic/beats/libbeat/monitoring"
1415
)
@@ -26,7 +27,7 @@ var (
2627
decodingError = monitoring.NewInt(sourcemapUploadMetrics, "decoding.errors")
2728
)
2829

29-
var schema = pr.CreateSchema(sourcemapSchema, processorName)
30+
var schema = pr.CreateSchema(generatedschemas.SourcemapSchema, processorName)
3031

3132
func NewProcessor() pr.Processor {
3233
return &processor{schema: schema}

processor/transaction/schema.go renamed to processor/transaction/generated-schemas/payload.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
package transaction
1+
package schemas
22

3-
func Schema() string {
4-
return transactionSchema
5-
}
6-
7-
var transactionSchema = `{
3+
const PayloadSchema = `{
84
"$schema": "http://json-schema.org/draft-04/schema#",
95
"$id": "docs/spec/transactions/payload.json",
106
"title": "Transactions payload",

processor/transaction/processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package transaction
22

33
import (
44
pr "github.com/elastic/apm-server/processor"
5+
generatedschemas "github.com/elastic/apm-server/processor/transaction/generated-schemas"
56
"github.com/elastic/beats/libbeat/monitoring"
67

78
"github.com/santhosh-tekuri/jsonschema"
@@ -21,7 +22,7 @@ const (
2122
spanDocType = "span"
2223
)
2324

24-
var schema = pr.CreateSchema(transactionSchema, processorName)
25+
var schema = pr.CreateSchema(generatedschemas.PayloadSchema, processorName)
2526

2627
func NewProcessor() pr.Processor {
2728
return &processor{schema: schema}

script/inline_schemas/inline_schemas.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"fmt"
55
"io/ioutil"
6+
"os"
7+
"path"
68
"path/filepath"
79
"regexp"
810
"strings"
@@ -12,11 +14,11 @@ const basePath = "./docs/spec/"
1214

1315
func main() {
1416
schemaPaths := []struct {
15-
path, schemaOut, goVariable, packageName string
17+
path, schemaOut, goVariable string
1618
}{
17-
{"errors/payload.json", "processor/error/schema.go", "errorSchema", "error"},
18-
{"transactions/payload.json", "processor/transaction/schema.go", "transactionSchema", "transaction"},
19-
{"sourcemaps/payload.json", "processor/sourcemap/schema.go", "sourcemapSchema", "sourcemap"},
19+
{"errors/payload.json", "processor/error/generated-schemas/payload.go", "PayloadSchema"},
20+
{"transactions/payload.json", "processor/transaction/generated-schemas/payload.go", "PayloadSchema"},
21+
{"sourcemaps/payload.json", "processor/sourcemap/generated-schemas/payload.go", "SourcemapSchema"},
2022
}
2123
for _, schemaInfo := range schemaPaths {
2224
file := filepath.Join(filepath.Dir(basePath), schemaInfo.path)
@@ -30,8 +32,11 @@ func main() {
3032
panic(err)
3133
}
3234

33-
publicSchema := fmt.Sprintf("func Schema() string {\n\treturn %s\n}\n", schemaInfo.goVariable)
34-
goScript := fmt.Sprintf("package %s\n\n%s\nvar %s = `%s`\n", schemaInfo.packageName, publicSchema, schemaInfo.goVariable, schema)
35+
goScript := fmt.Sprintf("package schemas\n\nconst %s = `%s`\n", schemaInfo.goVariable, schema)
36+
err = os.MkdirAll(path.Dir(schemaInfo.schemaOut), os.ModePerm)
37+
if err != nil {
38+
panic(err)
39+
}
3540
err = ioutil.WriteFile(schemaInfo.schemaOut, []byte(goScript), 0644)
3641
if err != nil {
3742
panic(err)

0 commit comments

Comments
 (0)