Skip to content

Commit

Permalink
Add _ViewInstrumentMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Nov 28, 2021
1 parent 60eccf4 commit ed0e517
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from threading import Lock
from typing import Callable, Dict, List

from opentelemetry.sdk._metrics.aggregation import Aggregation
Expand All @@ -31,7 +32,38 @@ def __init__(
exemplar_reservoir: Callable,
resource: Resource,
):
pass
self._name = name
self._unit = unit
self._description = description

if attribute_keys is None:
self._attribute_keys = set()
else:
self._attribute_keys = set(attribute_keys.items())

self._extra_dimensions = extra_dimensions
self._aggregation = aggregation
self._exemplar_reservoir = exemplar_reservoir
self._attributes_aggregation = {}
self._lock = Lock()

def _process(self, measurement: Measurement) -> None:
pass

if measurement.attributes is None:
attributes = {}

else:
attributes = measurement.attributes

attributes = frozenset(
set(attributes).difference(self._attribute_keys)
)

if attributes not in self._attributes_aggregation.keys():
# FIXME how to handle aggregations that support config?
with self._lock:
self._attributes_aggregation[attributes] = self._aggregation[
attributes
]

self._attributes_aggregation[attributes].aggregate(measurement.amount)

0 comments on commit ed0e517

Please sign in to comment.