Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_metric_descriptor_sum_int(self):
client = mock.Mock()
option = stackdriver.Options(
project_id="project-test", metric_prefix="teste")
view_name_sum_int = "view-sum-int"
agg_sum = aggregation_module.SumAggregation(sum=2)
view_sum_int = view_module.View(
view_name_sum_int, "processed video size over time",
[FRONTEND_KEY], VIDEO_SIZE_MEASURE, agg_sum)
exporter = stackdriver.StackdriverStatsExporter(
options=option, client=client)
desc = exporter.create_metric_descriptor(view_sum_int)
self.assertIsNotNone(desc)
def test_make_request_1(self, monitor_resource_mock):
client = mock.Mock()
start_time = datetime.utcnow()
end_time = datetime.utcnow()
v_data = view_data_module.ViewData(
view=VIDEO_SIZE_VIEW, start_time=start_time, end_time=end_time)
view_data = [v_data]
option = stackdriver.Options(project_id="project-test")
exporter = stackdriver.StackdriverStatsExporter(
options=option, client=client)
requests = exporter.make_request(view_data, 0)
self.assertEqual(len(requests), 1)
def test_create_metric_descriptor_last_value_int(self):
client = mock.Mock()
option = stackdriver.Options(
project_id="project-test", metric_prefix="teste")
view_name_base = "view-base"
agg_base = aggregation_module.LastValueAggregation()
view_base = view_module.View(
view_name_base, "processed video size over time", [FRONTEND_KEY],
VIDEO_SIZE_MEASURE, agg_base)
exporter = stackdriver.StackdriverStatsExporter(
options=option, client=client)
desc = exporter.create_metric_descriptor(view_base)
self.assertIsNotNone(desc)
def test_blank_project(self):
self.assertRaises(Exception, stackdriver.new_stats_exporter,
stackdriver.Options(project_id=""))
def test_default_monitoring_labels(self):
default_labels = {'key1': 'value1'}
option = stackdriver.Options(default_monitoring_labels=default_labels)
self.assertEqual(option.default_monitoring_labels, default_labels)
def test_options_parameters(self):
option = stackdriver.Options(
project_id="project-id", metric_prefix="sample")
self.assertEqual(option.project_id, "project-id")
self.assertEqual(option.metric_prefix, "sample")
def _enable_exporter():
"""Create and register the stackdriver exporter.
For any data to be exported to stackdriver, an exporter needs to be created
and registered with the view manager. Collected data will be reported via
all the registered exporters. By not creating and registering an exporter,
all collected data will stay local and will not appear on stackdriver.
"""
project_id = _get_project_id()
exporter = stackdriver_exporter.new_stats_exporter(
stackdriver_exporter.Options(project_id=project_id))
STATS.view_manager.register_exporter(exporter)
def _new_exporter():
"""
Initializes a metrics exporter.
Tries to initialize a Stackdriver exporter, falls back to StdoutExporter.
"""
try:
_, project_id = google.auth.default()
return stackdriver_exporter.new_stats_exporter(
stackdriver_exporter.Options(project_id=project_id, resource='global'))
except google.auth.exceptions.DefaultCredentialsError:
_logger.exception("Using stdout exporter")
return StdoutExporter()