Merge "Add global_delegeated_tenant field to agent config"

This commit is contained in:
Jenkins 2017-01-25 17:08:29 +00:00 committed by Gerrit Code Review
commit 9599bb4912
4 changed files with 18 additions and 5 deletions

View File

@ -106,6 +106,13 @@ Main:
# https://github.com/DataDog/dd-agent/wiki/Network-Traffic-and-Proxy-Configuration
# non_local_traffic: no
# Submits all metrics to this tenant unless specified by the metric.
# This is the equivalent of submitting delegated_tenant with all metrics, and when
# not set will submit metrics to the default tenant of the provided credentials.
# Used when deploying the agent to systems where the credentials of the monitored
# tenant are not known.
# global_delegated_tenant:
Statsd:
# ========================================================================== #
# Monasca Statsd configuration #

View File

@ -35,9 +35,11 @@ class AgentCheck(util.Dimensions):
self.log = logging.getLogger('%s.%s' % (__name__, name))
threshold = agent_config.get('recent_point_threshold', None)
tenant_id = agent_config.get('global_delegated_tenant', None)
self.aggregator = (
aggregator.MetricsAggregator(self.hostname,
recent_point_threshold=threshold))
recent_point_threshold=threshold,
tenant_id=tenant_id))
self.instances = instances or []
self.library_versions = None

View File

@ -50,10 +50,11 @@ class InvalidValueMeta(Exception):
class MetricsAggregator(object):
"""A metric aggregator class."""
def __init__(self, hostname, recent_point_threshold=None):
def __init__(self, hostname, recent_point_threshold=None, tenant_id=None):
self.total_count = 0
self.count = 0
self.hostname = hostname
self.global_delegated_tenant = tenant_id
recent_point_threshold = recent_point_threshold or RECENT_POINT_THRESHOLD_DEFAULT
self.recent_point_threshold = int(recent_point_threshold)
@ -166,6 +167,8 @@ class MetricsAggregator(object):
hostname_to_post = self.get_hostname_to_post(hostname)
tenant_to_post = delegated_tenant or self.global_delegated_tenant
dimensions_copy = dimensions.copy()
if 'hostname' not in dimensions_copy and hostname_to_post:
@ -178,13 +181,13 @@ class MetricsAggregator(object):
# TODO(joe): Decide if hostname_to_post and device_name are necessary
# for the context tuple
context = (name, tuple(dimensions_copy.items()), delegated_tenant,
context = (name, tuple(dimensions_copy.items()), tenant_to_post,
hostname_to_post, device_name)
if context not in self.metrics:
self.metrics[context] = metric_class(name,
dimensions_copy,
tenant=delegated_tenant)
tenant=tenant_to_post)
cur_time = time()
if timestamp is not None:
if cur_time - int(timestamp) > self.recent_point_threshold:

View File

@ -36,7 +36,8 @@ class MonascaStatsd(object):
# Create the aggregator (which is the point of communication between the server and reporting threads.
aggregator = agg.MetricsAggregator(util.get_hostname(),
recent_point_threshold=statsd_config['recent_point_threshold'])
recent_point_threshold=statsd_config['recent_point_threshold'],
tenant_id=statsd_config.get('global_delegated_tenant', None))
# Start the reporting thread.
interval = int(statsd_config['monasca_statsd_interval'])