Skip to content

Commit e94dc5d

Browse files
modular-magicianLuca Prete
andauthored
[#13215] Make metric_descriptor argument optional for google_logging_metric (#6937) (#4971)
Co-authored-by: Luca Prete <[email protected]> Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Luca Prete <[email protected]>
1 parent 9e0d554 commit e94dc5d

File tree

5 files changed

+103
-117
lines changed

5 files changed

+103
-117
lines changed

.changelog/6937.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
logging: made `metric_descriptor` argument optional for `google_logging_metric`
3+
```

google-beta/resource_logging_metric.go

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,6 @@ func resourceLoggingMetric() *schema.Resource {
4747
Description: `An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which
4848
is used to match log entries.`,
4949
},
50-
"metric_descriptor": {
51-
Type: schema.TypeList,
52-
Required: true,
53-
Description: `The metric descriptor associated with the logs-based metric.`,
54-
MaxItems: 1,
55-
Elem: &schema.Resource{
56-
Schema: map[string]*schema.Schema{
57-
"metric_kind": {
58-
Type: schema.TypeString,
59-
Required: true,
60-
ValidateFunc: validateEnum([]string{"DELTA", "GAUGE", "CUMULATIVE"}),
61-
Description: `Whether the metric records instantaneous values, changes to a value, etc.
62-
Some combinations of metricKind and valueType might not be supported.
63-
For counter metrics, set this to DELTA. Possible values: ["DELTA", "GAUGE", "CUMULATIVE"]`,
64-
},
65-
"value_type": {
66-
Type: schema.TypeString,
67-
Required: true,
68-
ValidateFunc: validateEnum([]string{"BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"}),
69-
Description: `Whether the measurement is an integer, a floating-point number, etc.
70-
Some combinations of metricKind and valueType might not be supported.
71-
For counter metrics, set this to INT64. Possible values: ["BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"]`,
72-
},
73-
"display_name": {
74-
Type: schema.TypeString,
75-
Optional: true,
76-
Description: `A concise name for the metric, which can be displayed in user interfaces. Use sentence case
77-
without an ending period, for example "Request count". This field is optional but it is
78-
recommended to be set for any metrics associated with user-visible concepts, such as Quota.`,
79-
},
80-
"labels": {
81-
Type: schema.TypeSet,
82-
Optional: true,
83-
Description: `The set of labels that can be used to describe a specific instance of this metric type. For
84-
example, the appengine.googleapis.com/http/server/response_latencies metric type has a label
85-
for the HTTP response code, response_code, so you can look at latencies for successful responses
86-
or just for responses that failed.`,
87-
Elem: loggingMetricMetricDescriptorLabelsSchema(),
88-
// Default schema.HashSchema is used.
89-
},
90-
"unit": {
91-
Type: schema.TypeString,
92-
Optional: true,
93-
Description: `The unit in which the metric value is reported. It is only applicable if the valueType is
94-
'INT64', 'DOUBLE', or 'DISTRIBUTION'. The supported units are a subset of
95-
[The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard`,
96-
Default: "1",
97-
},
98-
},
99-
},
100-
},
10150
"name": {
10251
Type: schema.TypeString,
10352
Required: true,
@@ -218,6 +167,61 @@ have an associated extractor expression in this map. The syntax of the extractor
218167
the same as for the valueExtractor field.`,
219168
Elem: &schema.Schema{Type: schema.TypeString},
220169
},
170+
"metric_descriptor": {
171+
Type: schema.TypeList,
172+
Computed: true,
173+
Optional: true,
174+
Description: `The optional metric descriptor associated with the logs-based metric.
175+
If unspecified, it uses a default metric descriptor with a DELTA metric kind,
176+
INT64 value type, with no labels and a unit of "1". Such a metric counts the
177+
number of log entries matching the filter expression.`,
178+
MaxItems: 1,
179+
Elem: &schema.Resource{
180+
Schema: map[string]*schema.Schema{
181+
"metric_kind": {
182+
Type: schema.TypeString,
183+
Required: true,
184+
ValidateFunc: validateEnum([]string{"DELTA", "GAUGE", "CUMULATIVE"}),
185+
Description: `Whether the metric records instantaneous values, changes to a value, etc.
186+
Some combinations of metricKind and valueType might not be supported.
187+
For counter metrics, set this to DELTA. Possible values: ["DELTA", "GAUGE", "CUMULATIVE"]`,
188+
},
189+
"value_type": {
190+
Type: schema.TypeString,
191+
Required: true,
192+
ValidateFunc: validateEnum([]string{"BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"}),
193+
Description: `Whether the measurement is an integer, a floating-point number, etc.
194+
Some combinations of metricKind and valueType might not be supported.
195+
For counter metrics, set this to INT64. Possible values: ["BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"]`,
196+
},
197+
"display_name": {
198+
Type: schema.TypeString,
199+
Optional: true,
200+
Description: `A concise name for the metric, which can be displayed in user interfaces. Use sentence case
201+
without an ending period, for example "Request count". This field is optional but it is
202+
recommended to be set for any metrics associated with user-visible concepts, such as Quota.`,
203+
},
204+
"labels": {
205+
Type: schema.TypeSet,
206+
Optional: true,
207+
Description: `The set of labels that can be used to describe a specific instance of this metric type. For
208+
example, the appengine.googleapis.com/http/server/response_latencies metric type has a label
209+
for the HTTP response code, response_code, so you can look at latencies for successful responses
210+
or just for responses that failed.`,
211+
Elem: loggingMetricMetricDescriptorLabelsSchema(),
212+
// Default schema.HashSchema is used.
213+
},
214+
"unit": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
Description: `The unit in which the metric value is reported. It is only applicable if the valueType is
218+
'INT64', 'DOUBLE', or 'DISTRIBUTION'. The supported units are a subset of
219+
[The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard`,
220+
Default: "1",
221+
},
222+
},
223+
},
224+
},
221225
"value_extractor": {
222226
Type: schema.TypeString,
223227
Optional: true,

google-beta/resource_logging_metric_generated_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ resource "google_logging_metric" "logging_metric" {
203203
name = "tf-test-my-(custom)/metric%{random_suffix}"
204204
filter = "resource.type=gae_app AND severity>=ERROR"
205205
bucket_name = google_logging_project_bucket_config.logging_metric.id
206-
207-
metric_descriptor {
208-
metric_kind = "DELTA"
209-
value_type = "INT64"
210-
unit = "1"
211-
}
212206
}
213207
`, context)
214208
}

google-beta/resource_logging_metric_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ func testAccLoggingMetric_loggingBucketBase(suffix string, filter string) string
173173
resource "google_logging_metric" "logging_metric" {
174174
name = "my-custom-metric-%s"
175175
filter = "%s"
176-
177-
metric_descriptor {
178-
metric_kind = "DELTA"
179-
unit = "1"
180-
value_type = "INT64"
181-
}
182176
}
183177
`, suffix, filter)
184178
}
@@ -195,12 +189,6 @@ resource "google_logging_metric" "logging_metric" {
195189
name = "my-custom-metric-%s"
196190
bucket_name = google_logging_project_bucket_config.logging_bucket.id
197191
filter = "%s"
198-
199-
metric_descriptor {
200-
metric_kind = "DELTA"
201-
unit = "1"
202-
value_type = "INT64"
203-
}
204192
}
205193
`, project_id, suffix, filter)
206194
}

website/docs/r/logging_metric.html.markdown

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ resource "google_logging_metric" "logging_metric" {
132132
name = "my-(custom)/metric"
133133
filter = "resource.type=gae_app AND severity>=ERROR"
134134
bucket_name = google_logging_project_bucket_config.logging_metric.id
135-
136-
metric_descriptor {
137-
metric_kind = "DELTA"
138-
value_type = "INT64"
139-
unit = "1"
140-
}
141135
}
142136
```
143137

@@ -159,11 +153,54 @@ The following arguments are supported:
159153
An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which
160154
is used to match log entries.
161155

156+
157+
- - -
158+
159+
160+
* `description` -
161+
(Optional)
162+
A description of this metric, which is used in documentation. The maximum length of the
163+
description is 8000 characters.
164+
165+
* `bucket_name` -
166+
(Optional)
167+
The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects
168+
are supported. The bucket has to be in the same project as the metric.
169+
162170
* `metric_descriptor` -
163-
(Required)
164-
The metric descriptor associated with the logs-based metric.
171+
(Optional)
172+
The optional metric descriptor associated with the logs-based metric.
173+
If unspecified, it uses a default metric descriptor with a DELTA metric kind,
174+
INT64 value type, with no labels and a unit of "1". Such a metric counts the
175+
number of log entries matching the filter expression.
165176
Structure is [documented below](#nested_metric_descriptor).
166177

178+
* `label_extractors` -
179+
(Optional)
180+
A map from a label key string to an extractor expression which is used to extract data from a log
181+
entry field and assign as the label value. Each label key specified in the LabelDescriptor must
182+
have an associated extractor expression in this map. The syntax of the extractor expression is
183+
the same as for the valueExtractor field.
184+
185+
* `value_extractor` -
186+
(Optional)
187+
A valueExtractor is required when using a distribution logs-based metric to extract the values to
188+
record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or
189+
REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which
190+
the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax
191+
(https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified
192+
log entry field. The value of the field is converted to a string before applying the regex. It is an
193+
error to specify a regex that does not include exactly one capture group.
194+
195+
* `bucket_options` -
196+
(Optional)
197+
The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it
198+
describes the bucket boundaries used to create a histogram of the extracted values.
199+
Structure is [documented below](#nested_bucket_options).
200+
201+
* `project` - (Optional) The ID of the project in which the resource belongs.
202+
If it is not provided, the provider project is used.
203+
167204

168205
<a name="nested_metric_descriptor"></a>The `metric_descriptor` block supports:
169206

@@ -218,46 +255,6 @@ The following arguments are supported:
218255
Default value is `STRING`.
219256
Possible values are `BOOL`, `INT64`, and `STRING`.
220257

221-
- - -
222-
223-
224-
* `description` -
225-
(Optional)
226-
A description of this metric, which is used in documentation. The maximum length of the
227-
description is 8000 characters.
228-
229-
* `bucket_name` -
230-
(Optional)
231-
The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects
232-
are supported. The bucket has to be in the same project as the metric.
233-
234-
* `label_extractors` -
235-
(Optional)
236-
A map from a label key string to an extractor expression which is used to extract data from a log
237-
entry field and assign as the label value. Each label key specified in the LabelDescriptor must
238-
have an associated extractor expression in this map. The syntax of the extractor expression is
239-
the same as for the valueExtractor field.
240-
241-
* `value_extractor` -
242-
(Optional)
243-
A valueExtractor is required when using a distribution logs-based metric to extract the values to
244-
record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or
245-
REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which
246-
the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax
247-
(https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified
248-
log entry field. The value of the field is converted to a string before applying the regex. It is an
249-
error to specify a regex that does not include exactly one capture group.
250-
251-
* `bucket_options` -
252-
(Optional)
253-
The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it
254-
describes the bucket boundaries used to create a histogram of the extracted values.
255-
Structure is [documented below](#nested_bucket_options).
256-
257-
* `project` - (Optional) The ID of the project in which the resource belongs.
258-
If it is not provided, the provider project is used.
259-
260-
261258
<a name="nested_bucket_options"></a>The `bucket_options` block supports:
262259

263260
* `linear_buckets` -

0 commit comments

Comments
 (0)