in src/lambdas/custodian_metrics_updater/processors/new_metrics_collector.py [0:0]
def collect_metrics_for_customer(self, ctx: MetricsContext):
"""
Collects predefined hard-coded set of reports. Here we definitely know
that all the reports are collected as of "now" date, so we can cache
some sources of data and use lower-level metrics to calculate higher
level
"""
reports = (
ReportType.OPERATIONAL_OVERVIEW,
ReportType.OPERATIONAL_RESOURCES,
ReportType.OPERATIONAL_RULES,
ReportType.OPERATIONAL_FINOPS,
ReportType.C_LEVEL_OVERVIEW,
)
start, end = self.whole_period(ctx.now, *reports)
_LOG.info(f'Need to collect data from {start} to {end}')
jobs = self._ajs.to_ambiguous(
self._ajs.get_by_customer_name(
customer_name=ctx.customer.name,
start=start,
end=end, # todo here end must be not including
ascending=True, # important
)
)
job_source = JobMetricsDataSource(jobs)
if not job_source:
_LOG.warning('No jobs for customer found')
sc_provider = ShardsCollectionProvider(self._rs)
_LOG.info('Generating operational overview for all tenants')
ctx.add_reports(
self.operational_overview(
ctx=ctx,
job_source=job_source,
sc_provider=sc_provider,
report_type=ReportType.OPERATIONAL_OVERVIEW,
)
)
_LOG.info('Generating operational resources for all tenants')
ctx.add_reports(
self.save_data_to_s3(
self.operational_resources(
ctx=ctx,
job_source=job_source,
sc_provider=sc_provider,
report_type=ReportType.OPERATIONAL_RESOURCES,
)
)
)
_LOG.info('Generating operational rules for all tenants')
ctx.add_reports(
self.save_data_to_s3(
self._complete_rules_report(
self.operational_rules(
now=ctx.now,
job_source=job_source,
report_type=ReportType.OPERATIONAL_RULES,
),
ctx,
)
)
)
_LOG.info('Generating operational finops for all tenants')
ctx.add_reports(
self.operational_finops(
ctx=ctx,
job_source=job_source,
sc_provider=sc_provider,
report_type=ReportType.OPERATIONAL_FINOPS,
)
)
# todo operational compliance, attacks, finops, kubernetes
# todo project reports
# todo tops
# todo clevel
collected = bool(
self._rms.get_latest_for_customer(
customer=ctx.customer,
type_=ReportType.C_LEVEL_OVERVIEW,
till=ReportType.C_LEVEL_OVERVIEW.end(ctx.now),
)
)
if not collected:
_LOG.info(
'Generating c-level overview for all tenants because '
'it has not be collected yet'
)
ctx.add_reports(
self.c_level_overview(
ctx=ctx,
job_source=job_source,
sc_provider=sc_provider,
report_type=ReportType.C_LEVEL_OVERVIEW,
)
)
_LOG.info(f'Saving all reports items: {ctx.n_reports}')
self._rms.batch_save(ctx.iter_reports())