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

Add specification of metric instrument units #1177

Closed
wants to merge 10 commits into from

Conversation

justinfoote
Copy link
Member

@justinfoote justinfoote commented Nov 2, 2020

Fixes #705

Changes

This PR adds some requirements about units for Metric Instruments.

I made some decisions that I'd love feedback on:

  1. We will not do any reaggregation or reconciliation of units in the SDK (this is to eliminate the need to parse unit strings or provide a more feature-rich units API, which is a long rabbit hole).
  2. Metric instruments should assume that any unit string they get is valid.
  3. I have left it up to API implementors to decide whether to provide constants or composition functions for the required units.
  4. I've identified a handful of base units, along with a few prefixes that we consider important. I chose these based on the current semantic conventions, and I included a few other frequently used units. As we write more semantic conventions, we should add more units as needed.
  5. I chose the case-insensitive form from the UCUM specification. I'm willing to be convinced that I made the wrong choice here. This is the guidance from UCUM:

    Some computer systems or programming languages still have the requirement of case insensitivity and some humans who are not familiar with SI units tend to confuse upper and lower case or can not interpret the difference in upper and lower case correctly. For this reason the case insensitive symbols are defined. Although The Unified Code for Units of Measure does not encourage use of case insensitive symbols where not absolutely necessary, in some circumstances the case insensitive representation may be the greatest common denominator. Thus some systems that can handle case sensitivity may end up using case insensitive symbols in order to communicate with less powerful systems.

@justinfoote justinfoote requested review from a team November 2, 2020 18:00
Implementors may choose the correct prefix to use for the scale of values being
measured. The choice of prefix may affect the value type to be recorded.

> Example: it may be reasonable to record time as an integer when using an
Copy link
Member Author

Choose a reason for hiding this comment

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

@aabmass - I didn't see your comment on #705 before I wrote this up. I'd love your feedback about the wording of this section. How can we add the guidance you were suggesting (if the values to be recorded are whole numbers, instrumenters should prefer recording in a smaller unit (like nanoseconds) rather than recording a floating point in a larger unit)

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if others think this is a good idea in the first place. The reason I suggested it is:

  • Higher precision
  • Potentially smaller on wire if we ever switched OTLP to varint

However, Prometheus recommends base units (seconds) and statsd uses milliseconds for time. Is the gain in precision worth it over sticking to prior art? There is also a concern of overflow for very large values, but I can't think of an actual example that would overflow.

specification/metrics/api.md Outdated Show resolved Hide resolved
specification/metrics/api.md Outdated Show resolved Hide resolved

Metric instruments SHOULD NOT validate that the unit string passed to them is a
valid value. The default unit to be used by a metric instrument when unit is not
provided SHOULD be the non-annotated unity unit (that is: `1`).
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry a bit about the use of units jargon that may be lost on our readers. On the other hand, I want to embrace it. We should introduce terms to explain the syntax, like "{thing}" is a unity unit counting a quanity of things, to start with, so that a non-annotated unity unit is what you get when all you know is "quantity of things".

Also in the UCUM document, the terms "metric" vs "nonmetric". I'm afraid we also use the term "metric", so this overloading can be confusing, but it's also quite handy.

Some of the lingering confusion about the choice between ValueRecorder/ValueObserver (a.k.a. "Grouping" instruments) vs the others (a.k.a. "Adding" instruments) can be reflected in terms used in the UCUM document.

For example,

Furthermore, for a unit to be metric it must be a quantity on a ratio scale where multiplication and division with scalars are defined.

I think we can say you SHOULD NOT use a nonmetric unit with an Adding instrument.

Those symbols that are used as units that imply a measurement on a scale other than a ratio scale (e.g., interval scale, logarithmic scale) are defined differently. These do not represent proper units as elements of the group (U,·). Therefore those special semantic entities are called special units, as opposed to proper units.

We could say that ValueRecorder/ValueObserver may be used with metric and nonmetric units, on the other hand, and the API has no way to say which it is. We might say that when you use a Grouping instrument for inputs with known-proper units, we can always correctly aggregate these using a sum (because they are "metric"). The SDK can automatically switch between sum and histogram aggregation when units are proper.

Just encouraging you to add a bit more , if you're up to it. 😀

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, after giving this some thought, I think I'm in favor of less jargon.

  • I want to remove the term Unity. In the semantic convention table, I'd prefer we use the name none, to indicate that this is an instrument measuring something unitless.
  • I don't love the idea of introducing a new definition of the term metric. In this case, it means a unit that can be meaningfully scaled, especially by orders of magnitude. (They bring up the example that celsius is not metric, even though the SI allows metric prefixes to be used with it, because, for example, 30 celsius is not 3 times hotter than 10 celsius.) This definition is so enormously different from those used elsewhere in the spec, I think it's inviting misunderstanding.
  • While I could certainly see the convenience of an SDK choosing the appropriate aggregator based on the units of the instrument, I fear that it's putting too much meaning into a value that I don't think the SDK should need to reason about. There is a lot of meaning that our SDKs could parse out of the units field, but it's a slippery slope. This is part of why this PR took me so long to write -- I kept adding a whole bunch of complexity, then I'd have to scale it back and delete a bunch of paragraphs.
  • Having said all that, I would be in favor of adding guidance about what sort of units to use with adding or grouping instruments; I think that would be useful. I'll try putting something like that together today.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about "identity unit"? "unitless unit"?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I think I prefer unitless.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with unitless for now. I'm open to more feedback about it. Naming things is hard.

@justinfoote
Copy link
Member Author

Hey, anyone who's interested in seeing this PR merged, I'd love to get my build-tools PR reviewed. It generates markdown and code for these units. Find it here: open-telemetry/build-tools#21

@github-actions
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 28, 2020
@MrAlias MrAlias removed the Stale label Nov 30, 2020
@jgals
Copy link

jgals commented Dec 4, 2020

@justinfoote and @jmacd, I'm commenting here to avoid having this PR closed by the bot. 🤖

| operations | operations | {operations} |
| packets | packets | {packets} |
| processes | processes | {processes} |
| threads | threads | {threads} |
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to put these into some yaml so the could be auto-generated to support them?

Copy link
Contributor

Choose a reason for hiding this comment

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

(as a TODO?)

Copy link
Member Author

Choose a reason for hiding this comment

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

💯 There is a corresponding PR here: open-telemetry/build-tools#21

I had considered adding the yaml to this PR according to that proposal, but I thought it more prudent to wait until that PR merges. It's looking like that's imminent, so maybe I'll go ahead and add the yaml now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added the yaml and the generated markdown table in 6fe5382.
This introduces a hard dependency between these PRs though. We can't merge this one until the build-tools one is merged.

spec-compliance-matrix.md Outdated Show resolved Hide resolved

Metric instruments SHOULD NOT validate that the unit string passed to them is a
valid value. The default unit to be used by a metric instrument when unit is not
provided SHOULD be the non-annotated unity unit (that is: `1`).
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "identity unit"? "unitless unit"?

@github-actions
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Dec 22, 2020
@github-actions github-actions bot removed the Stale label Jan 5, 2021
@github-actions
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added Stale and removed Stale labels Jan 12, 2021
Copy link
Contributor

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

Thank you @justinfoote

@jmacd
Copy link
Contributor

jmacd commented Jan 13, 2021

@open-telemetry/specs-metrics-approvers please review.

@github-actions
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jan 21, 2021
@arminru arminru requested a review from a team January 21, 2021 17:53
@jmacd jmacd removed the Stale label Jan 21, 2021
Base automatically changed from master to main January 27, 2021 21:16
@github-actions
Copy link

github-actions bot commented Feb 4, 2021

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Feb 4, 2021
@github-actions
Copy link

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Feb 11, 2021
@weyert
Copy link

weyert commented Mar 25, 2021

@jmacd @justinfoote @open-telemetry/specs-metrics-approvers Was it intended to close this PR?

@jmacd
Copy link
Contributor

jmacd commented Mar 25, 2021

@weyert I ❤️ this PR and want to get it approved.

@jmacd jmacd reopened this Mar 25, 2021
@github-actions github-actions bot removed the Stale label Mar 26, 2021
@github-actions
Copy link

github-actions bot commented Apr 3, 2021

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 3, 2021
@github-actions
Copy link

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Apr 11, 2021
@Oberon00
Copy link
Member

In the context of open-telemetry/build-tools#65, this came up again. Do you still plan to merge this? If so, would someone care to update the generator docs to document this "unit" feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standardization of Units needed
8 participants