def _get_metadata(self, resource_type, transformers): info = {} try: met = list(METRICS_CONF['metrics_units'][resource_type].values()) info['unit'] = met[0]['unit'] # NOTE(mc): deprecated second try kept for backward compatibility. except KeyError: LOG.warning('Error when trying to use yaml metrology conf.') LOG.warning('Fallback on the deprecated oslo config method.') try: info['unit'] = self.units_mappings[resource_type][1] except (KeyError, IndexError): info['unit'] = self.default_unit[1] start = ck_utils.dt2ts(ck_utils.get_month_start()) end = ck_utils.dt2ts(ck_utils.get_month_end()) try: resource = self.active_resources(resource_type, start, end, None)[0] except IndexError: resource = {} info['metadata'] = resource.get('dimensions', {}).keys() try: service_metrics = METRICS_CONF['services_metrics'][resource_type] for service_metric in service_metrics: metric, statistics = list(service_metric.items())[0] info['metadata'].append(metric) # NOTE(mc): deprecated second try kept for backward compatibility. except KeyError: LOG.warning('Error when trying to use yaml metrology conf.') LOG.warning('Fallback on the deprecated oslo config method.') try: for metric, statistics in self.metrics_mappings[resource_type]: info['metadata'].append(metric) except (KeyError, IndexError): pass return info
def _get_metadata(self, resource_type, transformers, conf): info = {} info['unit'] = conf['metrics'][resource_type]['unit'] start = ck_utils.dt2ts(ck_utils.get_month_start()) end = ck_utils.dt2ts(ck_utils.get_month_end()) try: resource = self.active_resources( resource_type, start, end, None, )[0] except IndexError: resource = {} info['metadata'] = resource.get('dimensions', {}).keys() service_metrics = METRICS_CONF['services_metrics'][resource_type] for service_metric in service_metrics: metric, statistics = list(service_metric.items())[0] info['metadata'].append(metric) return info
def last_month(): month_start = ck_utils.get_month_start() month_end = ck_utils.get_month_end() start_ts = ck_utils.dt2ts(month_start) end_ts = ck_utils.dt2ts(month_end) return start_ts, end_ts
def test_month_end_without_dt(self, patch_utcnow_mock): date = datetime.datetime(2014, 1, 31) trans_dt = ck_utils.get_month_end() self.assertEqual(date, trans_dt) patch_utcnow_mock.assert_called_once_with()