Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] [pdata] Migrate the code generator to go templates #7241

Conversation

dmitryax
Copy link
Member

This change migrates the env var based templates to go templates to allow more complicated logic in them needed for #7205

@dmitryax dmitryax requested review from a team and djaglowski February 26, 2023 08:28
@dmitryax dmitryax changed the title [chore] [pdata] Migrate the generator to go templates [chore] [pdata] Migrate the code generator to go templates Feb 26, 2023
@codecov
Copy link

codecov bot commented Feb 26, 2023

Codecov Report

Base: 90.99% // Head: 90.99% // No change to project coverage 👍

Coverage data is based on head (21b9b40) compared to base (6f800ca).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7241   +/-   ##
=======================================
  Coverage   90.99%   90.99%           
=======================================
  Files         293      293           
  Lines       14268    14268           
=======================================
  Hits        12983    12983           
  Misses       1017     1017           
  Partials      268      268           
Impacted Files Coverage Δ
pdata/pmetric/generated_exemplarslice.go 100.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dmitryax dmitryax force-pushed the pdata-migrate-generator-to-go-templates branch 2 times, most recently from 9a889f3 to 7f87467 Compare February 26, 2023 20:08
@dmitryax dmitryax force-pushed the pdata-migrate-generator-to-go-templates branch from 7f87467 to 21b9b40 Compare February 27, 2023 07:07
Comment on lines -23 to -30
const accessorSliceTemplate = `// ${fieldName} returns the ${fieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${returnType} {
return new${returnType}(&ms.${origAccessor}.${fieldName})
const accessorSliceTemplate = `// {{ .fieldName }} returns the {{ .fieldName }} associated with this {{ .structName }}.
func (ms {{ .structName }}) {{ .fieldName }}() {{ .packageName }}{{ .returnType }} {
{{- if .isCommon }}
return {{ .packageName }}{{ .returnType }}(internal.New{{ .returnType }}(&ms.{{ .origAccessor }}.{{ .fieldName }}))
{{- else }}
return new{{ .returnType }}(&ms.{{ .origAccessor }}.{{ .fieldName }})
{{- end }}
}`

const accessorSliceTemplateCommon = `// ${fieldName} returns the ${fieldName} associated with this ${structName}.
func (ms ${structName}) ${fieldName}() ${packageName}${returnType} {
return ${packageName}${returnType}(internal.New${returnType}(&ms.${origAccessor}.${fieldName}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, we're now autodetecting whether or not each struct is common based on the package, and this is necessarily part of this change in order to build the map expected by go templates. Is that right?

Copy link
Member Author

@dmitryax dmitryax Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now autodetecting whether or not each struct is common based on the package

We've been doing that for a while already. But it's still can be changed if ever needed

@bogdandrutu bogdandrutu merged commit 1f5865d into open-telemetry:main Feb 27, 2023
@dmitryax dmitryax deleted the pdata-migrate-generator-to-go-templates branch March 1, 2023 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants