ferruzzi commented on code in PR #31725:
URL: https://github.com/apache/airflow/pull/31725#discussion_r1222244685
##########
airflow/metrics/otel_logger.py:
##########
@@ -235,6 +301,57 @@ def del_counter(self, name: str, attributes: Attributes =
None) -> None:
if key in self.map.keys():
del self.map[key]
+ def set_value(self, name: str, value: float, delta: bool, tags:
Attributes):
+ """
+ Overrides the last reading for a Gauge with a new value.
+
+ :param name: The name of the gauge to record.
+ :param value: The new reading to record.
+ :param delta: If True, value is added to the previous reading, else it
overrides.
+ :param tags: Gauge attributes which were used to generate a unique key
to store the counter.
+ :returns: None
+ """
+ key: str = _generate_key_name(name, tags)
+ old_value = self.poke_gauge(name, tags)
+ # If delta is true, add the new value to the last reading otherwise
overwrite it.
+ self.map[key] = Observation(value + (delta * old_value), tags)
Review Comment:
Yup, python will happily treat True as 1; None and False are 0. :)
Another handy use for that is if you want to see how many Trues you have,
you can use sum, like "How many names contain the letter A?" could be `sum(['A'
in name for name in names])` You'll end up with a list[bool] containing both
True and False values, and sum() will add all the 1's and 0's accordingly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]