noc.core.service.base

Module Contents

class noc.core.service.base.Service

Bases: object

Basic service implementation.

  • on_change_<var> - subscribed to changes of config variable <var>
name
leader_lock_name
leader_group_name
pooled = False
process_name = noc-%(name).10s
use_mongo = False
api = []
api_request_handler
use_translation = False
use_jinja = False
use_telemetry = False
traefik_backend
traefik_frontend_rule
require_dcs_health = True
LOG_FORMAT
LOG_LEVELS
DEFAULT_SHARDING_KEY = managed_object
SHARDING_KEYS
NSQ_WRITER_CLOSE_TRY_TIMEOUT = 0.25
NSQ_WRITER_CLOSE_RETRIES = 5
create_parser(self)

Return argument parser

add_arguments(self, parser)

Apply additional parser arguments

classmethod die(cls, msg='')

Dump message to stdout and terminate process with error code

setup_logging(self, loglevel=None)

Create new or setup existing logger

setup_test_logging(self)
setup_translation(self)
on_change_loglevel(self, old_value, new_value)
log_separator(self, symbol='*', length=72)

Log a separator string to visually split log

setup_signal_handlers(self)

Set up signal handlers

set_proc_title(self)

Set process title

start(self)

Run main server loop

on_start(self)

Reload config

stop(self)
on_SIGHUP(self, signo, frame)
on_SIGTERM(self, signo, frame)
get_service_address(self)

Returns an (address, port) for HTTP service listener

update_service_address(self)

Update service address and port from tornado TCPServer :param server: :return:

get_handlers(self)

Returns a list of additional handlers

get_app_settings(self)

Returns tornado application settings

activate(self)

Initialize services before run

deactivate(self)
get_register_tags(self)
on_register(self)
on_activate(self)

Called when service activated

acquire_lock(self)
acquire_slot(self)
on_deactivate(self)
open_rpc(self, name, pool=None, sync=False, hints=None)

Returns RPC proxy object.

get_mon_status(self)
get_mon_data(self)

Returns monitoring data

iter_rpc_retry_timeout(self)

Yield timeout to wait after unsuccessful RPC connection

subscribe(self, topic, channel, handler, raw=False, **kwargs)

Subscribe message to channel

suspend_subscription(self, handler)

Suspend subscription for handler :param handler: :return:

resume_subscription(self, handler)

Resume subscription for handler :param handler: :return:

get_topic_queue(self, topic)
nsq_publisher_guard(self, queue)
nsq_publisher(self, queue)

Publisher for NSQ topic

Returns:
shutdown_topic_queues(self)
pub(self, topic, data, raw=False)

Publish message to topic :param topic: Topic name :param data: Message to send. Message will be automatically

converted to JSON if raw is False, or passed as-is otherwise
Parameters:raw – True - pass message as-is, False - convert to JSON
mpub(self, topic, messages)

Publish multiple messages to topic

get_executor(self, name)

Return or start named executor

register_metrics(self, table, metrics)

Register metrics

Parameters:
  • table – Table name
  • metrics – List of dicts containing metrics records
Returns:

static _iter_metrics_raw_chunks(table, metrics)
_register_unclustered_metrics(self, table, metrics)

Register metrics to send in non-clustered configuration. Must be used via register_metrics only

Parameters:
  • fields – Table name
  • metrics – List of dicts containing metrics records
Returns:

_register_replicated_metrics(self, table, metrics)

Register metrics to send in non-sharded replicated configuration. Must be used via register_metrics only

Parameters:
  • fields – Table name
  • metrics – List of dicts containing metrics records
Returns:

_register_sharded_metrics(self, table, metrics)

Register metrics to send in sharded replicated configuration Must be used via register_metrics only

Parameters:
  • table – Table name
  • metrics – List of dicts containing metrics records
Returns:

start_telemetry_callback(self)

Run telemetry callback :return:

send_telemetry(self)

Publish telemetry data

Returns:
log_request(self, handler)

Custom HTTP Log request handler :param handler: :return:

get_leader_lock_name(self)
add_close_callback(self, cb, *args, **kwargs)
get_backend_weight(self)

Return backend weight for weighted load balancers (i.e. traefik). Return None for default weight :return:

get_backend_limit(self)

Return backend connection limit for load balancers (i.e. traefik) Return None for no limits :return:

is_valid_health_check(self, service_id)

Check received service id matches own service id :param service_id: :return:

get_health_status(self)

Check service health to be reported to service registry :return: (http code, message)

uptime(self)