def test_update_log_metric(self): # Setup Expected Response name = "name3373707" description = "description-1724546052" filter_ = "filter-1274492040" value_extractor = "valueExtractor2047672534" expected_response = { "name": name, "description": description, "filter": filter_, "value_extractor": value_extractor, } expected_response = logging_metrics_pb2.LogMetric(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup Request metric_name = client.metric_path("[PROJECT]", "[METRIC]") metric = {} response = client.update_log_metric(metric_name, metric) assert expected_response == response assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.UpdateLogMetricRequest( metric_name=metric_name, metric=metric) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_log_metric(self): # Setup Expected Response name = 'name3373707' description = 'description-1724546052' filter_ = 'filter-1274492040' value_extractor = 'valueExtractor2047672534' expected_response = { 'name': name, 'description': description, 'filter': filter_, 'value_extractor': value_extractor } expected_response = logging_metrics_pb2.LogMetric(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch('google.api_core.grpc_helpers.create_channel') with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup Request metric_name = client.metric_path('[PROJECT]', '[METRIC]') metric = {} response = client.update_log_metric(metric_name, metric) assert expected_response == response assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.UpdateLogMetricRequest( metric_name=metric_name, metric=metric) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_log_metrics(self): # Setup Expected Response next_page_token = "" metrics_element = {} metrics = [metrics_element] expected_response = { "next_page_token": next_page_token, "metrics": metrics } expected_response = logging_metrics_pb2.ListLogMetricsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup Request parent = client.project_path("[PROJECT]") paged_list_response = client.list_log_metrics(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.metrics[0] == resources[0] assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.ListLogMetricsRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_log_metrics(self): # Setup Expected Response next_page_token = '' metrics_element = {} metrics = [metrics_element] expected_response = { 'next_page_token': next_page_token, 'metrics': metrics } expected_response = logging_metrics_pb2.ListLogMetricsResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup Request parent = client.project_path('[PROJECT]') paged_list_response = client.list_log_metrics(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.metrics[0] == resources[0] assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.ListLogMetricsRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_log_metric(self): # Setup Expected Response name = 'name3373707' description = 'description-1724546052' filter_ = 'filter-1274492040' value_extractor = 'valueExtractor2047672534' expected_response = { 'name': name, 'description': description, 'filter': filter_, 'value_extractor': value_extractor } expected_response = logging_metrics_pb2.LogMetric(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup Request parent = client.project_path('[PROJECT]') metric = {} response = client.create_log_metric(parent, metric) assert expected_response == response assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.CreateLogMetricRequest( parent=parent, metric=metric) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_list_log_metrics_exception(self): channel = ChannelStub(responses=[CustomException()]) client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup request parent = client.project_path('[PROJECT]') paged_list_response = client.list_log_metrics(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_delete_log_metric_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup request metric_name = client.metric_path('[PROJECT]', '[METRIC]') with pytest.raises(CustomException): client.delete_log_metric(metric_name)
def sample_delete_log_metric(): # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.DeleteLogMetricRequest( metric_name="metric_name_value", ) # Make the request client.delete_log_metric(request=request)
def sample_delete_log_metric(): """Snippet for delete_log_metric""" # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.DeleteLogMetricRequest() # Make the request response = client.delete_log_metric(request=request)
def test_create_log_metric_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup request parent = client.project_path('[PROJECT]') metric = {} with pytest.raises(CustomException): client.create_log_metric(parent, metric)
def cleanupLogBasedMetrics(project_name): """ Deletes all log-based metrics. """ client = logging_v2.MetricsServiceV2Client() metrics = True while metrics: metrics = ["{}/metrics/{}".format(project_name, metric.name) for metric in client.list_log_metrics(project_name)] for metric in metrics: try: client.delete_log_metric(metric) except: print('Could not delete metric: ' + metric)
def sample_get_log_metric(): # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.GetLogMetricRequest(metric_name="metric_name_value", ) # Make the request response = client.get_log_metric(request=request) # Handle the response print(response)
def sample_list_log_metrics(): """Snippet for list_log_metrics""" # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.ListLogMetricsRequest() # Make the request page_result = client.list_log_metrics(request=request) for response in page_result: print("{}".format(response))
def sample_list_log_metrics(): # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.ListLogMetricsRequest(parent="parent_value", ) # Make the request page_result = client.list_log_metrics(request=request) # Handle the response for response in page_result: print(response)
def test_list_log_metrics_exception(self): channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup request parent = client.project_path("[PROJECT]") paged_list_response = client.list_log_metrics(parent) with pytest.raises(CustomException): list(paged_list_response)
def test_delete_log_metric_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup request metric_name = client.metric_path("[PROJECT]", "[METRIC]") with pytest.raises(CustomException): client.delete_log_metric(metric_name)
def test_delete_log_metric(self): channel = ChannelStub() client = logging_v2.MetricsServiceV2Client(channel=channel) # Setup Request metric_name = client.metric_path('[PROJECT]', '[METRIC]') client.delete_log_metric(metric_name) assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.DeleteLogMetricRequest( metric_name=metric_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_get_log_metric(): """Snippet for get_log_metric""" # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) request = logging_v2.GetLogMetricRequest() # Make the request response = client.get_log_metric(request=request) # Handle response print("{}".format(response))
def test_create_log_metric_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup request parent = client.project_path("[PROJECT]") metric = {} with pytest.raises(CustomException): client.create_log_metric(parent, metric)
def test_delete_log_metric(self): channel = ChannelStub() patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = logging_v2.MetricsServiceV2Client() # Setup Request metric_name = client.metric_path("[PROJECT]", "[METRIC]") client.delete_log_metric(metric_name) assert len(channel.requests) == 1 expected_request = logging_metrics_pb2.DeleteLogMetricRequest( metric_name=metric_name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def sample_update_log_metric(): # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) metric = logging_v2.LogMetric() metric.name = "name_value" metric.filter = "filter_value" request = logging_v2.UpdateLogMetricRequest( metric_name="metric_name_value", metric=metric, ) # Make the request response = client.update_log_metric(request=request) # Handle the response print(response)
def setUp(self): self.client = logging_v2.MetricsServiceV2Client() self.project_id = getProjectId()