Skip to content

Commit

Permalink
feat: add support for metrics routing (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamar7 authored Dec 17, 2024
1 parent 414c771 commit a93e86d
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 10 deletions.
6 changes: 6 additions & 0 deletions ibm_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@
"value": "private"
}
]
},
{
"key": "enable_metrics_routing_to_cloud_monitoring"
},
{
"key": "metrics_router_routes"
}
],
"architecture": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions solutions/instances/DA-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Several optional input variables in the IBM Cloud [Observability instances deplo

* Cloud Logs Event Notification Instances (`cloud_logs_existing_en_instances`)
* Cloud Logs policies (`cloud_logs_policies`)
* Metrics Router Routes (`metrics_router_routes`)


## Cloud Logs Event Notification Instances <a name="cloud_logs_existing_en_instances"></a>
Expand Down Expand Up @@ -88,3 +89,44 @@ cloud_logs_policies = [
}
]
```

## Metrics Router Routes <a name="metrics_router_routes"></a>

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.

- Variable name: `metrics_router_routes`.
- Type: A list of objects. Each object represents a route.
- Default value: An empty list (`[]`).

### Options for metrics_router_routes

- `name` (required): The name of the route.
- `rules` (required): The routing rules that will be evaluated in their order of the array. You can configure up to 10 rules per route.
- `action` (optional): The action if the inclusion_filters matches, default is send action. Allowed values are `send` and `drop`.
- `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:
- `operand` - Part of CRN that can be compared with values. Allowable values are: `location`, `service_name`, `service_instance`, `resource_type`, `resource`.

- `operator` - The operation to be performed between operand and the provided values. Allowable values are: `is`, `in`.

- `values` - The provided string values of the operand to be compared with.
- `targets` (required): The target uuid for a pre-defined metrics router target.

### Example metrics_router_routes

```hcl
metrics_router_routes = {
name = "my-route"
rules {
action = "send"
targets {
id = "c3af557f-fb0e-4476-85c3-0889e7fe7bc4"
}
inclusion_filters {
operand = "location"
operator = "is"
values = [ "us-south" ]
}
}
}
```
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.
1 change: 1 addition & 0 deletions solutions/instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This deployable architecture creates observability instances in IBM Cloud and su
* A KMS-encrypted Object Storage bucket for Cloud Logs data, if one is not passed in.
* A KMS-encrypted Object Storage bucket for Cloud Logs metrics, if one is not passed in.
* An Activity Tracker event route to an Object Storage bucket and Cloud Logs target.
* An IBM Cloud Metric Routing, setting route to a Cloud Monitoring target.
* An option to integrate Cloud Logs with existing event notification instance.
* An option to configure Cloud logs policies (TCO Optimizer).

Expand Down
47 changes: 40 additions & 7 deletions solutions/instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ locals {
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
# tflint-ignore: terraform_unused_declarations
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
# tflint-ignore: terraform_unused_declarations
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

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

Expand Down Expand Up @@ -51,6 +53,19 @@ locals {
cloud_logs_target_name = var.prefix != null ? "${var.prefix}-cloud-logs-target" : "cloud-logs-target"
at_cos_route_name = var.prefix != null ? "${var.prefix}-at-cos-route" : "at-cos-route"
at_cloud_logs_route_name = var.prefix != null ? "${var.prefix}-at-cloud-logs-route" : "at-cloud-logs-route"
metric_router_target_name = var.prefix != null ? "${var.prefix}-cloud-monitoring-target" : "cloud-monitoring-target"
metric_router_route_name = var.prefix != null ? "${var.prefix}-metric-routing-route" : "metric-routing-route"

default_metrics_router_route = [{
name = local.metric_router_route_name
rules = [{
action = "send"
targets = [{
id = module.observability_instance.metrics_router_targets[local.metric_router_target_name].id
}]
inclusion_filters = []
}]
}]

archive_bucket_config = var.manage_log_archive_cos_bucket ? {
class = var.log_archive_cos_bucket_class
Expand Down Expand Up @@ -155,13 +170,11 @@ module "cos_resource_group" {
#######################################################################################################################

locals {
parsed_existing_cloud_monitoring_crn = var.existing_cloud_monitoring_crn != null ? split(":", var.existing_cloud_monitoring_crn) : []
existing_cloud_monitoring_guid = length(local.parsed_existing_cloud_monitoring_crn) > 0 ? local.parsed_existing_cloud_monitoring_crn[7] : null
cloud_monitoring_instance_name = var.prefix != null ? "${var.prefix}-${var.cloud_monitoring_instance_name}" : var.cloud_monitoring_instance_name
cloud_logs_instance_name = var.prefix != null ? "${var.prefix}-cloud-logs" : var.cloud_logs_instance_name
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
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
cloud_logs_buckets = [local.cloud_logs_data_bucket_crn, local.cloud_log_metrics_bucket_crn]
cloud_monitoring_instance_name = var.prefix != null ? "${var.prefix}-${var.cloud_monitoring_instance_name}" : var.cloud_monitoring_instance_name
cloud_logs_instance_name = var.prefix != null ? "${var.prefix}-cloud-logs" : var.cloud_logs_instance_name
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
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
cloud_logs_buckets = [local.cloud_logs_data_bucket_crn, local.cloud_log_metrics_bucket_crn]
}

data "ibm_iam_account_settings" "iam_account_settings" {
Expand Down Expand Up @@ -213,6 +226,13 @@ module "en_crn_parser" {
crn = local.cloud_logs_existing_en_instances[count.index]["instance_crn"]
}

module "cloud_monitoring_crn_parser" {
count = var.existing_cloud_monitoring_crn != null ? 1 : 0
source = "terraform-ibm-modules/common-utilities/ibm//modules/crn-parser"
version = "1.0.0"
crn = var.existing_cloud_monitoring_crn
}

module "observability_instance" {
depends_on = [time_sleep.wait_for_atracker_cos_authorization_policy]
source = "terraform-ibm-modules/observability-instances/ibm"
Expand Down Expand Up @@ -284,6 +304,19 @@ module "observability_instance" {

# Routes
activity_tracker_routes = local.at_routes

# IBM Cloud Metrics Routing

metrics_router_targets = local.validate_metrics_routing ? [
{
destination_crn = var.cloud_monitoring_provision ? module.observability_instance.cloud_monitoring_crn : var.existing_cloud_monitoring_crn
target_name = local.metric_router_target_name
target_region = var.cloud_monitoring_provision ? var.region : module.cloud_monitoring_crn_parser.region
skip_mrouter_sysdig_iam_auth_policy = false
}
] : []

metrics_router_routes = local.validate_metrics_routing ? (var.metrics_router_routes != null ? var.metrics_router_routes : local.default_metrics_router_route) : []
}

resource "time_sleep" "wait_for_atracker_cos_authorization_policy" {
Expand Down
14 changes: 13 additions & 1 deletion solutions/instances/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ output "cloud_monitoring_crn" {
}

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

Expand Down Expand Up @@ -120,3 +120,15 @@ output "kms_keys" {
description = "IDs of new KMS Keys created"
value = length(module.kms) > 0 ? module.kms[0].keys : null
}

## Metrics Routing

output "metrics_router_targets" {
description = "The map of created metrics routing targets."
value = var.enable_metrics_routing_to_cloud_monitoring ? module.observability_instance.metrics_router_targets : null
}

output "metrics_router_routes" {
description = "The map of created metrics routing routes."
value = var.enable_metrics_routing_to_cloud_monitoring ? module.observability_instance.metrics_router_routes : null
}
31 changes: 30 additions & 1 deletion solutions/instances/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ variable "cloud_logs_policies" {
id = string
})))
}))
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)."
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-)."
default = []
}

Expand All @@ -276,6 +276,35 @@ variable "enable_at_event_routing_to_cloud_logs" {
default = true
}

##############################################################################
# Metric Routing Variables
##############################################################################

variable "metrics_router_routes" {
type = list(object({
name = string
rules = list(object({
action = string
targets = list(object({
id = string
}))
inclusion_filters = list(object({
operand = string
operator = string
values = list(string)
}))
}))
}))
default = []
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-)"
}

variable "enable_metrics_routing_to_cloud_monitoring" {
type = bool
description = "Whether to enable metrics routing from IBM Cloud Metric Routing to Cloud Monitoring."
default = true
}

##############################################################################
# Cloud Monitoring Variables
##############################################################################
Expand Down

0 comments on commit a93e86d

Please sign in to comment.