forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging-metrics.tf
120 lines (117 loc) · 4.5 KB
/
logging-metrics.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
_logging_metrics_factory_data_raw = merge([
for k in local.observability_factory_data_raw :
lookup(k, "logging_metrics", {})
]...)
_logging_metrics_factory_data = {
for k, v in local._logging_metrics_factory_data_raw :
k => {
filter = v.filter
bucket_name = try(v.bucket_name, null)
description = try(v.description, null)
disabled = try(v.disabled, null)
label_extractors = try(v.label_extractors, null)
value_extractor = try(v.value_extractor, null)
bucket_options = !can(v.bucket_options) ? null : {
explicit_buckets = !can(v.bucket_options.explicit_buckets) ? null : {
bounds = v.bucket_options.explicit_buckets.bounds
}
exponential_buckets = !can(v.bucket_options.exponential_buckets) ? null : {
num_finite_buckets = v.bucket_options.exponential_buckets.num_finite_buckets
growth_factor = v.bucket_options.exponential_buckets.growth_factor
scale = v.bucket_options.exponential_buckets.scale
}
linear_buckets = !can(v.bucket_options.linear_buckets) ? null : {
num_finite_buckets = v.bucket_options.linear_buckets.num_finite_buckets
width = v.bucket_options.linear_buckets.width
offset = v.bucket_options.linear_buckets.offset
}
}
metric_descriptor = !can(v.metric_descriptor) ? null : {
metric_kind = v.metric_descriptor.metric_kind
value_type = v.metric_descriptor.value_type
display_name = try(v.metric_descriptor.display_name, null)
unit = try(v.metric_descriptor.unit, null)
labels = !can(v.metric_descriptor.labels) ? [] : [
for vv in v.metric_descriptor.labels :
{
key = vv.key
description = try(vv.description, null)
value_type = try(vv.value_type, null)
}
]
}
}
}
metrics = merge(local._logging_metrics_factory_data, var.logging_metrics)
}
resource "google_logging_metric" "metrics" {
for_each = local.metrics
project = local.project.project_id
name = each.key
filter = each.value.filter
description = each.value.description
disabled = each.value.disabled
bucket_name = each.value.bucket_name
value_extractor = each.value.value_extractor
label_extractors = each.value.label_extractors
dynamic "bucket_options" {
for_each = each.value.bucket_options[*]
content {
dynamic "explicit_buckets" {
for_each = bucket_options.value.explicit_buckets[*]
content {
bounds = explicit_buckets.value.bounds
}
}
dynamic "exponential_buckets" {
for_each = bucket_options.value.exponential_buckets[*]
content {
num_finite_buckets = exponential_buckets.value.num_finite_buckets
growth_factor = exponential_buckets.value.growth_factor
scale = exponential_buckets.value.scale
}
}
dynamic "linear_buckets" {
for_each = bucket_options.value.linear_buckets[*]
content {
num_finite_buckets = linear_buckets.value.num_finite_buckets
width = linear_buckets.value.width
offset = linear_buckets.value.offset
}
}
}
}
dynamic "metric_descriptor" {
for_each = each.value.metric_descriptor[*]
content {
metric_kind = metric_descriptor.value.metric_kind
value_type = metric_descriptor.value.value_type
display_name = metric_descriptor.value.display_name
unit = metric_descriptor.value.unit
dynamic "labels" {
for_each = metric_descriptor.value.labels
content {
key = labels.value.key
description = labels.value.description
value_type = labels.value.value_type
}
}
}
}
}