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

[pdata] Remove Val suffix from pcommon.Value getter/setter methods #6099

Merged
merged 1 commit into from
Sep 27, 2022

Conversation

dmitryax
Copy link
Member

Resolves #6081

@codecov
Copy link

codecov bot commented Sep 16, 2022

Codecov Report

Base: 91.91% // Head: 91.77% // Decreases project coverage by -0.13% ⚠️

Coverage data is based on head (646d1d4) compared to base (a511b16).
Patch coverage: 75.26% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6099      +/-   ##
==========================================
- Coverage   91.91%   91.77%   -0.14%     
==========================================
  Files         217      217              
  Lines       13317    13345      +28     
==========================================
+ Hits        12240    12248       +8     
- Misses        848      868      +20     
  Partials      229      229              
Impacted Files Coverage Δ
pdata/pcommon/generated_primitive_slice.go 100.00% <ø> (ø)
pdata/pcommon/common.go 89.92% <73.25%> (-3.60%) ⬇️
...er/loggingexporter/internal/otlptext/databuffer.go 99.12% <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.

@bogdandrutu
Copy link
Member

I like the new API... Want to hear more opinions. @open-telemetry/collector-approvers ?

@dmitryax
Copy link
Member Author

@bogdandrutu If we merge this, we will still have (Set)[Double|Int]Val methods on pmetric.NumberDataPoint and pmetric.Examplar structs, but I believe it's good to keep the Val suffix there because they have other unrelated fields and they look through another Value entity, so we should keep something related to value in those method names.

@bogdandrutu
Copy link
Member

Maybe that should be Value?

@bogdandrutu
Copy link
Member

@dmitryax what about the metrics data type then? We definitely are not consistent here

@tigrannajaryan
Copy link
Member

I am not sure this is an improvement. Get prefix is explicitly not recommended by Effective Go for getters. Granted, Val suffix is also not pretty.

Minor argument in favour of Val suffix: it is faster to use with autocomplete, less characters to type until you get the right hint.

However, I can live with either approach.

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

I like this a lot. Get and Set feel like natural prefixes for this situation, even if it goes against Go naming standards

@dmitryax
Copy link
Member Author

dmitryax commented Sep 16, 2022

Maybe that should be Value?

Yes, (Set)[Double|Int]Value on pmetric.NumberDataPoint and pmetric.Examplar sounds better to me 👍

@dmitryax what about the metrics data type then? We definitely are not consistent here

We are not, yes. We don't have any prefix or suffix for the metric type getters, it's just Sum(), Gauge() etc. It goes through a oneof protobuf message called Data. I'm not sure what we can do there to bring consistency. Making it SumValue or SumData doesn't feel convenient.

@TylerHelmuth
Copy link
Member

We definitely are not consistent here

This is pretty annoying, and if we can't use Get|Set everywhere then I'd probably vote for consistency over anything else. But if I was a new user to the pdata API, I think GetString and SetString are nicer than StringVal and SetStringVal.

But I also have a bias towards languages with Getters and Setters. An argument could be made that for Go Get isn't the expected name and would throw users off.

@TylerHelmuth
Copy link
Member

it's just Sum(), Gauge()

This makes me really wish we could just do SetString and String. GetSum and GetGauge don't feel right. (Which is maybe a good argument against using Get for Value.)

@bogdandrutu
Copy link
Member

@dmitryax please summarize the conversation in the issue:

  • 4 places where we have this pattern right now (please enumerate them, and add links so people can find them easily), and all somehow inconsistent for naming.
  • Let's play with the proposals: 1. use get/set (see how that impact other places); 2. In case of Metric/Exemplar should we have SumData to be consistent with DoubleValue?

So let's enumerate the rules that we want to apply (or exceptions if any) and apply them and see what we get. By apply just some code snippets it is fine.

Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

I preferred BoolVal to GetBool until I realized that Get would be a better pair to Set in SetBool.

@dmitryax
Copy link
Member Author

Please do not merge until a decision is made on #6081 (comment)

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

To avoid merging until decision in the issue is made

@dmitryax dmitryax force-pushed the replace-val-suffix branch 2 times, most recently from 41c213d to 9391db7 Compare September 26, 2022 23:35
// StringVal returns the string value associated with this Value.
// If the Type() is not ValueTypeString then returns empty string.
// Str returns the string value associated with this Value.
// The shorter name is used instead of String to avoid implementing fmt.Stringer interface.
Copy link
Member

Choose a reason for hiding this comment

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

Consider to have this comment on the "SetStr" as well.

@bogdandrutu bogdandrutu merged commit 8254e36 into open-telemetry:main Sep 27, 2022
@dmitryax dmitryax deleted the replace-val-suffix branch September 27, 2022 16:29
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.

[pdata] Revisit need of Val suffix of Value methods
5 participants