summaryrefslogtreecommitdiff
path: root/robusta_krr/formatters
diff options
context:
space:
mode:
authorПавел Жуков <33721692+LeaveMyYard@users.noreply.github.com>2023-03-20 20:21:42 +0200
committerПавел Жуков <33721692+LeaveMyYard@users.noreply.github.com>2023-03-20 20:21:42 +0200
commit07a1bb1dc504dac31bfe17d68e72981c1c2a045a (patch)
treec526198179e538ed8ec66ca5145916c7f3f2bda8 /robusta_krr/formatters
parentf3f0b6c5d515ff0cca06c96f4c7296eaf0343970 (diff)
Fix prometheus integration
Diffstat (limited to 'robusta_krr/formatters')
-rw-r--r--robusta_krr/formatters/__init__.py1
-rw-r--r--robusta_krr/formatters/pprint.py23
-rw-r--r--robusta_krr/formatters/table.py10
3 files changed, 32 insertions, 2 deletions
diff --git a/robusta_krr/formatters/__init__.py b/robusta_krr/formatters/__init__.py
index cdb12bb..0fc1c80 100644
--- a/robusta_krr/formatters/__init__.py
+++ b/robusta_krr/formatters/__init__.py
@@ -1,3 +1,4 @@
from .json import JSONFormatter
+from .pprint import PPrintFormatter
from .table import TableFormatter
from .yaml import YAMLFormatter
diff --git a/robusta_krr/formatters/pprint.py b/robusta_krr/formatters/pprint.py
new file mode 100644
index 0000000..bdfcc4c
--- /dev/null
+++ b/robusta_krr/formatters/pprint.py
@@ -0,0 +1,23 @@
+from __future__ import annotations
+
+from pprint import pformat
+
+from robusta_krr.core.abstract.formatters import BaseFormatter
+from robusta_krr.core.models.result import Result
+
+
+class PPrintFormatter(BaseFormatter):
+ """Formatter for object output with python's pprint module."""
+
+ __display_name__ = "pprint"
+
+ def format(self, result: Result) -> str:
+ """Format the result using pprint.pformat(...)
+
+ :param result: The results to format.
+ :type result: :class:`core.result.Result`
+ :returns: The formatted results.
+ :rtype: str
+ """
+
+ return pformat(result.dict())
diff --git a/robusta_krr/formatters/table.py b/robusta_krr/formatters/table.py
index 9eda49e..327d66a 100644
--- a/robusta_krr/formatters/table.py
+++ b/robusta_krr/formatters/table.py
@@ -12,6 +12,7 @@ from robusta_krr.utils import resource_units
NONE_LITERAL = "none"
NAN_LITERAL = "?"
PRESCISION = 4
+ALLOWED_DIFFERENCE = 0.05
class TableFormatter(BaseFormatter):
@@ -28,10 +29,13 @@ class TableFormatter(BaseFormatter):
return resource_units.format(value, prescision=prescision)
def _format_request_str(self, item: ResourceScan, resource: ResourceType, selector: str) -> str:
+ allocated = getattr(item.object.allocations, selector)[resource]
+ recommended = getattr(item.recommended, selector)[resource]
+
return (
- self._format_united_decimal(getattr(item.object.allocations, selector)[resource])
+ self._format_united_decimal(allocated)
+ " -> "
- + self._format_united_decimal(getattr(item.recommended, selector)[resource], prescision=PRESCISION)
+ + self._format_united_decimal(recommended, prescision=PRESCISION)
)
def format(self, result: Result) -> Table:
@@ -49,6 +53,7 @@ class TableFormatter(BaseFormatter):
table.add_column("Cluster", style="cyan")
table.add_column("Namespace", style="cyan")
table.add_column("Name", style="cyan")
+ table.add_column("Pods", style="cyan")
table.add_column("Type", style="cyan")
table.add_column("Container", style="cyan")
for resource in ResourceType:
@@ -69,6 +74,7 @@ class TableFormatter(BaseFormatter):
item.object.cluster if full_info_row else "",
item.object.namespace if full_info_row else "",
item.object.name if full_info_row else "",
+ str(len(item.object.pods)) if full_info_row else "",
item.object.kind if full_info_row else "",
item.object.container,
*[