def sync(self): """ Synchronizes sample queue to cloud and reschedules sync loop """ if self._samples: chan = ServiceRegistry.get_rpc_channel('metricsd', ServiceRegistry.CLOUD) client = MetricsControllerStub(chan) if self.post_processing_fn: # If services wants to, let it run a postprocessing function # If we throw an exception here, we'll have no idea whether # something was postprocessed or not, so I guess try and make it # idempotent? #m sevchicken self.post_processing_fn(self._samples) samples = self._retry_queue + self._samples metrics_container = MetricsContainer( gatewayId=snowflake.snowflake(), family=samples) future = client.Collect.future(metrics_container, self.grpc_timeout) future.add_done_callback( lambda future: self._loop.call_soon_threadsafe( self.sync_done, samples, future)) self._retry_queue.clear() self._samples.clear() self._loop.call_later(self.sync_interval, self.sync)
def _package_and_send_metrics( self, metrics: [metrics_pb2.MetricFamily], target: ScrapeTarget, ) -> None: """ Send parsed and protobuf-converted metrics to cloud. """ chan = ServiceRegistry.get_rpc_channel( 'metricsd', ServiceRegistry.CLOUD, grpc_options=self._grpc_options, ) client = MetricsControllerStub(chan) for chunk in self._chunk_samples(metrics): metrics_container = MetricsContainer( gatewayId=snowflake.snowflake(), family=chunk, ) future = client.Collect.future( metrics_container, self.grpc_timeout, ) future.add_done_callback( lambda future: self._loop.call_soon_threadsafe( self.scrape_done, future, target, ), ) self._loop.call_later( target.interval, self.scrape_prometheus_target, target, )
def sync(self, service_name): """ Synchronizes sample queue for specific service to cloud and reschedules sync loop """ if service_name in self._samples_for_service and \ self._samples_for_service[service_name]: chan = ServiceRegistry.get_rpc_channel( 'metricsd', ServiceRegistry.CLOUD, grpc_options=self._grpc_options) client = MetricsControllerStub(chan) if self.post_processing_fn: # If services wants to, let it run a postprocessing function # If we throw an exception here, we'll have no idea whether # something was postprocessed or not, so I guess try and make it # idempotent? #m sevchicken self.post_processing_fn( self._samples_for_service[service_name]) samples = self._samples_for_service[service_name] sample_chunks = self._chunk_samples(samples) for idx, chunk in enumerate(sample_chunks): metrics_container = MetricsContainer( gatewayId=snowflake.snowflake(), family=chunk) future = client.Collect.future(metrics_container, self.grpc_timeout) future.add_done_callback( self._make_sync_done_func(service_name, idx)) self._samples_for_service[service_name].clear() self._loop.call_later(self.sync_interval, self.sync, service_name)
def sync(self): """ Synchronizes sample queue to cloud and reschedules sync loop """ if self._samples: chan = ServiceRegistry.get_rpc_channel('metricsd', ServiceRegistry.CLOUD) client = MetricsControllerStub(chan) samples = self._retry_queue + self._samples metrics_container = MetricsContainer( gatewayId=snowflake.snowflake(), family=samples) future = client.Collect.future(metrics_container, self.grpc_timeout) future.add_done_callback( lambda future: self._loop.call_soon_threadsafe( self.sync_done, samples, future)) self._retry_queue.clear() self._samples.clear() self._loop.call_later(self.sync_interval, self.sync)