Skip to content

Commit a93e86d

Browse files
authored
feat: add support for metrics routing (#208)
1 parent 414c771 commit a93e86d

File tree

7 files changed

+133
-10
lines changed

7 files changed

+133
-10
lines changed

ibm_catalog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@
449449
"value": "private"
450450
}
451451
]
452+
},
453+
{
454+
"key": "enable_metrics_routing_to_cloud_monitoring"
455+
},
456+
{
457+
"key": "metrics_router_routes"
452458
}
453459
],
454460
"architecture": {

reference-architecture/deployable-architecture-observability-instances.svg

Lines changed: 1 addition & 1 deletion
Loading

solutions/instances/DA-types.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Several optional input variables in the IBM Cloud [Observability instances deplo
44

55
* Cloud Logs Event Notification Instances (`cloud_logs_existing_en_instances`)
66
* Cloud Logs policies (`cloud_logs_policies`)
7+
* Metrics Router Routes (`metrics_router_routes`)
78

89

910
## Cloud Logs Event Notification Instances <a name="cloud_logs_existing_en_instances"></a>
@@ -88,3 +89,44 @@ cloud_logs_policies = [
8889
}
8990
]
9091
```
92+
93+
## Metrics Router Routes <a name="metrics_router_routes"></a>
94+
95+
The `metrics_router_routes` input variable allows you to provide a list of routes that will be configured in the IBM Cloud Metrics Routing. Refer [here](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-about) for more information.
96+
97+
- Variable name: `metrics_router_routes`.
98+
- Type: A list of objects. Each object represents a route.
99+
- Default value: An empty list (`[]`).
100+
101+
### Options for metrics_router_routes
102+
103+
- `name` (required): The name of the route.
104+
- `rules` (required): The routing rules that will be evaluated in their order of the array. You can configure up to 10 rules per route.
105+
- `action` (optional): The action if the inclusion_filters matches, default is send action. Allowed values are `send` and `drop`.
106+
- `inclusion_filters` (required): A list of conditions to be satisfied for routing metrics to pre-defined target.'inclusion_filters' is an object with three parameters:
107+
- `operand` - Part of CRN that can be compared with values. Allowable values are: `location`, `service_name`, `service_instance`, `resource_type`, `resource`.
108+
109+
- `operator` - The operation to be performed between operand and the provided values. Allowable values are: `is`, `in`.
110+
111+
- `values` - The provided string values of the operand to be compared with.
112+
- `targets` (required): The target uuid for a pre-defined metrics router target.
113+
114+
### Example metrics_router_routes
115+
116+
```hcl
117+
metrics_router_routes = {
118+
name = "my-route"
119+
rules {
120+
action = "send"
121+
targets {
122+
id = "c3af557f-fb0e-4476-85c3-0889e7fe7bc4"
123+
}
124+
inclusion_filters {
125+
operand = "location"
126+
operator = "is"
127+
values = [ "us-south" ]
128+
}
129+
}
130+
}
131+
```
132+
Refer [here](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-route_rules_definitions&interface=ui) for more information about IBM Cloud Metrics Routing route.

solutions/instances/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This deployable architecture creates observability instances in IBM Cloud and su
1212
* A KMS-encrypted Object Storage bucket for Cloud Logs data, if one is not passed in.
1313
* A KMS-encrypted Object Storage bucket for Cloud Logs metrics, if one is not passed in.
1414
* An Activity Tracker event route to an Object Storage bucket and Cloud Logs target.
15+
* An IBM Cloud Metric Routing, setting route to a Cloud Monitoring target.
1516
* An option to integrate Cloud Logs with existing event notification instance.
1617
* An option to configure Cloud logs policies (TCO Optimizer).
1718

solutions/instances/main.tf

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ locals {
1010
validate_existing_cloud_monitoring = var.cloud_monitoring_provision && var.existing_cloud_monitoring_crn != null ? tobool("if cloud_monitoring_provision is set to true, then existing_cloud_monitoring_crn should be null and vice versa") : true
1111
# tflint-ignore: terraform_unused_declarations
1212
validate_cos_resource_group = var.existing_cos_instance_crn == null ? var.ibmcloud_cos_api_key != null && var.cos_resource_group_name == null ? tobool("if value for `ibmcloud_cos_api_key` is set, then `cos_resource_group_name` cannot be null") : true : true
13+
# tflint-ignore: terraform_unused_declarations
14+
validate_metrics_routing = var.enable_metrics_routing_to_cloud_monitoring ? ((var.existing_cloud_monitoring_crn != null || var.cloud_monitoring_provision) ? true : tobool("When `enable_metrics_routing_to_cloud_monitoring` is set to true, you must either set `cloud_monitoring_provision` as true or provide the `existing_cloud_monitoring_crn`.")) : true
1315

1416
default_cos_region = var.cos_region != null ? var.cos_region : var.region
1517

@@ -51,6 +53,19 @@ locals {
5153
cloud_logs_target_name = var.prefix != null ? "${var.prefix}-cloud-logs-target" : "cloud-logs-target"
5254
at_cos_route_name = var.prefix != null ? "${var.prefix}-at-cos-route" : "at-cos-route"
5355
at_cloud_logs_route_name = var.prefix != null ? "${var.prefix}-at-cloud-logs-route" : "at-cloud-logs-route"
56+
metric_router_target_name = var.prefix != null ? "${var.prefix}-cloud-monitoring-target" : "cloud-monitoring-target"
57+
metric_router_route_name = var.prefix != null ? "${var.prefix}-metric-routing-route" : "metric-routing-route"
58+
59+
default_metrics_router_route = [{
60+
name = local.metric_router_route_name
61+
rules = [{
62+
action = "send"
63+
targets = [{
64+
id = module.observability_instance.metrics_router_targets[local.metric_router_target_name].id
65+
}]
66+
inclusion_filters = []
67+
}]
68+
}]
5469

5570
archive_bucket_config = var.manage_log_archive_cos_bucket ? {
5671
class = var.log_archive_cos_bucket_class
@@ -155,13 +170,11 @@ module "cos_resource_group" {
155170
#######################################################################################################################
156171

157172
locals {
158-
parsed_existing_cloud_monitoring_crn = var.existing_cloud_monitoring_crn != null ? split(":", var.existing_cloud_monitoring_crn) : []
159-
existing_cloud_monitoring_guid = length(local.parsed_existing_cloud_monitoring_crn) > 0 ? local.parsed_existing_cloud_monitoring_crn[7] : null
160-
cloud_monitoring_instance_name = var.prefix != null ? "${var.prefix}-${var.cloud_monitoring_instance_name}" : var.cloud_monitoring_instance_name
161-
cloud_logs_instance_name = var.prefix != null ? "${var.prefix}-cloud-logs" : var.cloud_logs_instance_name
162-
cloud_logs_data_bucket_crn = var.existing_cloud_logs_data_bucket_crn != null ? var.existing_cloud_logs_data_bucket_crn : module.cos_bucket[0].buckets[local.cloud_log_data_bucket].bucket_crn
163-
cloud_log_metrics_bucket_crn = var.existing_cloud_logs_metrics_bucket_crn != null ? var.existing_cloud_logs_metrics_bucket_crn : module.cos_bucket[0].buckets[local.cloud_log_metrics_bucket].bucket_crn
164-
cloud_logs_buckets = [local.cloud_logs_data_bucket_crn, local.cloud_log_metrics_bucket_crn]
173+
cloud_monitoring_instance_name = var.prefix != null ? "${var.prefix}-${var.cloud_monitoring_instance_name}" : var.cloud_monitoring_instance_name
174+
cloud_logs_instance_name = var.prefix != null ? "${var.prefix}-cloud-logs" : var.cloud_logs_instance_name
175+
cloud_logs_data_bucket_crn = var.existing_cloud_logs_data_bucket_crn != null ? var.existing_cloud_logs_data_bucket_crn : module.cos_bucket[0].buckets[local.cloud_log_data_bucket].bucket_crn
176+
cloud_log_metrics_bucket_crn = var.existing_cloud_logs_metrics_bucket_crn != null ? var.existing_cloud_logs_metrics_bucket_crn : module.cos_bucket[0].buckets[local.cloud_log_metrics_bucket].bucket_crn
177+
cloud_logs_buckets = [local.cloud_logs_data_bucket_crn, local.cloud_log_metrics_bucket_crn]
165178
}
166179

167180
data "ibm_iam_account_settings" "iam_account_settings" {
@@ -213,6 +226,13 @@ module "en_crn_parser" {
213226
crn = local.cloud_logs_existing_en_instances[count.index]["instance_crn"]
214227
}
215228

229+
module "cloud_monitoring_crn_parser" {
230+
count = var.existing_cloud_monitoring_crn != null ? 1 : 0
231+
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
232+
version = "1.0.0"
233+
crn = var.existing_cloud_monitoring_crn
234+
}
235+
216236
module "observability_instance" {
217237
depends_on = [time_sleep.wait_for_atracker_cos_authorization_policy]
218238
source = "terraform-ibm-modules/observability-instances/ibm"
@@ -284,6 +304,19 @@ module "observability_instance" {
284304

285305
# Routes
286306
activity_tracker_routes = local.at_routes
307+
308+
# IBM Cloud Metrics Routing
309+
310+
metrics_router_targets = local.validate_metrics_routing ? [
311+
{
312+
destination_crn = var.cloud_monitoring_provision ? module.observability_instance.cloud_monitoring_crn : var.existing_cloud_monitoring_crn
313+
target_name = local.metric_router_target_name
314+
target_region = var.cloud_monitoring_provision ? var.region : module.cloud_monitoring_crn_parser.region
315+
skip_mrouter_sysdig_iam_auth_policy = false
316+
}
317+
] : []
318+
319+
metrics_router_routes = local.validate_metrics_routing ? (var.metrics_router_routes != null ? var.metrics_router_routes : local.default_metrics_router_route) : []
287320
}
288321

289322
resource "time_sleep" "wait_for_atracker_cos_authorization_policy" {

solutions/instances/outputs.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ output "cloud_monitoring_crn" {
4747
}
4848

4949
output "cloud_monitoring_guid" {
50-
value = var.cloud_monitoring_provision ? module.observability_instance.cloud_monitoring_guid : local.existing_cloud_monitoring_guid
50+
value = var.cloud_monitoring_provision ? module.observability_instance.cloud_monitoring_guid : module.cloud_monitoring_crn_parser[0].service_instance
5151
description = "The guid of the provisioned IBM cloud monitoring instance."
5252
}
5353

@@ -120,3 +120,15 @@ output "kms_keys" {
120120
description = "IDs of new KMS Keys created"
121121
value = length(module.kms) > 0 ? module.kms[0].keys : null
122122
}
123+
124+
## Metrics Routing
125+
126+
output "metrics_router_targets" {
127+
description = "The map of created metrics routing targets."
128+
value = var.enable_metrics_routing_to_cloud_monitoring ? module.observability_instance.metrics_router_targets : null
129+
}
130+
131+
output "metrics_router_routes" {
132+
description = "The map of created metrics routing routes."
133+
value = var.enable_metrics_routing_to_cloud_monitoring ? module.observability_instance.metrics_router_routes : null
134+
}

solutions/instances/variables.tf

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ variable "cloud_logs_policies" {
256256
id = string
257257
})))
258258
}))
259-
description = "Configuration of Cloud Logs policies. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/tree/main/solutions/standard/DA-types.md#cloud_logs_policies)."
259+
description = "Configuration of Cloud Logs policies. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md#cloud-logs-policies-)."
260260
default = []
261261
}
262262

@@ -276,6 +276,35 @@ variable "enable_at_event_routing_to_cloud_logs" {
276276
default = true
277277
}
278278

279+
##############################################################################
280+
# Metric Routing Variables
281+
##############################################################################
282+
283+
variable "metrics_router_routes" {
284+
type = list(object({
285+
name = string
286+
rules = list(object({
287+
action = string
288+
targets = list(object({
289+
id = string
290+
}))
291+
inclusion_filters = list(object({
292+
operand = string
293+
operator = string
294+
values = list(string)
295+
}))
296+
}))
297+
}))
298+
default = []
299+
description = "Routes for IBM Cloud Metrics Routing. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md#metrics-router-routes-)"
300+
}
301+
302+
variable "enable_metrics_routing_to_cloud_monitoring" {
303+
type = bool
304+
description = "Whether to enable metrics routing from IBM Cloud Metric Routing to Cloud Monitoring."
305+
default = true
306+
}
307+
279308
##############################################################################
280309
# Cloud Monitoring Variables
281310
##############################################################################

0 commit comments

Comments
 (0)