@@ -132,7 +132,7 @@ def _fetch(cls, client, metric_type):
132132 return cls ._from_dict (info )
133133
134134 @classmethod
135- def _list (cls , client , filter_string = None ):
135+ def _list (cls , client , filter_string = None , type_prefix = None ):
136136 """List all metric descriptors for the project.
137137
138138 :type client: :class:`gcloud.monitoring.client.Client`
@@ -143,6 +143,11 @@ def _list(cls, client, filter_string=None):
143143 An optional filter expression describing the metric descriptors
144144 to be returned. See the `filter documentation`_.
145145
146+ :type type_prefix: string or None
147+ :param type_prefix: An optional prefix constraining the selected
148+ metric types. This adds ``metric.type = starts_with("<prefix>")``
149+ to the filter.
150+
146151 :rtype: list of :class:`MetricDescriptor`
147152 :returns: A list of metric descriptor instances.
148153
@@ -152,14 +157,21 @@ def _list(cls, client, filter_string=None):
152157 path = '/projects/{project}/metricDescriptors/' .format (
153158 project = client .project )
154159
155- descriptors = []
160+ filters = []
161+ if filter_string is not None :
162+ filters .append (filter_string )
156163
164+ if type_prefix is not None :
165+ filters .append ('metric.type = starts_with("{prefix}")' .format (
166+ prefix = type_prefix ))
167+
168+ descriptors = []
157169 page_token = None
158170 while True :
159171 params = {}
160172
161- if filter_string is not None :
162- params ['filter' ] = filter_string
173+ if filters :
174+ params ['filter' ] = ' AND ' . join ( filters )
163175
164176 if page_token is not None :
165177 params ['pageToken' ] = page_token
0 commit comments