Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mdumandag committed Aug 5, 2021
1 parent 3e990f1 commit 7ea0d8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
52 changes: 26 additions & 26 deletions hazelcast/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ProbeUnit(object):
ENUM = 6
"""0..n, ordinal of an enum."""

# New enum values should be should be converted to a tag to ensure backward
# New enum values should be converted to a tag to ensure backward
# compatibility during compressing the metrics. see ProbeUnit#newUnit
# handling in Java for that. We don't implement this functionality yet in
# the Python client, as we don't use such enum members.
Expand All @@ -112,29 +112,29 @@ class ValueType(object):
class MetricsCompressor(object):
"""Compresses metrics into a ``bytearray`` blob.
The compressor uses dictionary based delta compression and deflates
the resulting ``bytearray`` by using ``zlib.compress()``. This
compressor doesn't use the textual representation of the
:class:`MetricDescriptor` hence it is agnostic to the order of the
tags in that representation.
Adding metrics by calling :func:`add_long` or :func:`add_double`
builds a dictionary by mapping all words found in the passed
:class:`MetricDescriptor`s to ``int``s and these ``int``s will be
written to the resulting ``bytearray`` blob. Before these ``int``s
are written, the current :class:`MetricDescriptor` is compared to the
previous one and only the fields of the descriptor that are different
from the previous will be written to the metrics blob.
When the blob is retrieved from this compressor (when the metrics
collection cycle finishes) the dictionary is stored in the dictionary
blob. The compressor iterates over the words stored in the dictionary
in ascending order and writes them to the blob by skipping the first
N characters that are equal to the first N character of the previously
written word, hence using delta compression here too.
After both the metrics and the dictionary blob is constructed, they
are copied into a final blob in the following structure:
The compressor uses dictionary based delta compression and deflates
the resulting ``bytearray`` by using ``zlib.compress()``. This
compressor doesn't use the textual representation of the
:class:`MetricDescriptor` hence it is agnostic to the order of the
tags in that representation.
Adding metrics by calling :func:`add_long` or :func:`add_double`
builds a dictionary by mapping all words found in the passed
:class:`MetricDescriptor`s to ``int``s and these ``int``s will be
written to the resulting ``bytearray`` blob. Before these ``int``s
are written, the current :class:`MetricDescriptor` is compared to the
previous one and only the fields of the descriptor that are different
from the previous will be written to the metrics blob.
When the blob is retrieved from this compressor (when the metrics
collection cycle finishes) the dictionary is stored in the dictionary
blob. The compressor iterates over the words stored in the dictionary
in ascending order and writes them to the blob by skipping the first
N characters that are equal to the first N character of the previously
written word, hence using delta compression here too.
After both the metrics and the dictionary blob is constructed, they
are copied into a final blob in the following structure:
+--------------------------------+--------------------+
| Compressor version | 2 bytes (short) |
Expand Down Expand Up @@ -213,7 +213,7 @@ def _write_descriptor(self, descriptor):
else:
self._metrics_buf.write_byte(descriptor.unit)

# include excludedTargets and tags bytes for compatibility purposes
# include excludedTargets and tags bits for compatibility purposes
if mask & _MASK_EXCLUDED_TARGETS == 0:
self._metrics_buf.write_byte(0)

Expand Down Expand Up @@ -245,7 +245,7 @@ def _calculate_descriptor_mask(self, descriptor):
if descriptor.unit == last_descriptor.unit:
mask |= _MASK_UNIT

# include excludedTargets and tags bytes for compatibility purposes
# include excludedTargets and tags bits for compatibility purposes
mask |= _MASK_EXCLUDED_TARGETS
mask |= _MASK_TAG_COUNT

Expand Down
6 changes: 4 additions & 2 deletions hazelcast/statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os

from hazelcast.core import CLIENT_TYPE
from hazelcast.invocation import Invocation
Expand All @@ -21,7 +22,6 @@
_KEY_VALUE_SEPARATOR = "="
_EMPTY_ATTRIBUTE_VALUE = ""

_DEFAULT_PROBE_VALUE = 0
_NEAR_CACHE_DESCRIPTOR_PREFIX = "nearcache"
_NEAR_CACHE_DESCRIPTOR_DISCRIMINATOR = "name"

Expand Down Expand Up @@ -94,7 +94,7 @@ def _register_gauges(self):
)
self._register_system_gauge(
"os.systemLoadAverage",
lambda: psutil.cpu_percent(),
lambda: os.getloadavg()[0],
ValueType.DOUBLE,
)
self._register_system_gauge(
Expand Down Expand Up @@ -124,6 +124,7 @@ def _register_gauges(self):
)

def _register_system_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG):
# Try a gauge function read, we will register it if it succeeds.
try:
gauge_fn()
self._registered_system_gauges[gauge_name] = (gauge_fn, value_type)
Expand All @@ -133,6 +134,7 @@ def _register_system_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG
)

def _register_process_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG):
# Try a gauge function read, we will register it if it succeeds.
try:
process = psutil.Process()
gauge_fn(process)
Expand Down

0 comments on commit 7ea0d8c

Please sign in to comment.