Skip to content

Commit

Permalink
Merge pull request #109 from yahoo/polling_plugin_agent_tests
Browse files Browse the repository at this point in the history
Additional polling_plugin_agent_tests
  • Loading branch information
varunvarma committed Oct 11, 2019
2 parents fd9c372 + 2492be4 commit f701d97
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Core]
Name = unit_test
Module = nosetests

[Documentation]
Author = Verizon Media, Inc.
Version = 0.1
Website = https://github.com/yahoo/panoptes
Description = Unit Tests

[main]
execute_frequency = 60
resource_filter = resource_class = "network" AND resource_subclass = "load-balancer" AND resource_type = "test"
load_balancer_connection_timeout = 5
load_balancer_read_timeout = 30
hostname_lookup_timeout = 30

[transforms]
test_group = 'foobar:test_group:not_present_1,not_present_2'

[topics]
processed = processed
43 changes: 43 additions & 0 deletions tests/metric_group_sets/interface_plugin_counter_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"metrics_group_interval": 60,
"resource": {
"resource_site": "test_site",
"resource_class": "network",
"resource_subclass": "test_subclass",
"resource_type": "test_type",
"resource_id": "test_id_2",
"resource_endpoint": "test_endpoint_2",
"resource_metadata": {
"_resource_ttl": "604800",
"test_metadata_key": "test_metadata_value"
},
"resource_creation_timestamp": 1666516070.58,
"resource_plugin": "Discovery_Plugin"
},
"dimensions": [
{
"dimension_name": "test_dimension_name",
"dimension_value": "test_dimension_value"
}
],
"metrics_group_type": "test_group",
"metrics": [

{
"metric_creation_timestamp": 1666516070.58,
"metric_type": "counter",
"metric_name": "test_system_uptime",
"metric_value": 500
},
{
"metric_creation_timestamp": 1666516070.58,
"metric_type": "counter",
"metric_name": "extra_test_metric",
"metric_value": 1000
}
],
"metrics_group_creation_timestamp": 1666516070.58,
"metrics_group_schema_version": "0.2"
}
]
43 changes: 43 additions & 0 deletions tests/metric_group_sets/interface_plugin_counter_8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"metrics_group_interval": 60,
"resource": {
"resource_site": "test_site",
"resource_class": "network",
"resource_subclass": "test_subclass",
"resource_type": "test_type",
"resource_id": "test_id_2",
"resource_endpoint": "test_endpoint_2",
"resource_metadata": {
"_resource_ttl": "604800",
"test_metadata_key": "test_metadata_value"
},
"resource_creation_timestamp": 1666516249.58,
"resource_plugin": "Discovery_Plugin"
},
"dimensions": [
{
"dimension_name": "test_dimension_name",
"dimension_value": "test_dimension_value"
}
],
"metrics_group_type": "test_group",
"metrics": [

{
"metric_creation_timestamp": 1666516249.58,
"metric_type": "counter",
"metric_name": "test_system_uptime",
"metric_value": 400
},
{
"metric_creation_timestamp": 1666516249.58,
"metric_type": "counter",
"metric_name": "extra_test_metric",
"metric_value": 900
}
],
"metrics_group_creation_timestamp": 1666516249.58,
"metrics_group_schema_version": "0.2"
}
]
48 changes: 46 additions & 2 deletions tests/test_plugin_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from yahoo_panoptes.polling.polling_plugin_agent import PanoptesMetricsKeyValueStore, \
PanoptesPollingPluginAgentKeyValueStore, PanoptesPollingPluginKeyValueStore, \
PanoptesPollingAgentContext, start_polling_plugin_agent, polling_plugin_task, \
_process_metrics_group_set, shutdown_signal_handler as polling_agent_shutdown
_process_metrics_group_set, shutdown_signal_handler as polling_agent_shutdown, \
PanoptesPollingTaskContext

from yahoo_panoptes.discovery.discovery_plugin_agent import PanoptesDiscoveryPluginAgentKeyValueStore, \
PanoptesDiscoveryPluginKeyValueStore, PanoptesDiscoveryAgentContext, start_discovery_plugin_agent, \
Expand Down Expand Up @@ -248,7 +249,7 @@ def test_polling_transform_converts_correct_counters(self, message_producer, mes

panoptes_context = PanoptesContext(config_file=os.path.join(path, 'config_files/test_panoptes_config.ini'))

for i in range(1, 7):
for i in range(1, 9):
panoptes_metrics = self.prepare_panoptes_metrics_group_set(
'{}/metric_group_sets/interface_plugin_counter_{}.json'.format(pwd, i))
_process_metrics_group_set(context=panoptes_context, results=panoptes_metrics, plugin=mock_panoptes_plugin)
Expand Down Expand Up @@ -289,6 +290,22 @@ def test_polling_transform_converts_correct_counters(self, message_producer, mes
'gauge|test_system_uptime': 0,
'counter|extra_test_metric': 1000,
'gauge|extra_test_metric': 1
},
{
# Confidence below the const.METRICS_CONFIDENCE_THRESHOLD
# ( time_difference > (metrics_group.interval * const.METRICS_KV_STORE_TTL_MULTIPLE )
'counter|test_system_uptime': 500,
'gauge|test_system_uptime': 0,
'counter|extra_test_metric': 1000,
'gauge|extra_test_metric': 0
},
{
# Skip Conversion due to the new counter value
# being less than the previous value
'counter|test_system_uptime': 400,
'gauge|test_system_uptime': 1,
'counter|extra_test_metric': 900,
'gauge|extra_test_metric': 1
}
]

Expand All @@ -303,6 +320,33 @@ def test_polling_transform_converts_correct_counters(self, message_producer, mes
panoptes_metric['metric_value']
)

@patch('yahoo_panoptes.framework.context.PanoptesContext.get_kv_store')
@patch('yahoo_panoptes.framework.context.PanoptesContext._get_message_producer')
@patch('yahoo_panoptes.framework.context.PanoptesContext.message_producer', new_callable=PropertyMock)
def test_polling_no_matching_transform_type(self, message_producer, message_producer_property, kv_store):

mock_panoptes_plugin = MockPanoptesObject()
mock_panoptes_plugin.config = ConfigObj(
pwd + '/config_files/test_panoptes_polling_plugin_conf_diff_transform_callback.ini')
kv_store.return_value = PanoptesMockRedis()

mock_message_producer = MockPanoptesMessageProducer()

message_producer.return_value = mock_message_producer
message_producer_property.return_value = message_producer_property

panoptes_context = PanoptesContext(config_file=os.path.join(path, 'config_files/test_panoptes_config.ini'))

for i in range(1, 9):
panoptes_metrics = self.prepare_panoptes_metrics_group_set(
'{}/metric_group_sets/interface_plugin_counter_{}.json'.format(pwd, i))
_process_metrics_group_set(context=panoptes_context, results=panoptes_metrics, plugin=mock_panoptes_plugin)

self.assertEqual(
panoptes_context.message_producer.messages,
[]
)

@patch('yahoo_panoptes.framework.context.PanoptesContext._get_message_producer')
@patch('yahoo_panoptes.framework.context.PanoptesContext.message_producer', new_callable=PropertyMock)
def test_polling_kafka_produces_to_the_correct_topics(self, message_producer, message_producer_property):
Expand Down

0 comments on commit f701d97

Please sign in to comment.