Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#13215] Make metric_descriptor argument optional for google_logging_metric #13225

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6937.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
logging: made `metric_descriptor` argument optional for `google_logging_metric`
```
106 changes: 55 additions & 51 deletions google/resource_logging_metric.go
Expand Up @@ -47,57 +47,6 @@ func resourceLoggingMetric() *schema.Resource {
Description: `An advanced logs filter (https://cloud.google.com/logging/docs/view/advanced-filters) which
is used to match log entries.`,
},
"metric_descriptor": {
Type: schema.TypeList,
Required: true,
Description: `The metric descriptor associated with the logs-based metric.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"metric_kind": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEnum([]string{"DELTA", "GAUGE", "CUMULATIVE"}),
Description: `Whether the metric records instantaneous values, changes to a value, etc.
Some combinations of metricKind and valueType might not be supported.
For counter metrics, set this to DELTA. Possible values: ["DELTA", "GAUGE", "CUMULATIVE"]`,
},
"value_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEnum([]string{"BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"}),
Description: `Whether the measurement is an integer, a floating-point number, etc.
Some combinations of metricKind and valueType might not be supported.
For counter metrics, set this to INT64. Possible values: ["BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"]`,
},
"display_name": {
Type: schema.TypeString,
Optional: true,
Description: `A concise name for the metric, which can be displayed in user interfaces. Use sentence case
without an ending period, for example "Request count". This field is optional but it is
recommended to be set for any metrics associated with user-visible concepts, such as Quota.`,
},
"labels": {
Type: schema.TypeSet,
Optional: true,
Description: `The set of labels that can be used to describe a specific instance of this metric type. For
example, the appengine.googleapis.com/http/server/response_latencies metric type has a label
for the HTTP response code, response_code, so you can look at latencies for successful responses
or just for responses that failed.`,
Elem: loggingMetricMetricDescriptorLabelsSchema(),
// Default schema.HashSchema is used.
},
"unit": {
Type: schema.TypeString,
Optional: true,
Description: `The unit in which the metric value is reported. It is only applicable if the valueType is
'INT64', 'DOUBLE', or 'DISTRIBUTION'. The supported units are a subset of
[The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard`,
Default: "1",
},
},
},
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -218,6 +167,61 @@ have an associated extractor expression in this map. The syntax of the extractor
the same as for the valueExtractor field.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"metric_descriptor": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `The optional metric descriptor associated with the logs-based metric.
If unspecified, it uses a default metric descriptor with a DELTA metric kind,
INT64 value type, with no labels and a unit of "1". Such a metric counts the
number of log entries matching the filter expression.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"metric_kind": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEnum([]string{"DELTA", "GAUGE", "CUMULATIVE"}),
Description: `Whether the metric records instantaneous values, changes to a value, etc.
Some combinations of metricKind and valueType might not be supported.
For counter metrics, set this to DELTA. Possible values: ["DELTA", "GAUGE", "CUMULATIVE"]`,
},
"value_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateEnum([]string{"BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"}),
Description: `Whether the measurement is an integer, a floating-point number, etc.
Some combinations of metricKind and valueType might not be supported.
For counter metrics, set this to INT64. Possible values: ["BOOL", "INT64", "DOUBLE", "STRING", "DISTRIBUTION", "MONEY"]`,
},
"display_name": {
Type: schema.TypeString,
Optional: true,
Description: `A concise name for the metric, which can be displayed in user interfaces. Use sentence case
without an ending period, for example "Request count". This field is optional but it is
recommended to be set for any metrics associated with user-visible concepts, such as Quota.`,
},
"labels": {
Type: schema.TypeSet,
Optional: true,
Description: `The set of labels that can be used to describe a specific instance of this metric type. For
example, the appengine.googleapis.com/http/server/response_latencies metric type has a label
for the HTTP response code, response_code, so you can look at latencies for successful responses
or just for responses that failed.`,
Elem: loggingMetricMetricDescriptorLabelsSchema(),
// Default schema.HashSchema is used.
},
"unit": {
Type: schema.TypeString,
Optional: true,
Description: `The unit in which the metric value is reported. It is only applicable if the valueType is
'INT64', 'DOUBLE', or 'DISTRIBUTION'. The supported units are a subset of
[The Unified Code for Units of Measure](http://unitsofmeasure.org/ucum.html) standard`,
Default: "1",
},
},
},
},
"value_extractor": {
Type: schema.TypeString,
Optional: true,
Expand Down
6 changes: 0 additions & 6 deletions google/resource_logging_metric_generated_test.go
Expand Up @@ -203,12 +203,6 @@ resource "google_logging_metric" "logging_metric" {
name = "tf-test-my-(custom)/metric%{random_suffix}"
filter = "resource.type=gae_app AND severity>=ERROR"
bucket_name = google_logging_project_bucket_config.logging_metric.id

metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
unit = "1"
}
}
`, context)
}
Expand Down
12 changes: 0 additions & 12 deletions google/resource_logging_metric_test.go
Expand Up @@ -173,12 +173,6 @@ func testAccLoggingMetric_loggingBucketBase(suffix string, filter string) string
resource "google_logging_metric" "logging_metric" {
name = "my-custom-metric-%s"
filter = "%s"

metric_descriptor {
metric_kind = "DELTA"
unit = "1"
value_type = "INT64"
}
}
`, suffix, filter)
}
Expand All @@ -195,12 +189,6 @@ resource "google_logging_metric" "logging_metric" {
name = "my-custom-metric-%s"
bucket_name = google_logging_project_bucket_config.logging_bucket.id
filter = "%s"

metric_descriptor {
metric_kind = "DELTA"
unit = "1"
value_type = "INT64"
}
}
`, project_id, suffix, filter)
}
Expand Down
93 changes: 45 additions & 48 deletions website/docs/r/logging_metric.html.markdown
Expand Up @@ -132,12 +132,6 @@ resource "google_logging_metric" "logging_metric" {
name = "my-(custom)/metric"
filter = "resource.type=gae_app AND severity>=ERROR"
bucket_name = google_logging_project_bucket_config.logging_metric.id

metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
unit = "1"
}
}
```

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


- - -


* `description` -
(Optional)
A description of this metric, which is used in documentation. The maximum length of the
description is 8000 characters.

* `bucket_name` -
(Optional)
The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects
are supported. The bucket has to be in the same project as the metric.

* `metric_descriptor` -
(Required)
The metric descriptor associated with the logs-based metric.
(Optional)
The optional metric descriptor associated with the logs-based metric.
If unspecified, it uses a default metric descriptor with a DELTA metric kind,
INT64 value type, with no labels and a unit of "1". Such a metric counts the
number of log entries matching the filter expression.
Structure is [documented below](#nested_metric_descriptor).

* `label_extractors` -
(Optional)
A map from a label key string to an extractor expression which is used to extract data from a log
entry field and assign as the label value. Each label key specified in the LabelDescriptor must
have an associated extractor expression in this map. The syntax of the extractor expression is
the same as for the valueExtractor field.

* `value_extractor` -
(Optional)
A valueExtractor is required when using a distribution logs-based metric to extract the values to
record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or
REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which
the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax
(https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified
log entry field. The value of the field is converted to a string before applying the regex. It is an
error to specify a regex that does not include exactly one capture group.

* `bucket_options` -
(Optional)
The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it
describes the bucket boundaries used to create a histogram of the extracted values.
Structure is [documented below](#nested_bucket_options).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.


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

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

- - -


* `description` -
(Optional)
A description of this metric, which is used in documentation. The maximum length of the
description is 8000 characters.

* `bucket_name` -
(Optional)
The resource name of the Log Bucket that owns the Log Metric. Only Log Buckets in projects
are supported. The bucket has to be in the same project as the metric.

* `label_extractors` -
(Optional)
A map from a label key string to an extractor expression which is used to extract data from a log
entry field and assign as the label value. Each label key specified in the LabelDescriptor must
have an associated extractor expression in this map. The syntax of the extractor expression is
the same as for the valueExtractor field.

* `value_extractor` -
(Optional)
A valueExtractor is required when using a distribution logs-based metric to extract the values to
record from a log entry. Two functions are supported for value extraction - EXTRACT(field) or
REGEXP_EXTRACT(field, regex). The argument are 1. field - The name of the log entry field from which
the value is to be extracted. 2. regex - A regular expression using the Google RE2 syntax
(https://github.com/google/re2/wiki/Syntax) with a single capture group to extract data from the specified
log entry field. The value of the field is converted to a string before applying the regex. It is an
error to specify a regex that does not include exactly one capture group.

* `bucket_options` -
(Optional)
The bucketOptions are required when the logs-based metric is using a DISTRIBUTION value type and it
describes the bucket boundaries used to create a histogram of the extracted values.
Structure is [documented below](#nested_bucket_options).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.


<a name="nested_bucket_options"></a>The `bucket_options` block supports:

* `linear_buckets` -
Expand Down