-
Notifications
You must be signed in to change notification settings - Fork 806
feat: add support for metric data-point flags #4916
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ | |
| from opentelemetry.sdk.metrics._internal.measurement import Measurement | ||
| from opentelemetry.sdk.metrics._internal.point import Buckets as BucketsPoint | ||
| from opentelemetry.sdk.metrics._internal.point import ( | ||
| DataPointFlags, | ||
| ExponentialHistogramDataPoint, | ||
| HistogramDataPoint, | ||
| NumberDataPoint, | ||
|
|
@@ -887,10 +888,10 @@ def collect( | |
| offset=value_negative.offset, | ||
| bucket_counts=(value_negative.get_offset_counts()), | ||
| ), | ||
| # FIXME: Find the right value for flags | ||
| flags=0, | ||
| min=min_, | ||
| max=max_, | ||
| # FIXME: Find the right value for flags | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if there is additional work to be done here for determining what exactly the flags should be set to, so I have opted to leave the comment here. |
||
| flags=DataPointFlags.get_default(), | ||
| ) | ||
|
|
||
| # Here collection_temporality is CUMULATIVE. | ||
|
|
@@ -1055,10 +1056,10 @@ def collect( | |
| self._previous_value_negative.get_offset_counts() | ||
| ), | ||
| ), | ||
| # FIXME: Find the right value for flags | ||
| flags=0, | ||
| min=self._previous_min, | ||
| max=self._previous_max, | ||
| # FIXME: Find the right value for flags | ||
| flags=DataPointFlags.get_default(), | ||
| ) | ||
|
|
||
| return None | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,39 @@ | |
| from opentelemetry.util.types import Attributes | ||
|
|
||
|
|
||
| class DataPointFlags(int): | ||
| """A bitmask that represents options specific to the data point. | ||
|
|
||
| The only supported option is the "no recorded value" flag (``0x01``). If | ||
| set, this flag reflects explicitly missing data in a series. It serves as | ||
| an indicator that a previously present timeseries was removed and that | ||
| this timeseries SHOULD NOT be returned in queries after such an indicator | ||
| was received. It is an equivalent of the Prometheus staleness marker. | ||
|
|
||
| If this flag is set, all other data point properties except attributes, | ||
| time stamps, or time windows, SHOULD be ignored. | ||
|
|
||
| See the `OpenTelemetry Data Point Flags`_ spec for details. | ||
|
|
||
| .. _OpenTelemetry Data Point Flags: | ||
| https://opentelemetry.io/docs/specs/otel/metrics/data-model/#data-point-flags | ||
| """ | ||
|
|
||
| DEFAULT = 0x00 | ||
| NO_RECORDED_VALUE = 0x01 | ||
|
|
||
| @classmethod | ||
| def get_default(cls) -> "DataPointFlags": | ||
| return cls(cls.DEFAULT) | ||
|
|
||
| @property | ||
| def no_recorded_value(self) -> bool: | ||
| return bool(self & self.NO_RECORDED_VALUE) | ||
|
|
||
|
|
||
| DEFAULT_DATA_POINT_FLAGS = DataPointFlags.get_default() | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class NumberDataPoint: | ||
| """Single data point in a timeseries that describes the time-varying scalar | ||
|
|
@@ -37,6 +70,7 @@ class NumberDataPoint: | |
| time_unix_nano: int | ||
| value: Union[int, float] | ||
| exemplars: Sequence[Exemplar] = field(default_factory=list) | ||
| flags: DataPointFlags = DEFAULT_DATA_POINT_FLAGS | ||
|
|
||
| def to_json(self, indent: Optional[int] = 4) -> str: | ||
| return dumps(asdict(self), indent=indent) | ||
|
|
@@ -58,6 +92,7 @@ class HistogramDataPoint: | |
| min: float | ||
| max: float | ||
| exemplars: Sequence[Exemplar] = field(default_factory=list) | ||
| flags: DataPointFlags = DEFAULT_DATA_POINT_FLAGS | ||
|
|
||
| def to_json(self, indent: Optional[int] = 4) -> str: | ||
| return dumps(asdict(self), indent=indent) | ||
|
|
@@ -85,10 +120,10 @@ class ExponentialHistogramDataPoint: | |
| zero_count: int | ||
| positive: Buckets | ||
| negative: Buckets | ||
| flags: int | ||
| min: float | ||
| max: float | ||
| exemplars: Sequence[Exemplar] = field(default_factory=list) | ||
| flags: DataPointFlags = DEFAULT_DATA_POINT_FLAGS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is why the public-symbols-check fails but it should be fine with the defined default.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is complaining because specifically the order of these fields are changing (which I've opted to do for consistency). I can move it back, but then the argument order will be inconsistent between the different data-point types. Do we want to just label this as a breaking change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I say do it! |
||
|
|
||
| def to_json(self, indent: Optional[int] = 4) -> str: | ||
| return dumps(asdict(self), indent=indent) | ||
|
|
||
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.
We have a mixture of
DataPointFlags.DEFAULTandDataPointFlags.get_default()in this file, can we consolidate onto the new version?