google_monitoring_slo

A Service-Level Objective (SLO) describes the level of desired good service. It consists of a service-level indicator (SLI), a performance goal, and a period over which the objective is to be evaluated against that goal. The SLO can use SLIs defined in a number of different manners. Typical SLOs might include "99% of requests in each rolling week have latency below 200 milliseconds" or "99.5% of requests in each calendar month return successfully."

To get more information about Slo, see:

Open in Cloud Shell

Example Usage - Monitoring Slo Appengine

data "google_monitoring_app_engine_service" "default" {
  module_id = "default"
}

resource "google_monitoring_slo" "appeng_slo" {
  service = data.google_monitoring_app_engine_service.default.service_id

  slo_id = "ae-slo"
  display_name = "Terraform Test SLO for App Engine"

  goal = 0.9
  calendar_period = "DAY"

  basic_sli {
    latency {
      threshold = "1s"
    }
  }

  user_labels = {
    my_key       = "my_value"
    my_other_key = "my_other_value"
  }
}
## Example Usage - Monitoring Slo Request Based
resource "google_monitoring_custom_service" "customsrv" {
  service_id = "custom-srv-request-slos"
  display_name = "My Custom Service"
}

resource "google_monitoring_slo" "request_based_slo" {
  service = google_monitoring_custom_service.customsrv.service_id
  slo_id = "consumed-api-slo"
  display_name = "Terraform Test SLO with request based SLI (good total ratio)"

  goal = 0.9
  rolling_period_days = 30

  request_based_sli {
    distribution_cut {
          distribution_filter = "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\" resource.type=\"api\"  "
          range {
            max = 0.5
          }
        }
  }
}
Open in Cloud Shell

Example Usage - Monitoring Slo Windows Based Good Bad Metric Filter

resource "google_monitoring_custom_service" "customsrv" {
  service_id = "custom-srv-windows-slos"
  display_name = "My Custom Service"
}

resource "google_monitoring_slo" "windows_based" {
  service = google_monitoring_custom_service.customsrv.service_id
  display_name = "Terraform Test SLO with window based SLI"

  goal = 0.95
  calendar_period = "FORTNIGHT"

  windows_based_sli {
    window_period = "400s"
    good_bad_metric_filter =  join(" AND ", [
      "metric.type=\"monitoring.googleapis.com/uptime_check/check_passed\"",
      "resource.type=\"uptime_url\"",
    ])
  }
}
Open in Cloud Shell

Example Usage - Monitoring Slo Windows Based Metric Mean

resource "google_monitoring_custom_service" "customsrv" {
  service_id = "custom-srv-windows-slos"
  display_name = "My Custom Service"
}

resource "google_monitoring_slo" "windows_based" {
  service = google_monitoring_custom_service.customsrv.service_id
  display_name = "Terraform Test SLO with window based SLI"

  goal = 0.9
  rolling_period_days = 20

  windows_based_sli {
    window_period = "600s"
    metric_mean_in_range {
      time_series = join(" AND ", [
        "metric.type=\"agent.googleapis.com/cassandra/client_request/latency/95p\"",
        "resource.type=\"gce_instance\"",
      ])

      range {
        max = 5
      }
    }
  }
}
Open in Cloud Shell

Example Usage - Monitoring Slo Windows Based Metric Sum

resource "google_monitoring_custom_service" "customsrv" {
  service_id = "custom-srv-windows-slos"
  display_name = "My Custom Service"
}

resource "google_monitoring_slo" "windows_based" {
  service = google_monitoring_custom_service.customsrv.service_id
  display_name = "Terraform Test SLO with window based SLI"

  goal = 0.9
  rolling_period_days = 20

  windows_based_sli {
    window_period = "400s"
    metric_sum_in_range {
      time_series = join(" AND ", [
        "metric.type=\"monitoring.googleapis.com/uptime_check/request_latency\"",
        "resource.type=\"uptime_url\"",
      ])

      range {
        max = 5000
      }
    }
  }
}
Open in Cloud Shell

Example Usage - Monitoring Slo Windows Based Ratio Threshold

resource "google_monitoring_custom_service" "customsrv" {
  service_id = "custom-srv-windows-slos"
  display_name = "My Custom Service"
}

resource "google_monitoring_slo" "windows_based" {
  service = google_monitoring_custom_service.customsrv.service_id
  display_name = "Terraform Test SLO with window based SLI"

  goal = 0.9
  rolling_period_days = 20

  windows_based_sli {
    window_period = "100s"

    good_total_ratio_threshold {
      threshold = 0.1
      performance {
        distribution_cut {
          distribution_filter = join(" AND ", [
            "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"",
            "resource.type=\"consumed_api\"",
          ])

          range {
            min = 1
            max = 9
          }
        }
      }
    }
  }
}

Argument Reference

The following arguments are supported:


The basic_sli block supports:

The latency block supports:

The availability block supports:

The request_based_sli block supports:

The good_total_ratio block supports:

The distribution_cut block supports:

The range block supports:

The windows_based_sli block supports:

The good_total_ratio_threshold block supports:

The performance block supports:

The good_total_ratio block supports:

The distribution_cut block supports:

The range block supports:

The basic_sli_performance block supports:

The latency block supports:

The availability block supports:

The metric_mean_in_range block supports:

The range block supports:

The metric_sum_in_range block supports:

The range block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Slo can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Slo using one of the formats above. For example:

import {
  id = "{{name}}"
  to = google_monitoring_slo.default
}

When using the terraform import command, Slo can be imported using one of the formats above. For example:

$ terraform import google_monitoring_slo.default {{name}}

User Project Overrides

This resource supports User Project Overrides.