1515# limitations under the License.
1616
1717import logging
18- from retrying import retry
1918
2019import google .cloud .logging
2120import google .cloud .monitoring
@@ -51,8 +50,23 @@ def _logging():
5150 return 'OK' , 200
5251
5352
54- # TODO (nkubala): just as a note, currently the client logging API is broken
5553def _log (token , log_name = 'stdout' ):
54+ """
55+ Write a log entry to Stackdriver.
56+
57+ Keyword arguments:
58+ token -- 16-character (8-byte) hexadecimal token, to be written
59+ as a log entry.
60+ log_name -- The name of the logging group to be written to.
61+
62+ Once the entry is written to Stackdriver, the test driver will retrieve
63+ all entries with the name 'log_name', and verify there is an entry with
64+ the same value as 'token', indicating the entry was written successfully.
65+ """
66+
67+ # TODO (nkubala): just as a note, currently the client logging API is
68+ # broken
69+
5670 # TODO (nkubala): write token to 'log_name' log, instead of stdout
5771 # is this possible in non-standard (flex)???
5872
@@ -64,7 +78,7 @@ def _log(token, log_name='stdout'):
6478 logging .error ('Error while writing logs: {0}' .format (e ))
6579 raise ErrorResponse ('Error while writing logs: {0}' .format (e ))
6680
67- # logging.info (token)
81+ logging .debug (token )
6882 print (token )
6983
7084
@@ -88,8 +102,8 @@ def _monitoring():
88102 descriptor = client .fetch_metric_descriptor (name )
89103 if descriptor is None :
90104 _create_descriptor (name , client )
91- except (google .cloud .exceptions .Forbidden ,
92- google .cloud .exceptions .NotFound ) as ignored :
105+ except (google .cloud .exceptions .Forbidden ,
106+ google .cloud .exceptions .NotFound ) as ignored : # noqa: F841
93107 _create_descriptor (name , client )
94108
95109 _write_metric (name , client , token )
@@ -102,12 +116,30 @@ def _monitoring():
102116
103117
104118def _write_metric (name , client , token ):
119+ """
120+ Write a metric to Stackdriver Monitoring.
121+
122+ Keyword arguments:
123+ name -- The name of the metric to write. Takes the form
124+ 'custom.googleapis.com/{metric_name}'
125+ client -- the authenticated instance of a Google Cloud Client
126+ token -- a random 64-bit integer token. The metric value to be written.
127+
128+ Once the metric is written, the test driver will retrieve all metrics
129+ written with the provided name, and verify there is an entry with the
130+ same value as the provided token.
131+ """
105132 metric = client .metric (name , {})
106133 resource = client .resource ('global' , labels = {})
107134 client .write_point (metric , resource , token )
108135
109136
110137def _create_descriptor (name , client ):
138+ """
139+ Create a new metric descriptor.
140+ This descriptor is implicitly used to write a point-value metric to
141+ Stackdriver.
142+ """
111143 logging .info ('No descriptor found with name {0}: Creating...' .format (name ))
112144 descriptor = client .metric_descriptor (
113145 name ,
0 commit comments