diff --git a/.changelog/6937.txt b/.changelog/6937.txt new file mode 100644 index 00000000000..781b35f2ad0 --- /dev/null +++ b/.changelog/6937.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +logging: made `metric_descriptor` argument optional for `google_logging_metric` +``` diff --git a/google/resource_logging_metric.go b/google/resource_logging_metric.go index 247e4177447..daacdf61b01 100644 --- a/google/resource_logging_metric.go +++ b/google/resource_logging_metric.go @@ -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, @@ -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, diff --git a/google/resource_logging_metric_generated_test.go b/google/resource_logging_metric_generated_test.go index d1b8179b499..c39443aa4c9 100644 --- a/google/resource_logging_metric_generated_test.go +++ b/google/resource_logging_metric_generated_test.go @@ -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) } diff --git a/google/resource_logging_metric_test.go b/google/resource_logging_metric_test.go index d42cfe153f9..b86f76d2dd2 100644 --- a/google/resource_logging_metric_test.go +++ b/google/resource_logging_metric_test.go @@ -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) } @@ -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) } diff --git a/website/docs/r/logging_metric.html.markdown b/website/docs/r/logging_metric.html.markdown index 5062573e47e..d5a66548e7c 100644 --- a/website/docs/r/logging_metric.html.markdown +++ b/website/docs/r/logging_metric.html.markdown @@ -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" - } } ``` @@ -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. + The `metric_descriptor` block supports: @@ -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. - - The `bucket_options` block supports: * `linear_buckets` -