-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
pdata
: Add support for optional double fields
#4495
pdata
: Add support for optional double fields
#4495
Conversation
This is the second attempt at adding support for `optional double` fields in opentelemetry-proto. This implementation uses a customtype field in gogo protos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall design is what I had in mind, only small details about how the "pdata" API exposes this.
model/pdata/metrics.go
Outdated
func NewOptionalDouble(val float64) *data.OptionalDouble { | ||
return data.NewOptionalDouble(val) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- "*data.OptionalDouble" is internal so you need to have something like "type OptionalDouble = data.OptionalDouble" and return that at least.
- I think instead of changing
HistogramDataPoint.Sum(OptionalDouble)
we can have the sameHistogramDataPoint.Sum() -> float64
and have aHistogramDataPoint.HasSum() -> bool
?
The following changes were made: - make optional double field non-nullable - update pdata interface to use float64 instead of OptionalDouble type - added HasSum method to HistogramDataPoint - added serialization methods to OptionalDouble
Updated the code based on the feedback. The following changes were made:
NOTE: If this looks like the way we want to go, I still need to update the template for generating the |
Codecov Report
@@ Coverage Diff @@
## main #4495 +/- ##
==========================================
- Coverage 90.77% 90.74% -0.04%
==========================================
Files 179 180 +1
Lines 10412 10443 +31
==========================================
+ Hits 9452 9477 +25
- Misses 743 749 +6
Partials 217 217
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a lot to make this work with typecast as well as customtype, none of them really worked :( since the generated code either changes the field type (which will change the generated code) or does not know how to handle a pointer for a primitive float64:
See:
if m.Sum != nil {
if m.Sum != 0 {
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.Sum))))
i--
dAtA[i] = 0x29
}
}
This should be:
if m.Sum != nil {
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(*m.Sum))))
i--
dAtA[i] = 0x29
}
We have some options:
- Change the generate code as well since there are 1-2 presence. We can do this to unblock the optional.
- Move forward with @jsuereth prototype.
- Try to use https://github.com/planetscale/vtprotobuf, it seems to be an active community and probably we can make further improvements there.
- My long-term dream do a lazy custom parser. Probably lots of work for the moment.
@@ -234,14 +234,14 @@ func initHistogramMetric(hm pdata.Metric) { | |||
hdp0.SetStartTimestamp(TestMetricStartTimestamp) | |||
hdp0.SetTimestamp(TestMetricTimestamp) | |||
hdp0.SetCount(1) | |||
hdp0.SetSum(15) | |||
hdp0.SetSum(float64(15)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
// OptionalDouble is a custom data type that is used for all optional double fields in OTLP | ||
// Protobuf messages. | ||
type OptionalDouble struct { | ||
orig *types.DoubleValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pointer? Feels like unnecessary allocation.
|
||
// MarshalTo converts OptionalDouble into a binary representation. Called by Protobuf serialization. | ||
func (m *OptionalDouble) MarshalTo(data []byte) (n int, err error) { | ||
return m.orig.MarshalTo(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect since the types.DoubleValue
is a message with the float at ID=1 (see the https://github.com/gogo/protobuf/blob/v1.3.2/types/wrappers.pb.go#L1263). You need to only put the float value the ID will be filled by the parent.
1 : so far this option seems pretty hacky, I could continue down this road but I'm not sure if I should. 2 & 3: if 4: my long term dream is not thinking about protobuf 🤣 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had a comment on the library being used here.
package data // import "go.opentelemetry.io/collector/model/internal/data" | ||
|
||
import ( | ||
"github.com/gogo/protobuf/types" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bogdandrutu ,
This project is currently unmaintained, is there any reason why not to use https://github.com/golang/protobuf ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MovieStoreGuy you can see more details on the discussion about what to do w/ gogo in the proto repo PR open-telemetry/opentelemetry-proto#336
Ultimately it comes down to performance, which is why we're investigating alternatives.
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@codeboten not sure if this is still needed, I think we discussed what we needed. Feel free to reopen. |
Thx, it's not related. Hi Bogdan, do you think it's related to #5409 or not? Thanks! |
Description:
This is the second attempt at adding support for
optional double
fields in opentelemetry-proto. This implementation uses a customtype field in gogo protos.Link to tracking Issue: #4258
Testing: Added unit tests