Schemas: Reduce duplicated jenny code (#84061)

* Remove jenny_ts_resources and use jenny_ts_types for all cases

* Unify TS generated files into one jenny

* Add missing imports to versioned files

* Update Parca plugin

* Fix loki

* Use LokiQuery

* Fix pyroscope tests

* Fix prettier

* 😒 fix default pyroscope value name

* Set the LokiQuery

* Update Elasticsearch and TestData

* Missed files from testdata

* Order imports
This commit is contained in:
Selene
2024-03-11 12:51:44 +01:00
committed by GitHub
parent bd9f9c9eb0
commit 275ccf994b
97 changed files with 320 additions and 429 deletions
+16 -48
View File
@@ -11,22 +11,20 @@ import (
// LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version.
//
// TODO remove forceGroup option, it's a temporary hack to accommodate core kinds
func LatestMajorsOrXJenny(parentdir string, forceGroup bool, inner codejen.OneToOne[SchemaForGen]) OneToMany {
func LatestMajorsOrXJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToMany {
if inner == nil {
panic("inner jenny must not be nil")
}
return &lmox{
parentdir: parentdir,
inner: inner,
forceGroup: forceGroup,
parentdir: parentdir,
inner: inner,
}
}
type lmox struct {
parentdir string
inner codejen.OneToOne[SchemaForGen]
forceGroup bool
parentdir string
inner codejen.OneToOne[SchemaForGen]
}
func (j *lmox) JennyName() string {
@@ -42,49 +40,19 @@ func (j *lmox) Generate(kind kindsys.Kind) (codejen.Files, error) {
comm := kind.Props().Common()
sfg := SchemaForGen{
Name: comm.Name,
IsGroup: comm.LineageIsGroup,
IsGroup: true,
Schema: kind.Lineage().Latest(),
}
if j.forceGroup {
sfg.IsGroup = true
f, err := j.inner.Generate(sfg)
if err != nil {
return nil, fmt.Errorf("%s jenny failed on %s schema for %s: %w", j.inner.JennyName(), sfg.Schema.Version(), kind.Props().Common().Name, err)
}
if f == nil || !f.Exists() {
return nil, nil
}
do := func(sfg SchemaForGen, infix string) (codejen.Files, error) {
f, err := j.inner.Generate(sfg)
if err != nil {
return nil, fmt.Errorf("%s jenny failed on %s schema for %s: %w", j.inner.JennyName(), sfg.Schema.Version(), kind.Props().Common().Name, err)
}
if f == nil || !f.Exists() {
return nil, nil
}
f.RelativePath = filepath.Join(j.parentdir, comm.MachineName, infix, f.RelativePath)
f.From = append(f.From, j)
return codejen.Files{*f}, nil
}
if comm.Maturity.Less(kindsys.MaturityStable) {
sfg.Schema = kind.Lineage().Latest()
return do(sfg, "x")
}
var fl codejen.Files
major := -1
for sch := kind.Lineage().First(); sch != nil; sch = sch.Successor() {
if int(sch.Version()[0]) == major {
continue
}
major = int(sch.Version()[0])
sfg.Schema = sch.LatestInMajor()
files, err := do(sfg, fmt.Sprintf("v%v", sch.Version()[0]))
if err != nil {
return nil, err
}
fl = append(fl, files...)
}
if fl.Validate() != nil {
return nil, fl.Validate()
}
return fl, nil
f.RelativePath = filepath.Join(j.parentdir, comm.MachineName, "x", f.RelativePath)
f.From = append(f.From, j)
return codejen.Files{*f}, nil
}