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

Meagn logging metric unit #4407

Merged
merged 1 commit into from
Sep 6, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions google/resource_logging_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func resourceLoggingMetric() *schema.Resource {
},
},
},
"unit": {
Type: schema.TypeString,
Optional: true,
Default: "1",
},
},
},
},
Expand Down Expand Up @@ -456,6 +461,8 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData)
return nil
}
transformed := make(map[string]interface{})
transformed["unit"] =
flattenLoggingMetricMetricDescriptorUnit(original["unit"], d)
transformed["value_type"] =
flattenLoggingMetricMetricDescriptorValueType(original["valueType"], d)
transformed["metric_kind"] =
Expand All @@ -464,6 +471,10 @@ func flattenLoggingMetricMetricDescriptor(v interface{}, d *schema.ResourceData)
flattenLoggingMetricMetricDescriptorLabels(original["labels"], d)
return []interface{}{transformed}
}
func flattenLoggingMetricMetricDescriptorUnit(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenLoggingMetricMetricDescriptorValueType(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand Down Expand Up @@ -652,6 +663,13 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData,
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedUnit, err := expandLoggingMetricMetricDescriptorUnit(original["unit"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUnit); val.IsValid() && !isEmptyValue(val) {
transformed["unit"] = transformedUnit
}

transformedValueType, err := expandLoggingMetricMetricDescriptorValueType(original["value_type"], d, config)
if err != nil {
return nil, err
Expand All @@ -676,6 +694,10 @@ func expandLoggingMetricMetricDescriptor(v interface{}, d TerraformResourceData,
return transformed, nil
}

func expandLoggingMetricMetricDescriptorUnit(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandLoggingMetricMetricDescriptorValueType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
1 change: 1 addition & 0 deletions google/resource_logging_metric_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "google_logging_metric" "logging_metric" {
metric_descriptor {
metric_kind = "DELTA"
value_type = "DISTRIBUTION"
unit = "1"
labels {
key = "mass"
value_type = "STRING"
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/logging_metric.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ resource "google_logging_metric" "logging_metric" {
metric_descriptor {
metric_kind = "DELTA"
value_type = "DISTRIBUTION"
unit = "1"
labels {
key = "mass"
value_type = "STRING"
Expand Down Expand Up @@ -133,6 +134,12 @@ The following arguments are supported:

The `metric_descriptor` block supports:

* `unit` -
(Optional)
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

* `value_type` -
(Required)
Whether the measurement is an integer, a floating-point number, etc.
Expand Down