Skip to content

Commit

Permalink
Tools 2679 show stop writes bug (#210)
Browse files Browse the repository at this point in the history
* fix: TOOLS-2679 show stop-writes does not report storage-engine device or pmem metrics
  • Loading branch information
Jesse S committed Oct 9, 2023
1 parent 2342556 commit c216a0f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 74 deletions.
4 changes: 2 additions & 2 deletions lib/health/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@
stop_writes = select "stop_writes" from NAMESPACE.STATISTICS;
stop_writes = group by CLUSTER, NAMESPACE stop_writes;
ASSERT(stop_writes, False, "Namespace has hit stop-writes (stop_writes = true)", "OPERATIONS" , CRITICAL,
"Listed namespace(s) have hit stop-write. Please run 'show statistics namespace like stop_writes' for details.",
"Listed namespace(s) have hit stop-write. Please run 'show stop-writes' for details.",
"Namespace stop-writes flag check.");
clock_skew_stop_writes = select "clock_skew_stop_writes" from NAMESPACE.STATISTICS;
clock_skew_stop_writes = group by CLUSTER, NAMESPACE clock_skew_stop_writes;
ASSERT(clock_skew_stop_writes, False, "Namespace has hit clock-skew-stop-writes (clock_skew_stop_writes = true)", "OPERATIONS" , CRITICAL,
"Listed namespace(s) have hit clock-skew-stop-writes. Please run 'show statistics namespace like clock_skew_stop_writes' for details.",
"Listed namespace(s) have hit clock-skew-stop-writes. Please run 'show stop-writes' for details.",
"Namespace clock-skew-stop-writes flag check.");
SET CONSTRAINT VERSION < 4.3;
Expand Down
30 changes: 20 additions & 10 deletions lib/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,27 +1623,35 @@ def _create_stop_writes_entry(
node_sw_metrics[(namespace, set_, metric)] = entry


@staticmethod
def _is_stop_writes_cause(
usage: int | float, threshold: int | float, stop_writes: str | None = None
usage: int | float,
threshold: int | float,
stop_writes: str | None = None,
invert: bool = False,
):
if threshold == 0:
return False

if invert:
return (
True
if usage <= threshold
and (stop_writes is None or stop_writes.lower() == "true")
else False
)
return (
True
if usage >= threshold and (stop_writes is None or stop_writes.lower() == "true")
else False
)


@staticmethod
def _get_first_value_from_dict_with_key(
dict_: dict[str, Any],
key: str | tuple,
default_value: Any = None,
return_type: type = str,
) -> Any:
) -> tuple[Any, Any]:
if isinstance(key, str):
key = (key,)

Expand All @@ -1656,7 +1664,6 @@ def _get_first_value_from_dict_with_key(
return None, None


@staticmethod
def _format_ns_stop_writes_metrics(
stop_writes_metrics: StopWritesDict,
service_stats,
Expand Down Expand Up @@ -1754,13 +1761,16 @@ def _format_ns_stop_writes_metrics(
)
config, threshold = _get_first_value_from_dict_with_key(
stats,
("stop-writes-avail-pct", "min-avail-pct"),
(
"storage-engine.stop-writes-avail-pct",
"storage-engine.min-avail-pct",
),
default_value=None,
return_type=int,
)

if metric and usage is not None and threshold is not None:
sw = _is_stop_writes_cause(usage, threshold, stop_writes)
if usage is not None and threshold is not None:
sw = _is_stop_writes_cause(usage, threshold, stop_writes, invert=True)
_create_stop_writes_entry(
stop_writes_metrics[node],
metric,
Expand All @@ -1779,7 +1789,7 @@ def _format_ns_stop_writes_metrics(
)
config, threshold = _get_first_value_from_dict_with_key(
stats,
("stop-writes-used-pct", "max-used-pct"),
("storage-engine.stop-writes-used-pct", "storage-engine.max-used-pct"),
default_value=None,
return_type=int,
)
Expand Down Expand Up @@ -1816,7 +1826,7 @@ def _format_ns_stop_writes_metrics(
)

if usage is not None and threshold is not None and bytes_total is not None:
threshold = int(bytes_total) * (int(threshold) / 100)
threshold = bytes_total * (threshold / 100)
sw = _is_stop_writes_cause(usage, threshold, stop_writes)
_create_stop_writes_entry(
stop_writes_metrics[node],
Expand Down
13 changes: 8 additions & 5 deletions lib/view/sheet/decleration.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,19 @@ def fun(edata: EntryValue):
return fun

@staticmethod
def _fmt_pct_type(val: float):
def _fmt_pct_type(val: float, invert: bool = False):
if invert:
val = 100 - val

return str(round(float(val), 2)) + " %"

@staticmethod
def ratio_to_pct(edata: EntryValue):
return Converters._fmt_pct_type(edata.value * 100)
def ratio_to_pct(edata: EntryValue, invert: bool = False):
return Converters._fmt_pct_type(edata.value * 100, invert)

@staticmethod
def pct(edata: EntryValue):
return Converters._fmt_pct_type(edata.value)
def pct(edata: EntryValue, invert: bool = False):
return Converters._fmt_pct_type(edata.value, invert)


FormatterPredicateFnType = Callable[[EntryData], bool]
Expand Down
33 changes: 27 additions & 6 deletions lib/view/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,8 +1864,14 @@ def stop_writes_converter_selector(edata: EntryData):
return None

metric = edata.record["Metric"]
val = ""

if "pct" in metric:
if "avail" in metric:
val = Converters.pct(edata, invert=True)
val = "(inverted) " + val
return val

return Converters.pct(edata)
if "bytes" in metric:
return Converters.byte(edata)
Expand All @@ -1875,6 +1881,25 @@ def stop_writes_converter_selector(edata: EntryData):
return Converters.scientific_units(edata)


class StopWritesUsagePctProjector(Projectors.Number):
def __init__(self, source, *keys, **kwargs):
"""
Keyword Arguments:
invert -- False by default, if True will return 100 - value.
"""
super().__init__(source, *keys, **kwargs)
self.invert = kwargs.get("invert", False)

def do_project(self, sheet, sources):
data = sources.get("stop_writes", ((), {}))[1]
val = super().do_project(sheet, sources)

if "metric" in data and "avail" in data["metric"]:
val = 100 - val

return _ignore_zero(val)


sw_row_yellow_format = (
Formatters.yellow_alert(lambda edata: edata.record["Stop-Writes"] == True),
)
Expand Down Expand Up @@ -1925,12 +1950,8 @@ def stop_writes_converter_selector(edata: EntryData):
Field(
"Usage%",
Projectors.Div(
Projectors.Number("stop_writes", "metric_usage"),
Projectors.Func(
FieldType.number,
_ignore_zero,
Projectors.Number("stop_writes", "metric_threshold"),
),
StopWritesUsagePctProjector("stop_writes", "metric_usage"),
StopWritesUsagePctProjector("stop_writes", "metric_threshold"),
),
converter=Converters.ratio_to_pct,
formatters=sw_val_red_format + sw_val_yellow_format + sw_row_yellow_format,
Expand Down
Loading

0 comments on commit c216a0f

Please sign in to comment.