» 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:

» 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"
    }
  }
}

» 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 = join(" AND ", [
        "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"",
        "resource.type=\"consumed_api\"",
        "resource.label.\"project_id\"=\"my-project-name\"",
      ])

      range {
        max = 10
      }
    }
  }
}

» 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\"",
    ])
  }
}

» 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
      }
    }
  }
}

» 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
      }
    }
  }
}

» 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:

  • goal - (Required) The fraction of service that must be good in order for this objective to be met. 0 < goal <= 0.999

  • service - (Required) ID of the service to which this SLO belongs.


  • display_name - (Optional) Name used for UI elements listing this SLO.

  • rolling_period_days - (Optional) A rolling time period, semantically "in the past X days". Must be between 1 to 30 days, inclusive.

  • calendar_period - (Optional) A calendar period, semantically "since the start of the current ".

Possible values are: * DAY * WEEK * FORTNIGHT * MONTH

  • basic_sli - (Optional) Basic Service-Level Indicator (SLI) on a well-known service type. Performance will be computed on the basis of pre-defined metrics. SLIs are used to measure and calculate the quality of the Service's performance with respect to a single aspect of service quality. Exactly one of the following must be set: basic_sli, request_based_sli, windows_based_sli Structure is documented below.

  • request_based_sli - (Optional) A request-based SLI defines a SLI for which atomic units of service are counted directly. A SLI describes a good service. It is used to measure and calculate the quality of the Service's performance with respect to a single aspect of service quality. Exactly one of the following must be set: basic_sli, request_based_sli, windows_based_sli Structure is documented below.

  • windows_based_sli - (Optional) A windows-based SLI defines the criteria for time windows. good_service is defined based off the count of these time windows for which the provided service was of good quality. A SLI describes a good service. It is used to measure and calculate the quality of the Service's performance with respect to a single aspect of service quality. Exactly one of the following must be set: basic_sli, request_based_sli, windows_based_sli Structure is documented below.

  • slo_id - (Optional) The id to use for this ServiceLevelObjective. If omitted, an id will be generated instead.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The basic_sli block supports:

  • method - (Optional) An optional set of RPCs to which this SLI is relevant. Telemetry from other methods will not be used to calculate performance for this SLI. If omitted, this SLI applies to all the Service's methods. For service types that don't support breaking down by method, setting this field will result in an error.

  • location - (Optional) An optional set of locations to which this SLI is relevant. Telemetry from other locations will not be used to calculate performance for this SLI. If omitted, this SLI applies to all locations in which the Service has activity. For service types that don't support breaking down by location, setting this field will result in an error.

  • version - (Optional) The set of API versions to which this SLI is relevant. Telemetry from other API versions will not be used to calculate performance for this SLI. If omitted, this SLI applies to all API versions. For service types that don't support breaking down by version, setting this field will result in an error.

  • latency - (Required) Parameters for a latency threshold SLI. Structure is documented below.

The latency block supports:

  • threshold - (Required) A duration string, e.g. 10s. Good service is defined to be the count of requests made to this service that return in no more than threshold.

The request_based_sli block supports:

  • good_total_ratio - (Optional) A means to compute a ratio of good_service to total_service. Defines computing this ratio with two TimeSeries monitoring filters Must specify exactly two of good, bad, and total service filters. The relationship good_service + bad_service = total_service will be assumed. Exactly one of distribution_cut or good_total_ratio can be set. Structure is documented below.

  • distribution_cut - (Optional) Used when good_service is defined by a count of values aggregated in a Distribution that fall into a good range. The total_service is the total count of all values aggregated in the Distribution. Defines a distribution TimeSeries filter and thresholds used for measuring good service and total service. Exactly one of distribution_cut or good_total_ratio can be set. Structure is documented below.

The good_total_ratio block supports:

  • good_service_filter - (Optional) A TimeSeries monitoring filter quantifying good service provided. Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE. Exactly two of good_service_filter,bad_service_filter,total_service_filter must be set (good + bad = total is assumed).

  • bad_service_filter - (Optional) A TimeSeries monitoring filter quantifying bad service provided, either demanded service that was not provided or demanded service that was of inadequate quality. Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE. Exactly two of good_service_filter,bad_service_filter,total_service_filter must be set (good + bad = total is assumed).

  • total_service_filter - (Optional) A TimeSeries monitoring filter quantifying total demanded service. Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE. Exactly two of good_service_filter,bad_service_filter,total_service_filter must be set (good + bad = total is assumed).

The distribution_cut block supports:

  • distribution_filter - (Required) A TimeSeries monitoring filter aggregating values to quantify the good service provided. Must have ValueType = DISTRIBUTION and MetricKind = DELTA or MetricKind = CUMULATIVE.

  • range - (Required) Range of numerical values. The computed good_service will be the count of values x in the Distribution such that range.min <= x < range.max. inclusive of min and exclusive of max. Open ranges can be defined by setting just one of min or max. Structure is documented below.

The range block supports:

  • min - (Optional) Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range "< range.max"

  • max - (Optional) max value for the range (inclusive). If not given, will be set to "infinity", defining an open range ">= range.min"

The windows_based_sli block supports:

  • window_period - (Optional) Duration over which window quality is evaluated, given as a duration string "{X}s" representing X seconds. Must be an integer fraction of a day and at least 60s.

  • good_bad_metric_filter - (Optional) A TimeSeries monitoring filter with ValueType = BOOL. The window is good if any true values appear in the window. One of good_bad_metric_filter, good_total_ratio_threshold, metric_mean_in_range, metric_sum_in_range must be set for windows_based_sli.

  • good_total_ratio_threshold - (Optional) Criterion that describes a window as good if its performance is high enough. One of good_bad_metric_filter, good_total_ratio_threshold, metric_mean_in_range, metric_sum_in_range must be set for windows_based_sli. Structure is documented below.

  • metric_mean_in_range - (Optional) Criterion that describes a window as good if the metric's value is in a good range, averaged across returned streams. One of good_bad_metric_filter, good_total_ratio_threshold, metric_mean_in_range, metric_sum_in_range must be set for windows_based_sli. Average value X of time_series should satisfy range.min <= X < range.max for a good window. Structure is documented below.

  • metric_sum_in_range - (Optional) Criterion that describes a window as good if the metric's value is in a good range, summed across returned streams. Summed value X of time_series should satisfy range.min <= X < range.max for a good window. One of good_bad_metric_filter, good_total_ratio_threshold, metric_mean_in_range, metric_sum_in_range must be set for windows_based_sli. Structure is documented below.

The good_total_ratio_threshold block supports:

  • threshold - (Optional) If window performance >= threshold, the window is counted as good.

  • performance - (Optional) Request-based SLI to evaluate to judge window quality. Structure is documented below.

  • basic_sli_performance - (Optional) Basic SLI to evaluate to judge window quality. Structure is documented below.

The performance block supports:

  • good_total_ratio - (Optional) A means to compute a ratio of good_service to total_service. Defines computing this ratio with two TimeSeries monitoring filters Must specify exactly two of good, bad, and total service filters. The relationship good_service + bad_service = total_service will be assumed. Structure is documented below.

  • distribution_cut - (Optional) Used when good_service is defined by a count of values aggregated in a Distribution that fall into a good range. The total_service is the total count of all values aggregated in the Distribution. Defines a distribution TimeSeries filter and thresholds used for measuring good service and total service. Structure is documented below.

The good_total_ratio block supports:

  • good_service_filter - (Optional) A TimeSeries monitoring filter quantifying good service provided. Exactly two of good, bad, or total service filter must be defined (where good + bad = total is assumed) Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE.

  • bad_service_filter - (Optional) A TimeSeries monitoring filter quantifying bad service provided, either demanded service that was not provided or demanded service that was of inadequate quality. Exactly two of good, bad, or total service filter must be defined (where good + bad = total is assumed) Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE.

  • total_service_filter - (Optional) A TimeSeries monitoring filter quantifying total demanded service. Exactly two of good, bad, or total service filter must be defined (where good + bad = total is assumed) Must have ValueType = DOUBLE or ValueType = INT64 and must have MetricKind = DELTA or MetricKind = CUMULATIVE.

The distribution_cut block supports:

  • distribution_filter - (Required) A TimeSeries monitoring filter aggregating values to quantify the good service provided. Must have ValueType = DISTRIBUTION and MetricKind = DELTA or MetricKind = CUMULATIVE.

  • range - (Required) Range of numerical values. The computed good_service will be the count of values x in the Distribution such that range.min <= x < range.max. inclusive of min and exclusive of max. Open ranges can be defined by setting just one of min or max. Structure is documented below.

The range block supports:

  • min - (Optional) Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range "< range.max"

  • max - (Optional) max value for the range (inclusive). If not given, will be set to "infinity", defining an open range ">= range.min"

The basic_sli_performance block supports:

  • method - (Optional) An optional set of RPCs to which this SLI is relevant. Telemetry from other methods will not be used to calculate performance for this SLI. If omitted, this SLI applies to all the Service's methods. For service types that don't support breaking down by method, setting this field will result in an error.

  • location - (Optional) An optional set of locations to which this SLI is relevant. Telemetry from other locations will not be used to calculate performance for this SLI. If omitted, this SLI applies to all locations in which the Service has activity. For service types that don't support breaking down by location, setting this field will result in an error.

  • version - (Optional) The set of API versions to which this SLI is relevant. Telemetry from other API versions will not be used to calculate performance for this SLI. If omitted, this SLI applies to all API versions. For service types that don't support breaking down by version, setting this field will result in an error.

  • latency - (Required) Parameters for a latency threshold SLI. Structure is documented below.

The latency block supports:

  • threshold - (Required) A duration string, e.g. 10s. Good service is defined to be the count of requests made to this service that return in no more than threshold.

The metric_mean_in_range block supports:

  • time_series - (Required) A monitoring filter specifying the TimeSeries to use for evaluating window The provided TimeSeries must have ValueType = INT64 or ValueType = DOUBLE and MetricKind = GAUGE. Mean value X should satisfy range.min <= X < range.max under good service.

  • range - (Required) Range of numerical values. The computed good_service will be the count of values x in the Distribution such that range.min <= x < range.max. inclusive of min and exclusive of max. Open ranges can be defined by setting just one of min or max. Mean value X of time_series values should satisfy range.min <= X < range.max for a good service. Structure is documented below.

The range block supports:

  • min - (Optional) Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range "< range.max"

  • max - (Optional) max value for the range (inclusive). If not given, will be set to "infinity", defining an open range ">= range.min"

The metric_sum_in_range block supports:

  • time_series - (Required) A monitoring filter specifying the TimeSeries to use for evaluating window quality. The provided TimeSeries must have ValueType = INT64 or ValueType = DOUBLE and MetricKind = GAUGE. Summed value X should satisfy range.min <= X < range.max for a good window.

  • range - (Required) Range of numerical values. The computed good_service will be the count of values x in the Distribution such that range.min <= x < range.max. inclusive of min and exclusive of max. Open ranges can be defined by setting just one of min or max. Summed value X should satisfy range.min <= X < range.max for a good window. Structure is documented below.

The range block supports:

  • min - (Optional) Min value for the range (inclusive). If not given, will be set to "-infinity", defining an open range "< range.max"

  • max - (Optional) max value for the range (inclusive). If not given, will be set to "infinity", defining an open range ">= range.min"

» Attributes Reference

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

  • id - an identifier for the resource with format {{name}}

  • name - The full resource name for this service. The syntax is: projects/[PROJECT_ID_OR_NUMBER]/services/[SERVICE_ID]/serviceLevelObjectives/[SLO_NAME]

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • update - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

Slo can be imported using any of these accepted formats:

$ terraform import google_monitoring_slo.default {{name}}

» User Project Overrides

This resource supports User Project Overrides.