Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/logging_v2/types/logging_metrics.py: 98%

42 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 07:30 +0000

1# -*- coding: utf-8 -*- 

2# Copyright 2022 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16from typing import MutableMapping, MutableSequence 

17 

18import proto # type: ignore 

19 

20from google.api import distribution_pb2 # type: ignore 

21from google.api import metric_pb2 # type: ignore 

22from google.protobuf import timestamp_pb2 # type: ignore 

23 

24 

25__protobuf__ = proto.module( 

26 package="google.logging.v2", 

27 manifest={ 

28 "LogMetric", 

29 "ListLogMetricsRequest", 

30 "ListLogMetricsResponse", 

31 "GetLogMetricRequest", 

32 "CreateLogMetricRequest", 

33 "UpdateLogMetricRequest", 

34 "DeleteLogMetricRequest", 

35 }, 

36) 

37 

38 

39class LogMetric(proto.Message): 

40 r"""Describes a logs-based metric. The value of the metric is the 

41 number of log entries that match a logs filter in a given time 

42 interval. 

43 Logs-based metrics can also be used to extract values from logs 

44 and create a distribution of the values. The distribution 

45 records the statistics of the extracted values along with an 

46 optional histogram of the values as specified by the bucket 

47 options. 

48 

49 Attributes: 

50 name (str): 

51 Required. The client-assigned metric identifier. Examples: 

52 ``"error_count"``, ``"nginx/requests"``. 

53 

54 Metric identifiers are limited to 100 characters and can 

55 include only the following characters: ``A-Z``, ``a-z``, 

56 ``0-9``, and the special characters ``_-.,+!*',()%/``. The 

57 forward-slash character (``/``) denotes a hierarchy of name 

58 pieces, and it cannot be the first character of the name. 

59 

60 This field is the ``[METRIC_ID]`` part of a metric resource 

61 name in the format 

62 "projects/[PROJECT_ID]/metrics/[METRIC_ID]". Example: If the 

63 resource name of a metric is 

64 ``"projects/my-project/metrics/nginx%2Frequests"``, this 

65 field's value is ``"nginx/requests"``. 

66 description (str): 

67 Optional. A description of this metric, which 

68 is used in documentation. The maximum length of 

69 the description is 8000 characters. 

70 filter (str): 

71 Required. An `advanced logs 

72 filter <https://cloud.google.com/logging/docs/view/advanced_filters>`__ 

73 which is used to match log entries. Example: 

74 

75 :: 

76 

77 "resource.type=gae_app AND severity>=ERROR" 

78 

79 The maximum length of the filter is 20000 characters. 

80 disabled (bool): 

81 Optional. If set to True, then this metric is 

82 disabled and it does not generate any points. 

83 metric_descriptor (google.api.metric_pb2.MetricDescriptor): 

84 Optional. The metric descriptor associated with the 

85 logs-based metric. If unspecified, it uses a default metric 

86 descriptor with a DELTA metric kind, INT64 value type, with 

87 no labels and a unit of "1". Such a metric counts the number 

88 of log entries matching the ``filter`` expression. 

89 

90 The ``name``, ``type``, and ``description`` fields in the 

91 ``metric_descriptor`` are output only, and is constructed 

92 using the ``name`` and ``description`` field in the 

93 LogMetric. 

94 

95 To create a logs-based metric that records a distribution of 

96 log values, a DELTA metric kind with a DISTRIBUTION value 

97 type must be used along with a ``value_extractor`` 

98 expression in the LogMetric. 

99 

100 Each label in the metric descriptor must have a matching 

101 label name as the key and an extractor expression as the 

102 value in the ``label_extractors`` map. 

103 

104 The ``metric_kind`` and ``value_type`` fields in the 

105 ``metric_descriptor`` cannot be updated once initially 

106 configured. New labels can be added in the 

107 ``metric_descriptor``, but existing labels cannot be 

108 modified except for their description. 

109 value_extractor (str): 

110 Optional. A ``value_extractor`` is required when using a 

111 distribution logs-based metric to extract the values to 

112 record from a log entry. Two functions are supported for 

113 value extraction: ``EXTRACT(field)`` or 

114 ``REGEXP_EXTRACT(field, regex)``. The argument are: 

115 

116 1. field: The name of the log entry field from which the 

117 value is to be extracted. 

118 2. regex: A regular expression using the Google RE2 syntax 

119 (https://github.com/google/re2/wiki/Syntax) with a single 

120 capture group to extract data from the specified log 

121 entry field. The value of the field is converted to a 

122 string before applying the regex. It is an error to 

123 specify a regex that does not include exactly one capture 

124 group. 

125 

126 The result of the extraction must be convertible to a double 

127 type, as the distribution always records double values. If 

128 either the extraction or the conversion to double fails, 

129 then those values are not recorded in the distribution. 

130 

131 Example: 

132 ``REGEXP_EXTRACT(jsonPayload.request, ".*quantity=(\d+).*")`` 

133 label_extractors (MutableMapping[str, str]): 

134 Optional. A map from a label key string to an extractor 

135 expression which is used to extract data from a log entry 

136 field and assign as the label value. Each label key 

137 specified in the LabelDescriptor must have an associated 

138 extractor expression in this map. The syntax of the 

139 extractor expression is the same as for the 

140 ``value_extractor`` field. 

141 

142 The extracted value is converted to the type defined in the 

143 label descriptor. If the either the extraction or the type 

144 conversion fails, the label will have a default value. The 

145 default value for a string label is an empty string, for an 

146 integer label its 0, and for a boolean label its ``false``. 

147 

148 Note that there are upper bounds on the maximum number of 

149 labels and the number of active time series that are allowed 

150 in a project. 

151 bucket_options (google.api.distribution_pb2.BucketOptions): 

152 Optional. The ``bucket_options`` are required when the 

153 logs-based metric is using a DISTRIBUTION value type and it 

154 describes the bucket boundaries used to create a histogram 

155 of the extracted values. 

156 create_time (google.protobuf.timestamp_pb2.Timestamp): 

157 Output only. The creation timestamp of the 

158 metric. 

159 This field may not be present for older metrics. 

160 update_time (google.protobuf.timestamp_pb2.Timestamp): 

161 Output only. The last update timestamp of the 

162 metric. 

163 This field may not be present for older metrics. 

164 version (google.cloud.logging_v2.types.LogMetric.ApiVersion): 

165 Deprecated. The API version that created or 

166 updated this metric. The v2 format is used by 

167 default and cannot be changed. 

168 """ 

169 

170 class ApiVersion(proto.Enum): 

171 r"""Logging API version. 

172 

173 Values: 

174 V2 (0): 

175 Logging API v2. 

176 V1 (1): 

177 Logging API v1. 

178 """ 

179 V2 = 0 

180 V1 = 1 

181 

182 name: str = proto.Field( 

183 proto.STRING, 

184 number=1, 

185 ) 

186 description: str = proto.Field( 

187 proto.STRING, 

188 number=2, 

189 ) 

190 filter: str = proto.Field( 

191 proto.STRING, 

192 number=3, 

193 ) 

194 disabled: bool = proto.Field( 

195 proto.BOOL, 

196 number=12, 

197 ) 

198 metric_descriptor: metric_pb2.MetricDescriptor = proto.Field( 

199 proto.MESSAGE, 

200 number=5, 

201 message=metric_pb2.MetricDescriptor, 

202 ) 

203 value_extractor: str = proto.Field( 

204 proto.STRING, 

205 number=6, 

206 ) 

207 label_extractors: MutableMapping[str, str] = proto.MapField( 

208 proto.STRING, 

209 proto.STRING, 

210 number=7, 

211 ) 

212 bucket_options: distribution_pb2.Distribution.BucketOptions = proto.Field( 

213 proto.MESSAGE, 

214 number=8, 

215 message=distribution_pb2.Distribution.BucketOptions, 

216 ) 

217 create_time: timestamp_pb2.Timestamp = proto.Field( 

218 proto.MESSAGE, 

219 number=9, 

220 message=timestamp_pb2.Timestamp, 

221 ) 

222 update_time: timestamp_pb2.Timestamp = proto.Field( 

223 proto.MESSAGE, 

224 number=10, 

225 message=timestamp_pb2.Timestamp, 

226 ) 

227 version: ApiVersion = proto.Field( 

228 proto.ENUM, 

229 number=4, 

230 enum=ApiVersion, 

231 ) 

232 

233 

234class ListLogMetricsRequest(proto.Message): 

235 r"""The parameters to ListLogMetrics. 

236 

237 Attributes: 

238 parent (str): 

239 Required. The name of the project containing the metrics: 

240 

241 :: 

242 

243 "projects/[PROJECT_ID]". 

244 page_token (str): 

245 Optional. If present, then retrieve the next batch of 

246 results from the preceding call to this method. 

247 ``pageToken`` must be the value of ``nextPageToken`` from 

248 the previous response. The values of other method parameters 

249 should be identical to those in the previous call. 

250 page_size (int): 

251 Optional. The maximum number of results to return from this 

252 request. Non-positive values are ignored. The presence of 

253 ``nextPageToken`` in the response indicates that more 

254 results might be available. 

255 """ 

256 

257 parent: str = proto.Field( 

258 proto.STRING, 

259 number=1, 

260 ) 

261 page_token: str = proto.Field( 

262 proto.STRING, 

263 number=2, 

264 ) 

265 page_size: int = proto.Field( 

266 proto.INT32, 

267 number=3, 

268 ) 

269 

270 

271class ListLogMetricsResponse(proto.Message): 

272 r"""Result returned from ListLogMetrics. 

273 

274 Attributes: 

275 metrics (MutableSequence[google.cloud.logging_v2.types.LogMetric]): 

276 A list of logs-based metrics. 

277 next_page_token (str): 

278 If there might be more results than appear in this response, 

279 then ``nextPageToken`` is included. To get the next set of 

280 results, call this method again using the value of 

281 ``nextPageToken`` as ``pageToken``. 

282 """ 

283 

284 @property 

285 def raw_page(self): 

286 return self 

287 

288 metrics: MutableSequence["LogMetric"] = proto.RepeatedField( 

289 proto.MESSAGE, 

290 number=1, 

291 message="LogMetric", 

292 ) 

293 next_page_token: str = proto.Field( 

294 proto.STRING, 

295 number=2, 

296 ) 

297 

298 

299class GetLogMetricRequest(proto.Message): 

300 r"""The parameters to GetLogMetric. 

301 

302 Attributes: 

303 metric_name (str): 

304 Required. The resource name of the desired metric: 

305 

306 :: 

307 

308 "projects/[PROJECT_ID]/metrics/[METRIC_ID]". 

309 """ 

310 

311 metric_name: str = proto.Field( 

312 proto.STRING, 

313 number=1, 

314 ) 

315 

316 

317class CreateLogMetricRequest(proto.Message): 

318 r"""The parameters to CreateLogMetric. 

319 

320 Attributes: 

321 parent (str): 

322 Required. The resource name of the project in which to 

323 create the metric: 

324 

325 :: 

326 

327 "projects/[PROJECT_ID]" 

328 

329 The new metric must be provided in the request. 

330 metric (google.cloud.logging_v2.types.LogMetric): 

331 Required. The new logs-based metric, which 

332 must not have an identifier that already exists. 

333 """ 

334 

335 parent: str = proto.Field( 

336 proto.STRING, 

337 number=1, 

338 ) 

339 metric: "LogMetric" = proto.Field( 

340 proto.MESSAGE, 

341 number=2, 

342 message="LogMetric", 

343 ) 

344 

345 

346class UpdateLogMetricRequest(proto.Message): 

347 r"""The parameters to UpdateLogMetric. 

348 

349 Attributes: 

350 metric_name (str): 

351 Required. The resource name of the metric to update: 

352 

353 :: 

354 

355 "projects/[PROJECT_ID]/metrics/[METRIC_ID]" 

356 

357 The updated metric must be provided in the request and it's 

358 ``name`` field must be the same as ``[METRIC_ID]`` If the 

359 metric does not exist in ``[PROJECT_ID]``, then a new metric 

360 is created. 

361 metric (google.cloud.logging_v2.types.LogMetric): 

362 Required. The updated metric. 

363 """ 

364 

365 metric_name: str = proto.Field( 

366 proto.STRING, 

367 number=1, 

368 ) 

369 metric: "LogMetric" = proto.Field( 

370 proto.MESSAGE, 

371 number=2, 

372 message="LogMetric", 

373 ) 

374 

375 

376class DeleteLogMetricRequest(proto.Message): 

377 r"""The parameters to DeleteLogMetric. 

378 

379 Attributes: 

380 metric_name (str): 

381 Required. The resource name of the metric to delete: 

382 

383 :: 

384 

385 "projects/[PROJECT_ID]/metrics/[METRIC_ID]". 

386 """ 

387 

388 metric_name: str = proto.Field( 

389 proto.STRING, 

390 number=1, 

391 ) 

392 

393 

394__all__ = tuple(sorted(__protobuf__.manifest))