Limit size of statistics history, updated naming of some variables
@@ -23,6 +23,7 @@ from fledge.common import logger
from fledge.services.core.api.service import get_service_records
from fledge.common.common import _FLEDGE_ROOT, _FLEDGE_DATA
from fledge.common.configuration_manager import ConfigurationManager
+from fledge.common.storage_client import payload_builder
__author__ = "Amarendra K Sinha"
@@ -71,7 +72,7 @@ class SupportBuilder:
cf_mgr = ConfigurationManager(self._storage)
try:
south_cat = await cf_mgr.get_category_child("South")
- south_categories = [nc["key"] for nc in south_cat]
+ south_categories = [sc["key"] for sc in south_cat]
for service in south_categories:
self.add_syslog_service(pyz, file_spec, service)
except:
@@ -79,8 +80,8 @@ class SupportBuilder:
try:
north_cat = await cf_mgr.get_category_child("North")
north_categories = [nc["key"] for nc in north_cat]
- for service in north_categories:
- self.add_syslog_service(pyz, file_spec, service)
+ for task in north_categories:
+ self.add_syslog_service(pyz, file_spec, task)
except:
pass
await self.add_table_configuration(pyz, file_spec)
@@ -144,7 +145,7 @@ class SupportBuilder:
# The fledge entries from the syslog file
temp_file = self._interim_file_path + "/" + "syslog-{}-{}".format(service, file_spec)
try:
- subprocess.call("grep '{}' {} > {}".format(service, _SYSLOG_FILE, temp_file), shell=True)
+ subprocess.call("grep '{}\\[' {} > {}".format(service, _SYSLOG_FILE, temp_file), shell=True)
except OSError as ex:
raise RuntimeError("Error in creating {}. Error-{}".format(temp_file, str(ex)))
pyz.add(temp_file, arcname=basename(temp_file))
@@ -173,9 +174,13 @@ class SupportBuilder:
self.write_to_tar(pyz, temp_file, data)
async def add_table_statistics_history(self, pyz, file_spec):
- # The contents of the audit log from the storage layer
+ # The contents of the statistics history from the storage layer
temp_file = self._interim_file_path + "/" + "statistics-history-{}".format(file_spec)
- data = await self._storage.query_tbl("statistics_history")
+ payload = payload_builder.PayloadBuilder() \
+ .LIMIT(1000) \
+ .ORDER_BY(['history_ts', 'DESC']) \
+ .payload()
+ data = await self._storage.query_tbl_with_payload("statistics_history", payload)
self.write_to_tar(pyz, temp_file, data)
def add_service_registry(self, pyz, file_spec):
