Removing global variables.

This commit is contained in:
Aurélien Legrand 2022-03-17 17:04:31 +01:00 committed by Julio Castillo
parent 261fc20227
commit ea6d86ce01
2 changed files with 21 additions and 2 deletions

View File

@ -49,8 +49,6 @@ def main(event, context):
Returns:
'Function executed successfully'
'''
global client, interval
client, interval = create_client()
metrics_dict = create_metrics()
@ -462,6 +460,8 @@ def get_quota_current_usage(project_link, metric_name):
Returns:
results_list (list of string): Current usage.
'''
client, interval = create_client()
results = client.list_time_series(request={
"name": project_link,
"filter": f'metric.type = "{metric_name}"',
@ -481,6 +481,8 @@ def get_quota_current_limit(project_link, metric_name):
Returns:
results_list (list of string): Current limit.
'''
client, interval = create_client()
results = client.list_time_series(request={
"name": project_link,
"filter": f'metric.type = "{metric_name}"',
@ -600,6 +602,8 @@ def write_data_to_metric(monitored_project_id, value, metric_name, network_name)
usage (int): Current usage for that network.
limit (int): Current usage for that network.
'''
client = monitoring_v3.MetricServiceClient()
series = monitoring_v3.TimeSeries()
series.metric.type = f"custom.googleapis.com/{metric_name}"
series.resource.type = "global"

View File

@ -1,3 +1,18 @@
#
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
metrics_per_network:
instance_per_network: