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

Change pdata generated types to use type definition instead of aliases #5936

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Aug 19, 2022

Change the way how objects are generated in pdata. Previously the pdata objects were generated in the internal package and aliases were created in the public packageas.

This PR changes this, by creating only "wrappers" object inside the internal package, and the public type is a type def of the internal type:

package internal

type LogRecord struct {
	orig *otlplogs.LogRecord
}

func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord {
	return ms.orig
}

func NewLogRecord(orig *otlplogs.LogRecord) LogRecord {
	return LogRecord{orig: orig}
}
package plog

type LogRecord internal.LogRecord

With this approach, we still do not allow users access to the internal origin, which allows us flexibility to change to other representation (something like lazy proto, etc), but improves documentation of the pdata packages, see current documentation.

Signed-off-by: Bogdan [email protected]

@bogdandrutu bogdandrutu force-pushed the usedypedef branch 8 times, most recently from 00dbeab to c065c0c Compare August 24, 2022 01:00
@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #5936 (474d968) into main (18700db) will increase coverage by 0.39%.
The diff coverage is 99.04%.

@@            Coverage Diff             @@
##             main    #5936      +/-   ##
==========================================
+ Coverage   91.90%   92.30%   +0.39%     
==========================================
  Files         200      212      +12     
  Lines       12414    13249     +835     
==========================================
+ Hits        11409    12229     +820     
- Misses        793      803      +10     
- Partials      212      217       +5     
Impacted Files Coverage Δ
pdata/pcommon/timestamp.go 100.00% <ø> (ø)
pdata/ptrace/json.go 100.00% <ø> (ø)
pdata/ptrace/pb.go 100.00% <ø> (ø)
pdata/ptrace/ptraceotlp/traces.go 49.01% <ø> (ø)
pdata/ptrace/traces.go 92.59% <ø> (ø)
pdata/plog/logs.go 90.38% <92.30%> (ø)
pdata/plog/generated_logs.go 96.77% <97.69%> (ø)
pdata/ptrace/generated_traces.go 97.02% <97.87%> (ø)
pdata/pmetric/generated_metrics.go 96.08% <98.31%> (ø)
pdata/internal/generated_wrapper_common.go 100.00% <100.00%> (ø)
... and 26 more

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

@bogdandrutu bogdandrutu changed the title Use typedef Change pdata generated types to use type definition instead of aliases Aug 24, 2022
@bogdandrutu bogdandrutu marked this pull request as ready for review August 24, 2022 01:12
@bogdandrutu bogdandrutu requested a review from a team August 24, 2022 01:12
@bogdandrutu bogdandrutu requested review from a team, dmitryax and codeboten August 24, 2022 01:12
@bogdandrutu bogdandrutu force-pushed the usedypedef branch 2 times, most recently from 56b0107 to beea276 Compare August 24, 2022 01:17
Change the way how objects are generated in `pdata`. Previously the pdata objects were generated in the `internal` package and aliases were created in the public packageas.

This PR changes this, by creating only "wrappers" object inside the internal package, and the public type is a type def of the internal type:

```golang
package internal

type LogRecord struct {
	orig *otlplogs.LogRecord
}

func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord {
	return ms.orig
}

func NewLogRecord(orig *otlplogs.LogRecord) LogRecord {
	return LogRecord{orig: orig}
}
```

```golang
package plog

type LogRecord internal.LogRecord
```

With this approach, we still do not allow users access to the internal origin, which allows us flexibility to change to other representation (something like lazy proto, etc), but improves documentation of the pdata packages, see [current documentation](https://pkg.go.dev/go.opentelemetry.io/collector/[email protected]/plog).

Signed-off-by: Bogdan <[email protected]>
Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

Just couple of nits. Otherwise LGTM.

This is a great solution! I believe the only downside is that now we have some computational overhead spent of type conversions, right?

pdata/plog/generated_logs.go Show resolved Hide resolved
pdata/ptrace/traces.go Show resolved Hide resolved
pdata/plog/logs.go Show resolved Hide resolved
@bogdandrutu
Copy link
Member Author

This is a great solution! I believe the only downside is that now we have some computational overhead spent of type conversions, right?

I believe the compiler should be smart enough to not have to do this :)

Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

LGTM

@bogdandrutu bogdandrutu merged commit 58fa059 into open-telemetry:main Aug 24, 2022
@bogdandrutu bogdandrutu deleted the usedypedef branch August 24, 2022 23:32
bogdandrutu added a commit to bogdandrutu/opentelemetry-collector that referenced this pull request Aug 30, 2022
bogdandrutu added a commit that referenced this pull request Aug 30, 2022
The mistake happened in #5936

Signed-off-by: Bogdan <[email protected]>

Signed-off-by: Bogdan <[email protected]>
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.

2 participants