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

43 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 __future__ import annotations 

17 

18from typing import MutableMapping, MutableSequence 

19 

20import proto # type: ignore 

21 

22from google.api import distribution_pb2 # type: ignore 

23from google.api import metric_pb2 # type: ignore 

24from google.protobuf import timestamp_pb2 # type: ignore 

25 

26 

27__protobuf__ = proto.module( 

28 package="google.logging.v2", 

29 manifest={ 

30 "LogMetric", 

31 "ListLogMetricsRequest", 

32 "ListLogMetricsResponse", 

33 "GetLogMetricRequest", 

34 "CreateLogMetricRequest", 

35 "UpdateLogMetricRequest", 

36 "DeleteLogMetricRequest", 

37 }, 

38) 

39 

40 

41class LogMetric(proto.Message): 

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

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

44 interval. 

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

46 and create a distribution of the values. The distribution 

47 records the statistics of the extracted values along with an 

48 optional histogram of the values as specified by the bucket 

49 options. 

50 

51 Attributes: 

52 name (str): 

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

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

55 

56 Metric identifiers are limited to 100 characters and can 

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

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

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

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

61 

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

63 name in the format 

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

65 resource name of a metric is 

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

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

68 description (str): 

69 Optional. A description of this metric, which 

70 is used in documentation. The maximum length of 

71 the description is 8000 characters. 

72 filter (str): 

73 Required. An `advanced logs 

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

75 which is used to match log entries. Example: 

76 

77 :: 

78 

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

80 

81 The maximum length of the filter is 20000 characters. 

82 disabled (bool): 

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

84 disabled and it does not generate any points. 

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

86 Optional. The metric descriptor associated with the 

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

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

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

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

91 

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

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

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

95 LogMetric. 

96 

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

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

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

100 expression in the LogMetric. 

101 

102 Each label in the metric descriptor must have a matching 

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

104 value in the ``label_extractors`` map. 

105 

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

107 ``metric_descriptor`` cannot be updated once initially 

108 configured. New labels can be added in the 

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

110 modified except for their description. 

111 value_extractor (str): 

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

113 distribution logs-based metric to extract the values to 

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

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

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

117 

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

119 value is to be extracted. 

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

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

122 capture group to extract data from the specified log 

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

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

125 specify a regex that does not include exactly one capture 

126 group. 

127 

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

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

130 either the extraction or the conversion to double fails, 

131 then those values are not recorded in the distribution. 

132 

133 Example: 

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

135 label_extractors (MutableMapping[str, str]): 

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

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

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

139 specified in the LabelDescriptor must have an associated 

140 extractor expression in this map. The syntax of the 

141 extractor expression is the same as for the 

142 ``value_extractor`` field. 

143 

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

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

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

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

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

149 

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

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

152 in a project. 

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

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

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

156 describes the bucket boundaries used to create a histogram 

157 of the extracted values. 

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

159 Output only. The creation timestamp of the 

160 metric. 

161 This field may not be present for older metrics. 

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

163 Output only. The last update timestamp of the 

164 metric. 

165 This field may not be present for older metrics. 

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

167 Deprecated. The API version that created or 

168 updated this metric. The v2 format is used by 

169 default and cannot be changed. 

170 """ 

171 

172 class ApiVersion(proto.Enum): 

173 r"""Logging API version. 

174 

175 Values: 

176 V2 (0): 

177 Logging API v2. 

178 V1 (1): 

179 Logging API v1. 

180 """ 

181 V2 = 0 

182 V1 = 1 

183 

184 name: str = proto.Field( 

185 proto.STRING, 

186 number=1, 

187 ) 

188 description: str = proto.Field( 

189 proto.STRING, 

190 number=2, 

191 ) 

192 filter: str = proto.Field( 

193 proto.STRING, 

194 number=3, 

195 ) 

196 disabled: bool = proto.Field( 

197 proto.BOOL, 

198 number=12, 

199 ) 

200 metric_descriptor: metric_pb2.MetricDescriptor = proto.Field( 

201 proto.MESSAGE, 

202 number=5, 

203 message=metric_pb2.MetricDescriptor, 

204 ) 

205 value_extractor: str = proto.Field( 

206 proto.STRING, 

207 number=6, 

208 ) 

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

210 proto.STRING, 

211 proto.STRING, 

212 number=7, 

213 ) 

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

215 proto.MESSAGE, 

216 number=8, 

217 message=distribution_pb2.Distribution.BucketOptions, 

218 ) 

219 create_time: timestamp_pb2.Timestamp = proto.Field( 

220 proto.MESSAGE, 

221 number=9, 

222 message=timestamp_pb2.Timestamp, 

223 ) 

224 update_time: timestamp_pb2.Timestamp = proto.Field( 

225 proto.MESSAGE, 

226 number=10, 

227 message=timestamp_pb2.Timestamp, 

228 ) 

229 version: ApiVersion = proto.Field( 

230 proto.ENUM, 

231 number=4, 

232 enum=ApiVersion, 

233 ) 

234 

235 

236class ListLogMetricsRequest(proto.Message): 

237 r"""The parameters to ListLogMetrics. 

238 

239 Attributes: 

240 parent (str): 

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

242 

243 :: 

244 

245 "projects/[PROJECT_ID]". 

246 page_token (str): 

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

248 results from the preceding call to this method. 

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

250 the previous response. The values of other method parameters 

251 should be identical to those in the previous call. 

252 page_size (int): 

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

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

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

256 results might be available. 

257 """ 

258 

259 parent: str = proto.Field( 

260 proto.STRING, 

261 number=1, 

262 ) 

263 page_token: str = proto.Field( 

264 proto.STRING, 

265 number=2, 

266 ) 

267 page_size: int = proto.Field( 

268 proto.INT32, 

269 number=3, 

270 ) 

271 

272 

273class ListLogMetricsResponse(proto.Message): 

274 r"""Result returned from ListLogMetrics. 

275 

276 Attributes: 

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

278 A list of logs-based metrics. 

279 next_page_token (str): 

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

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

282 results, call this method again using the value of 

283 ``nextPageToken`` as ``pageToken``. 

284 """ 

285 

286 @property 

287 def raw_page(self): 

288 return self 

289 

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

291 proto.MESSAGE, 

292 number=1, 

293 message="LogMetric", 

294 ) 

295 next_page_token: str = proto.Field( 

296 proto.STRING, 

297 number=2, 

298 ) 

299 

300 

301class GetLogMetricRequest(proto.Message): 

302 r"""The parameters to GetLogMetric. 

303 

304 Attributes: 

305 metric_name (str): 

306 Required. The resource name of the desired metric: 

307 

308 :: 

309 

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

311 """ 

312 

313 metric_name: str = proto.Field( 

314 proto.STRING, 

315 number=1, 

316 ) 

317 

318 

319class CreateLogMetricRequest(proto.Message): 

320 r"""The parameters to CreateLogMetric. 

321 

322 Attributes: 

323 parent (str): 

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

325 create the metric: 

326 

327 :: 

328 

329 "projects/[PROJECT_ID]" 

330 

331 The new metric must be provided in the request. 

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

333 Required. The new logs-based metric, which 

334 must not have an identifier that already exists. 

335 """ 

336 

337 parent: str = proto.Field( 

338 proto.STRING, 

339 number=1, 

340 ) 

341 metric: "LogMetric" = proto.Field( 

342 proto.MESSAGE, 

343 number=2, 

344 message="LogMetric", 

345 ) 

346 

347 

348class UpdateLogMetricRequest(proto.Message): 

349 r"""The parameters to UpdateLogMetric. 

350 

351 Attributes: 

352 metric_name (str): 

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

354 

355 :: 

356 

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

358 

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

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

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

362 is created. 

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

364 Required. The updated metric. 

365 """ 

366 

367 metric_name: str = proto.Field( 

368 proto.STRING, 

369 number=1, 

370 ) 

371 metric: "LogMetric" = proto.Field( 

372 proto.MESSAGE, 

373 number=2, 

374 message="LogMetric", 

375 ) 

376 

377 

378class DeleteLogMetricRequest(proto.Message): 

379 r"""The parameters to DeleteLogMetric. 

380 

381 Attributes: 

382 metric_name (str): 

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

384 

385 :: 

386 

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

388 """ 

389 

390 metric_name: str = proto.Field( 

391 proto.STRING, 

392 number=1, 

393 ) 

394 

395 

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