

def flush(self):
    cur_time = time()
    flush_cutoff_time = self.calculate_bucket_start(cur_time)
    expiry_timestamp = (cur_time - self.expiry_seconds)
    metrics = []
    if self.metric_by_bucket:
        for bucket_start_timestamp in sorted(self.metric_by_bucket.keys()):
            metric_by_context = self.metric_by_bucket[bucket_start_timestamp]
            if (bucket_start_timestamp < flush_cutoff_time):
                not_sampled_in_this_bucket = self.last_sample_time_by_context.copy()
                for (context, metric) in metric_by_context.items():
                    if (metric.last_sample_time < expiry_timestamp):
                        log.warning(("%s hasn't been submitted in %ss. Expiring." % (context, self.expiry_seconds)))
                        not_sampled_in_this_bucket.pop(context, None)
                        self.last_sample_time_by_context.pop(context, None)
                    else:
                        metrics += metric.flush(bucket_start_timestamp, self.interval)
                        if isinstance(metric, Counter):
                            self.last_sample_time_by_context[context] = metric.last_sample_time
                            not_sampled_in_this_bucket.pop(context, None)
                self.create_empty_metrics(not_sampled_in_this_bucket, expiry_timestamp, bucket_start_timestamp, metrics)
                del self.metric_by_bucket[bucket_start_timestamp]
    elif (flush_cutoff_time >= (self.last_flush_cutoff_time + self.interval)):
        self.create_empty_metrics(expiry_timestamp.last_sample_time_by_context.copy(), expiry_timestamp, (flush_cutoff_time - self.interval), metrics)
    if (self.num_discarded_old_points > 0):
        log.warn(('%s points were discarded as a result of having an old timestamp' % self.num_discarded_old_points))
        self.num_discarded_old_points = 0
    log.debug(('received %s payloads since last flush' % self.count))
    self.total_count += self.count
    self.count = 0
    self.current_bucket = None
    self.current_mbc = {
        
    }
    self.last_flush_cutoff_time = flush_cutoff_time
    return metrics

dataset/ETHPy150Open serverdensity/sd-agent/aggregator.py MetricsBucketAggregator.flush/VarMisuse@250/414 `self`->`expiry_timestamp`