Skip to content

Add get metric descriptor #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions monitoring/api/v3/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@ def list_monitored_resources():
# [END list_monitored_resources]


def get_monitored_resource_descriptor(type):
def get_monitored_resource_descriptor(type_):
# [START get_monitored_resources]
client = monitoring.Client()
print(client.fetch_resource_descriptor(type))
print(client.fetch_resource_descriptor(type_))
# [END get_monitored_resources]


def get_metric_descriptor(type_):
# [START get_monitored_resources]
client = monitoring.Client()
print(client.fetch_metric_descriptor(type_))
# [END get_monitored_resources]


Expand All @@ -143,6 +150,17 @@ def get_monitored_resource_descriptor(type):
help=list_metric_descriptors.__doc__
)

get_metric_descriptor_parser = subparsers.add_parser(
'get-metric-descriptor',
help=get_metric_descriptor.__doc__
)

get_metric_descriptor_parser.add_argument(
'--metric',
help='The metric type of the metric descriptor to see details about.',
required=True
)

delete_metric_descriptor_parser = subparsers.add_parser(
'delete-metric-descriptor',
help=list_metric_descriptors.__doc__
Expand Down Expand Up @@ -201,6 +219,8 @@ def get_monitored_resource_descriptor(type):
create_metric_descriptor()
if args.command == 'list-metric-descriptors':
list_metric_descriptors()
if args.command == 'get-metric-descriptor':
get_metric_descriptor(args.metric)
if args.command == 'delete-metric-descriptor':
delete_metric_descriptor(args.metric)
if args.command == 'list-resources':
Expand Down
5 changes: 4 additions & 1 deletion monitoring/api/v3/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import snippets


def test_create_and_delete_metric_descriptor(capsys):
def test_create_get_delete_metric_descriptor(capsys):
snippets.create_metric_descriptor()
snippets.get_metric_descriptor('custom.googleapis.com/my_metric')
out, _ = capsys.readouterr()
assert 'a simple example' in out
snippets.delete_metric_descriptor('custom.googleapis.com/my_metric')
out, _ = capsys.readouterr()
assert 'Deleted metric' in out
Expand Down