-
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] Revisit need of Val
suffix of Value
methods
#6081
Comments
Another option is to ignore the |
Another option is to call |
If we ignore |
I also like |
Yes, if we go with |
This is what we are doing now, it's all zero values, which also means invalid values for complex types like |
There are 3 different parts of the related pdata API that we need to consider additionally in this issue.
Given the 1 and 2/3 are pretty different, I don't think necessary to have method names consistent across them, but we probably need to follow the same pattern for 2 and 3. Approach AOne solution that brings consistency between 2 and 3 setters / getters / type getters is to have the following interface:
func (v Value) Type() ValueType
func (v Value) GetString() string
func (v Value) SetString(val)
func (v Value) GetBool() bool
func (v Value) SetBool(val)
func (v Value) GetMap() Map
func (v Value) SetEmptyMap() Map
func (v Value) SetEmpty() Value
...
func (ms NumberDataPoint) ValueType() NumberDataPointValueType
func (ms NumberDataPoint) DoubleValue() float64
func (ms NumberDataPoint) SetDoubleValue(v float64)
func (ms NumberDataPoint) IntValue() int64
func (ms NumberDataPoint) SetIntValue(v int64)
func (ms Metric) DataType() MetricDataType
func (ms Metric) GaugeData() Gauge
func (ms Metric) SetEmptyGaugeData() Gauge
func (ms Metric) SumData() Sum
func (ms Metric) SetEmptySumData() Sum An open question for this approach whether we want to add The problem is with this option is that setters like Approach BWe can ignore that 2 and 3 goes through a oneof message proxy and apply the same naming as we have in 1: 2 will be: func (ms NumberDataPoint) Type() NumberDataPointValueType
func (ms NumberDataPoint) GetDouble() float64
func (ms NumberDataPoint) SetDouble(v float64)
func (ms NumberDataPoint) GetInt() int64
func (ms NumberDataPoint) SetInt(v int64) 3 will be: func (ms Metric) Type() MetricDataType
func (ms Metric) GetGauge() Gauge
func (ms Metric) SetEmptyGauge() Gauge
func (ms Metric) GetSum() Sum
func (ms Metric) SetEmptySum() Sum The problem with this option is that we potentially can run into a conflict with other fields that possibly can be added to 2 and 3 structs in future. Also Approach CApply approach A with just one exception for getter/setter name that brings inconsistency but provides more user friendly naming. 1 and 2 will be changed as defined in the approach A, but 3 will be kept at it currently is: 3 will be: func (ms Metric) DataType() MetricDataType
func (ms Metric) GetGauge() Gauge
func (ms Metric) SetEmptyGauge() Gauge
func (ms Metric) Sum() Sum
func (ms Metric) SetEmptySum() Sum Same as for approach A, it's an open question if we want to add Approach DAnother otpion is to bring additional structs representing the oneof protobuf message similar to @open-telemetry/collector-approvers please share your thoughts which option sounds better to you Bogdan's Edites:
|
@dmitryax in Approach C you have |
@dmitryax thanks for the writeup this helps a lot. My thinking is a bit different about the Because of that I believe that for metric, I prefer: func (ms Metric) Type() MetricType
func (ms Metric) Gauge() Gauge
func (ms Metric) SetEmptyGauge() Gauge
func (ms Metric) Sum() Sum
func (ms Metric) SetEmptySum() Sum
|
For Approach B part 2, I am missing the risk of func (ms NumberDataPoint) GetDouble() float64
func (ms NumberDataPoint) SetDouble(v float64)
func (ms NumberDataPoint) GetInt() int64
func (ms NumberDataPoint) SetInt(v int64) It feels to me like |
Having the Value in the name suggest that this is a Double entry inside a oneof named Value. But that does not help with conflicts, I would double check but I believe you cannot have another member called Double outside the oneof in the same message, because moving out and inside a oneof is a no op on the wire. |
Generally, I'm leaning towards Approach B. But still not sure if we need to bring If we go with Approach B, I'd like to make sure that it's ok to think about NumberDataPoint/Exemplar as a value itself because it's not only about possible conflicts, it may be that |
Bogdan's summaryRules
Resultspcommon.Value
func (v Value) Type() ValueType
func (v Value) GetString() string
func (v Value) SetString(val)
func (v Value) GetBool() bool
func (v Value) SetBool(val)
func (v Value) GetMap() Map
func (v Value) SetEmptyMap() Map
... pmetric.NumberDataPoint
func (ms NumberDataPoint) ValueType() NumberDataPointValueType
func (ms NumberDataPoint) DoubleValue() float64
func (ms NumberDataPoint) SetDoubleValue(v float64)
func (ms NumberDataPoint) IntValue() int64
func (ms NumberDataPoint) SetIntValue(v int64) pmetric.Metric
func (ms Metric) Type() MetricType
func (ms Metric) Gauge() Gauge
func (ms Metric) SetEmptyGauge() Gauge
func (ms Metric) Sum() Sum
func (ms Metric) SetEmptySum() Sum Action Items
|
@bogdandrutu thanks for providing the summary. I like the proposal. I would vote for adding |
Personally, I am not convinced about the |
* Dreprecate old APIs, add new APIs without "Data" Updates open-telemetry#6081 Signed-off-by: Bogdan <[email protected]>
* Dreprecate old APIs, add new APIs without "Data" Updates open-telemetry#6081 Signed-off-by: Bogdan <[email protected]>
* Dreprecate old APIs, add new APIs without "Data" Updates #6081 Signed-off-by: Bogdan <[email protected]> Signed-off-by: Bogdan <[email protected]>
@bogdandrutu thanks for taking care of the issues discovered above. The only thing left is to decide if we go with the My vote is that we shouldn't implement it unintentionally. But at the same time, I don't like that we add Maybe we can choose another name for string getter/setter? I don't think it's required to call it |
I like |
I like Str. would the final API look like: func (v Value) Type() ValueType
func (v Value) GetStr() string
func (v Value) SetStr(val)
func (v Value) GetBool() bool
func (v Value) SetBool(val)
func (v Value) GetMap() Map
func (v Value) SetEmptyMap() Map
func (v Value) SetEmpty() Value
func (ms NumberDataPoint) ValueType() NumberDataPointValueType
func (ms NumberDataPoint) DoubleValue() float64
func (ms NumberDataPoint) SetDoubleValue(v float64)
func (ms NumberDataPoint) IntValue() int64
func (ms NumberDataPoint) SetIntValue(v int64)
func (ms Metric) Type() MetricType
func (ms Metric) Gauge() Gauge
func (ms Metric) SetEmptyGauge() Gauge
func (ms Metric) Sum() Sum
func (ms Metric) SetEmptySum() Sum |
@TylerHelmuth , no we won't have func (v Value) Type() ValueType
func (v Value) Str() string
func (v Value) SetStr(val)
func (v Value) Bool() bool
func (v Value) SetBool(val)
func (v Value) Map() Map
func (v Value) SetEmptyMap() Map
func (v Value) SetEmpty() Value |
@dmitryax sorry, meant to remove all the Gets. That's what I get for multitasking. |
Ok looks like we have an agreement here. Updated #6099 accordingly |
Currently all the setter and getter methods of
pcommon.Value
end withVal
suffix, e.g.:Value.BoolVal
,Value.SetBoolVal
,Value.MapVal
etc. The only reason for having the suffix is that otherwise we end up with aValue.String
method unintentionally implementingfmt.Stringer
interface.Potentially we can remove the suffix from all the methods except for
Value.StringVal
where we can add an explicit note about the naming. I'm not sure if it's a good enough reason to introduce this exception.We can also keep the existing naming. I just wanted to bring this for discussion before releasing pdata 1.0. I don't have a strong preference.
@open-telemetry/collector-approvers please share your thoughts
The text was updated successfully, but these errors were encountered: