Skip to content

Commit d706b93

Browse files
roncohensimitt
authored andcommitted
Move generated schemas into sub-folders (elastic#1024)
1 parent 1afa789 commit d706b93

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package error
18+
package schema
1919

20-
func Schema() string {
21-
return errorSchema
22-
}
23-
24-
var errorSchema = `{
20+
const PayloadSchema = `{
2521
"$id": "docs/spec/errors/payload.json",
2622
"title": "Errors payload",
2723
"description": "List of errors wrapped in an object containing some other attributes normalized away from the errors themselves",

processor/error/package_tests/json_schema_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
er "github.com/elastic/apm-server/processor/error"
24+
"github.com/elastic/apm-server/processor/error/generated/schema"
2425
"github.com/elastic/apm-server/tests"
2526
)
2627

@@ -165,5 +166,5 @@ func TestPayloadAttributesInSchema(t *testing.T) {
165166
"errors.context.request.cookies.c2",
166167
"errors.context.tags.organization_uuid",
167168
)
168-
tests.TestPayloadAttributesInSchema(t, "error", undocumented, er.Schema())
169+
tests.TestPayloadAttributesInSchema(t, "error", undocumented, schema.PayloadSchema)
169170
}

processor/error/processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/santhosh-tekuri/jsonschema"
2222

2323
pr "github.com/elastic/apm-server/processor"
24+
"github.com/elastic/apm-server/processor/error/generated/schema"
2425
"github.com/elastic/beats/libbeat/monitoring"
2526
)
2627

@@ -37,10 +38,10 @@ const (
3738
errorDocType = "error"
3839
)
3940

40-
var schema = pr.CreateSchema(errorSchema, processorName)
41+
var loadedSchema = pr.CreateSchema(schema.PayloadSchema, processorName)
4142

4243
func NewProcessor() pr.Processor {
43-
return &processor{schema: schema}
44+
return &processor{schema: loadedSchema}
4445
}
4546

4647
func (p *processor) Name() string {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package sourcemap
18+
package schema
1919

20-
func Schema() string {
21-
return sourcemapSchema
22-
}
23-
24-
var sourcemapSchema = `{
20+
const PayloadSchema = `{
2521
"$id": "docs/spec/sourcemaps/sourcemap-metadata.json",
2622
"title": "Sourcemap Metadata",
2723
"description": "Sourcemap Metadata",

processor/sourcemap/package_tests/json_schema_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
sm "github.com/elastic/apm-server/processor/sourcemap"
24+
"github.com/elastic/apm-server/processor/sourcemap/generated/schema"
2425
"github.com/elastic/apm-server/tests"
2526
)
2627

@@ -31,7 +32,7 @@ func TestPayloadAttributesInSchema(t *testing.T) {
3132
"sourcemap",
3233
tests.NewSet("sourcemap", "sourcemap.file", "sourcemap.names", "sourcemap.sources", "sourcemap.sourceRoot",
3334
"sourcemap.mappings", "sourcemap.sourcesContent", "sourcemap.version"),
34-
sm.Schema())
35+
schema.PayloadSchema)
3536
}
3637

3738
var (

processor/sourcemap/processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
parser "github.com/go-sourcemap/sourcemap"
2727

2828
pr "github.com/elastic/apm-server/processor"
29+
"github.com/elastic/apm-server/processor/sourcemap/generated/schema"
2930
"github.com/elastic/apm-server/utility"
3031
"github.com/elastic/beats/libbeat/monitoring"
3132
)
@@ -43,10 +44,10 @@ var (
4344
decodingError = monitoring.NewInt(sourcemapUploadMetrics, "decoding.errors")
4445
)
4546

46-
var schema = pr.CreateSchema(sourcemapSchema, processorName)
47+
var loadedSchema = pr.CreateSchema(schema.PayloadSchema, processorName)
4748

4849
func NewProcessor() pr.Processor {
49-
return &processor{schema: schema}
50+
return &processor{schema: loadedSchema}
5051
}
5152

5253
func (p *processor) Name() string {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package transaction
18+
package schema
1919

20-
func Schema() string {
21-
return transactionSchema
22-
}
23-
24-
var transactionSchema = `{
20+
const PayloadSchema = `{
2521
"$id": "docs/spec/transactions/payload.json",
2622
"title": "Transactions payload",
2723
"description": "List of transactions wrapped in an object containing some other attributes normalized away from the transactions themselves",

processor/transaction/package_tests/json_schema_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
tr "github.com/elastic/apm-server/processor/transaction"
24+
"github.com/elastic/apm-server/processor/transaction/generated/schema"
2425
"github.com/elastic/apm-server/tests"
2526
)
2627

@@ -190,5 +191,5 @@ func TestPayloadAttributesInSchema(t *testing.T) {
190191
"transactions.marks.navigationTiming.navigationStart",
191192
"transactions.marks.performance",
192193
)
193-
tests.TestPayloadAttributesInSchema(t, "transaction", undocumented, tr.Schema())
194+
tests.TestPayloadAttributesInSchema(t, "transaction", undocumented, schema.PayloadSchema)
194195
}

processor/transaction/processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package transaction
1919

2020
import (
2121
pr "github.com/elastic/apm-server/processor"
22+
"github.com/elastic/apm-server/processor/transaction/generated/schema"
2223
"github.com/elastic/beats/libbeat/monitoring"
2324

2425
"github.com/santhosh-tekuri/jsonschema"
@@ -38,10 +39,10 @@ const (
3839
spanDocType = "span"
3940
)
4041

41-
var schema = pr.CreateSchema(transactionSchema, processorName)
42+
var loadedSchema = pr.CreateSchema(schema.PayloadSchema, processorName)
4243

4344
func NewProcessor() pr.Processor {
44-
return &processor{schema: schema}
45+
return &processor{schema: loadedSchema}
4546
}
4647

4748
type processor struct {

script/inline_schemas/inline_schemas.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package main
2020
import (
2121
"fmt"
2222
"io/ioutil"
23+
"os"
24+
"path"
2325
"path/filepath"
2426
"regexp"
2527
"strings"
@@ -29,11 +31,11 @@ const basePath = "./docs/spec/"
2931

3032
func main() {
3133
schemaPaths := []struct {
32-
path, schemaOut, goVariable, packageName string
34+
path, schemaOut string
3335
}{
34-
{"errors/payload.json", "processor/error/schema.go", "errorSchema", "error"},
35-
{"transactions/payload.json", "processor/transaction/schema.go", "transactionSchema", "transaction"},
36-
{"sourcemaps/payload.json", "processor/sourcemap/schema.go", "sourcemapSchema", "sourcemap"},
36+
{"errors/payload.json", "processor/error/generated/schema/payload.go"},
37+
{"transactions/payload.json", "processor/transaction/generated/schema/payload.go"},
38+
{"sourcemaps/payload.json", "processor/sourcemap/generated/schema/payload.go"},
3739
}
3840
for _, schemaInfo := range schemaPaths {
3941
file := filepath.Join(filepath.Dir(basePath), schemaInfo.path)
@@ -47,8 +49,11 @@ func main() {
4749
panic(err)
4850
}
4951

50-
publicSchema := fmt.Sprintf("func Schema() string {\n\treturn %s\n}\n", schemaInfo.goVariable)
51-
goScript := fmt.Sprintf("package %s\n\n%s\nvar %s = `%s`\n", schemaInfo.packageName, publicSchema, schemaInfo.goVariable, schema)
52+
goScript := fmt.Sprintf("package schema\n\nconst PayloadSchema = `%s`\n", schema)
53+
err = os.MkdirAll(path.Dir(schemaInfo.schemaOut), os.ModePerm)
54+
if err != nil {
55+
panic(err)
56+
}
5257
err = ioutil.WriteFile(schemaInfo.schemaOut, []byte(goScript), 0644)
5358
if err != nil {
5459
panic(err)

0 commit comments

Comments
 (0)