prometheus / prometheus/OpenMetrics
proto: Problem differentiating not-set value from default value
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.5k
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Description
Problem
The OpenMetrics Protobuf specification is using the proto3 syntax.
With the proto3 syntax all fields are optional by default. This is not to be confused with null-able. While one can choose not to specify a field it is then represented by its default value. Someone receiving a proto3 encoded payload has no way to tell the difference between a field explicitly set to its default value or not set at all.
The most prominent case where this can be problematic is for boolean fields where both the default value and the not-set value is false. In the context of OpenMetrics, as far as I can tell, one problematic example would be the examplar field in the CounterValue message. A use can not tell the difference between a not-set examplar and an examplar set to 0.
Solution
To solve the above I see 3 solutions:
- The
optionalkeyword, which would allow differentiating between a default value and a not-set value, was initially removed with theproto3syntax, but has been revived with v3.12.0. In case requiring protocv3.12.0is fine, one could just make use of the revivedoptionalkeyword. - The
optionalkeyword is just syntactic sugar foroneof. Thus, in case requiring protocv3.12.0is not an option, one can useoneofdirectly. See this stackoverflow answer. - Use
proto2instead ofproto3(see original Prometheus proto definition).
Further reading
- General Stackoverflow discussing
optionalinproto3. - Protoc release introducing
optionaltoproto3. - Documentation on field presence.
What do people think? Do you see alternative approaches?
Given that I don't have much expertise with Protobuf I might be missing something. If so, I would appreciate an answer pointing out my mistake.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with proto/openmetrics_data_model.proto around lines 109-123 and review the linked OpenMetrics Protobuf specification. Compare the referenced Prometheus metrics.proto definition and the three proposed approaches, then establish which field-presence behavior the schema should support and how completion would be verified.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100