def publish_counters(self, context, counters, source): """Send a metering message for publishing :param context: Execution context from the service or RPC call :param counter: Counter from pipeline after transformation :param source: counter source """ meters = [ meter_api.meter_message_from_counter(counter, cfg.CONF.metering_secret, source) for counter in counters ] topic = cfg.CONF.metering_topic msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': meters}, } LOG.debug('PUBLISH: %s', str(msg)) rpc.cast(context, topic, msg) for meter_name, meter_list in itertools.groupby( sorted(meters, key=lambda m: m['counter_name']), lambda m: m['counter_name']): msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': list(meter_list)}, } rpc.cast(context, topic + '.' + meter_name, msg)
def _process_queue(queue, policy): #note(sileht): # the behavior of rpc.cast call depends of rabbit_max_retries # if rabbit_max_retries <= 0: # it returns only if the msg has been sent on the amqp queue # if rabbit_max_retries > 0: # it raises a exception if rabbitmq is unreachable # # Ugly, but actually the oslo.rpc do a sys.exit(1) instead of a # RPCException, so we catch both until a correct behavior is # implemented in oslo # # the default policy just respect the rabbitmq configuration # nothing special is done if rabbit_max_retries <= 0 # and exception is reraised if rabbit_max_retries > 0 while queue: context, topic, msg = queue[0] try: rpc.cast(context, topic, msg) except (SystemExit, rpc.common.RPCException): samples = sum([len(m['args']['data']) for _, _, m in queue]) if policy == 'queue': LOG.warn("Failed to publish %s samples, queue them", samples) return queue elif policy == 'drop': LOG.warn("Failed to publish %d samples, dropping them", samples) return [] # default, occur only if rabbit_max_retries > 0 raise else: queue.pop(0) return []
def publish_counters(self, context, counters, source): """Send a metering message for publishing :param context: Execution context from the service or RPC call :param counter: Counter from pipeline after transformation :param source: counter source """ meters = [ meter_message_from_counter( counter, cfg.CONF.publisher_rpc.metering_secret, source) for counter in counters ] topic = cfg.CONF.publisher_rpc.metering_topic msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': meters}, } LOG.debug('PUBLISH: %s', str(msg)) rpc.cast(context, topic, msg) for meter_name, meter_list in itertools.groupby( sorted(meters, key=lambda m: m['counter_name']), lambda m: m['counter_name']): msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': list(meter_list)}, } rpc.cast(context, topic + '.' + meter_name, msg)
def cast(self, context, msg, topic=None, version=None): """rpc.cast() a remote method. :param context: The request context :param msg: The message to send, including the method and args. :param topic: Override the topic for this message. :param version: (Optional) Override the requested API version in this message. :returns: None. rpc.cast() does not wait on any return value from the remote method. """ self._set_version(msg, version) rpc.cast(context, self._get_topic(topic), msg)
def publish_counter(context, counter): """Send a metering message for the data represented by the counter. :param context: Execution context from the service or RPC call :param counter: ceilometer.counter.Counter instance """ msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': { 'data': meter.meter_message_from_counter(counter), }, } LOG.debug('PUBLISH: %s', str(msg)) rpc.cast(context, cfg.CONF.metering_topic, msg) rpc.cast(context, cfg.CONF.metering_topic + '.' + counter.name, msg)
def publish_counter(context, counter): """Send a metering message for the data represented by the counter. :param context: Execution context from the service or RPC call :param counter: ceilometer.counter.Counter instance """ msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': meter.meter_message_from_counter(counter), }, } LOG.debug('PUBLISH: %s', str(msg)) rpc.cast(context, cfg.CONF.metering_topic, msg) rpc.cast(context, cfg.CONF.metering_topic + '.' + counter.name, msg)
def flush(self): #note(sileht): # the behavior of rpc.cast call depends of rabbit_max_retries # if rabbit_max_retries <= 0: # it returns only if the msg has been sent on the amqp queue # if rabbit_max_retries > 0: # it raises a exception if rabbitmq is unreachable # # Ugly, but actually the oslo.rpc do a sys.exit(1) instead of a # RPCException, so we catch both until a correct behavior is # implemented in oslo # # the default policy just respect the rabbitmq configuration # nothing special is done if rabbit_max_retries <= 0 # and exception is reraised if rabbit_max_retries > 0 while self.local_queue: context, topic, msg = self.local_queue[0] try: rpc.cast(context, topic, msg) except (SystemExit, rpc.common.RPCException): if self.policy == 'queue': LOG.warn("Failed to publish counters, queue them") queue_length = len(self.local_queue) if queue_length > self.max_queue_length > 0: count = queue_length - self.max_queue_length self.local_queue = self.local_queue[count:] LOG.warn("Publisher max queue length is exceeded, " "dropping %d oldest counters", count) break elif self.policy == 'drop': counters = sum([len(m['args']['data']) for _, _, m in self.local_queue]) LOG.warn( "Failed to publish %d counters, dropping them", counters) self.local_queue = [] break else: # default, occur only if rabbit_max_retries > 0 self.local_queue = [] raise else: self.local_queue.pop(0)
def flush(self): #note(sileht): # the behavior of rpc.cast call depends of rabbit_max_retries # if rabbit_max_retries <= 0: # it returns only if the msg has been sent on the amqp queue # if rabbit_max_retries > 0: # it raises a exception if rabbitmq is unreachable # # Ugly, but actually the oslo.rpc do a sys.exit(1) instead of a # RPCException, so we catch both until a correct behavior is # implemented in oslo # # the default policy just respect the rabbitmq configuration # nothing special is done if rabbit_max_retries <= 0 # and exception is reraised if rabbit_max_retries > 0 while self.local_queue: context, topic, msg = self.local_queue[0] try: rpc.cast(context, topic, msg) except (SystemExit, rpc.common.RPCException): if self.policy == 'queue': LOG.warn("Failed to publish counters, queue them") queue_length = len(self.local_queue) if queue_length > self.max_queue_length > 0: count = queue_length - self.max_queue_length self.local_queue = self.local_queue[count:] LOG.warn( "Publisher max queue length is exceeded, " "dropping %d oldest counters", count) break elif self.policy == 'drop': counters = sum([ len(m['args']['data']) for _, _, m in self.local_queue ]) LOG.warn("Failed to publish %d counters, dropping them", counters) self.local_queue = [] break else: # default, occur only if rabbit_max_retries > 0 self.local_queue = [] raise else: self.local_queue.pop(0)
def publish_counters(self, context, counters, source): """Publish counters on RPC. :param context: Execution context from the service or RPC call. :param counters: Counters from pipeline after transformation. :param source: Counter source. """ meters = [ meter_message_from_counter( counter, cfg.CONF.publisher_rpc.metering_secret, source) for counter in counters ] topic = cfg.CONF.publisher_rpc.metering_topic msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': meters}, } LOG.audit('Publishing %d counters on %s', len(msg['args']['data']), topic) rpc.cast(context, topic, msg) if self.per_meter_topic: for meter_name, meter_list in itertools.groupby( sorted(meters, key=operator.itemgetter('counter_name')), operator.itemgetter('counter_name')): msg = { 'method': 'record_metering_data', 'version': '1.0', 'args': {'data': list(meter_list)}, } topic_name = topic + '.' + meter_name LOG.audit('Publishing %d counters on %s', len(msg['args']['data']), topic_name) rpc.cast(context, topic_name, msg)
def publish_counters(self, context, counters, source): """Send a metering message for publishing :param context: Execution context from the service or RPC call :param counter: Counter from pipeline after transformation :param source: counter source """ meters = [ meter_message_from_counter(counter, cfg.CONF.publisher_rpc.metering_secret, source) for counter in counters ] topic = cfg.CONF.publisher_rpc.metering_topic msg = {"method": "record_metering_data", "version": "1.0", "args": {"data": meters}} LOG.debug("PUBLISH: %s", str(msg)) rpc.cast(context, topic, msg) for meter_name, meter_list in itertools.groupby( sorted(meters, key=lambda m: m["counter_name"]), lambda m: m["counter_name"] ): msg = {"method": "record_metering_data", "version": "1.0", "args": {"data": list(meter_list)}} rpc.cast(context, topic + "." + meter_name, msg)