diff --git a/docs/resources/slo.md b/docs/resources/slo.md index 8a7edb39..3b3a011d 100644 --- a/docs/resources/slo.md +++ b/docs/resources/slo.md @@ -306,7 +306,7 @@ Optional: - `datadog` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/datadog#creating-slos-with-datadog) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--datadog)) - `dynatrace` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/dynatrace#creating-slos-with-dynatrace) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--dynatrace)) - `elasticsearch` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/elasticsearch#creating-slos-with-elasticsearch) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--elasticsearch)) -- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--gcm)) +- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--gcm)) - `grafana_loki` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/grafana-loki#creating-slos-with-grafana-loki) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--grafana_loki)) - `graphite` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/graphite#creating-slos-with-graphite) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--graphite)) - `honeycomb` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/honeycomb#creating-slos-with-honeycomb) (see [below for nested schema](#nestedblock--objective--count_metrics--bad--honeycomb)) @@ -446,7 +446,11 @@ Required: Required: - `project_id` (String) Project ID -- `query` (String) Query for the metrics + +Optional: + +- `promql` (String) Query for the metrics in PromQL format +- `query` (String) Query for the metrics in MQL format ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql)) @@ -677,7 +681,7 @@ Optional: - `datadog` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/datadog#creating-slos-with-datadog) (see [below for nested schema](#nestedblock--objective--count_metrics--good--datadog)) - `dynatrace` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/dynatrace#creating-slos-with-dynatrace) (see [below for nested schema](#nestedblock--objective--count_metrics--good--dynatrace)) - `elasticsearch` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/elasticsearch#creating-slos-with-elasticsearch) (see [below for nested schema](#nestedblock--objective--count_metrics--good--elasticsearch)) -- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--good--gcm)) +- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--good--gcm)) - `grafana_loki` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/grafana-loki#creating-slos-with-grafana-loki) (see [below for nested schema](#nestedblock--objective--count_metrics--good--grafana_loki)) - `graphite` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/graphite#creating-slos-with-graphite) (see [below for nested schema](#nestedblock--objective--count_metrics--good--graphite)) - `honeycomb` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/honeycomb#creating-slos-with-honeycomb) (see [below for nested schema](#nestedblock--objective--count_metrics--good--honeycomb)) @@ -817,7 +821,11 @@ Required: Required: - `project_id` (String) Project ID -- `query` (String) Query for the metrics + +Optional: + +- `promql` (String) Query for the metrics in PromQL format +- `query` (String) Query for the metrics in MQL format ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql)) @@ -1048,7 +1056,7 @@ Optional: - `datadog` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/datadog#creating-slos-with-datadog) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--datadog)) - `dynatrace` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/dynatrace#creating-slos-with-dynatrace) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--dynatrace)) - `elasticsearch` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/elasticsearch#creating-slos-with-elasticsearch) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--elasticsearch)) -- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--gcm)) +- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--gcm)) - `grafana_loki` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/grafana-loki#creating-slos-with-grafana-loki) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--grafana_loki)) - `graphite` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/graphite#creating-slos-with-graphite) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--graphite)) - `honeycomb` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/honeycomb#creating-slos-with-honeycomb) (see [below for nested schema](#nestedblock--objective--count_metrics--good_total--honeycomb)) @@ -1188,7 +1196,11 @@ Required: Required: - `project_id` (String) Project ID -- `query` (String) Query for the metrics + +Optional: + +- `promql` (String) Query for the metrics in PromQL format +- `query` (String) Query for the metrics in MQL format ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql)) @@ -1419,7 +1431,7 @@ Optional: - `datadog` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/datadog#creating-slos-with-datadog) (see [below for nested schema](#nestedblock--objective--count_metrics--total--datadog)) - `dynatrace` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/dynatrace#creating-slos-with-dynatrace) (see [below for nested schema](#nestedblock--objective--count_metrics--total--dynatrace)) - `elasticsearch` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/elasticsearch#creating-slos-with-elasticsearch) (see [below for nested schema](#nestedblock--objective--count_metrics--total--elasticsearch)) -- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--total--gcm)) +- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--count_metrics--total--gcm)) - `grafana_loki` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/grafana-loki#creating-slos-with-grafana-loki) (see [below for nested schema](#nestedblock--objective--count_metrics--total--grafana_loki)) - `graphite` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/graphite#creating-slos-with-graphite) (see [below for nested schema](#nestedblock--objective--count_metrics--total--graphite)) - `honeycomb` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/honeycomb#creating-slos-with-honeycomb) (see [below for nested schema](#nestedblock--objective--count_metrics--total--honeycomb)) @@ -1559,7 +1571,11 @@ Required: Required: - `project_id` (String) Project ID -- `query` (String) Query for the metrics + +Optional: + +- `promql` (String) Query for the metrics in PromQL format +- `query` (String) Query for the metrics in MQL format ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql)) @@ -1798,7 +1814,7 @@ Optional: - `datadog` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/datadog#creating-slos-with-datadog) (see [below for nested schema](#nestedblock--objective--raw_metric--query--datadog)) - `dynatrace` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/dynatrace#creating-slos-with-dynatrace) (see [below for nested schema](#nestedblock--objective--raw_metric--query--dynatrace)) - `elasticsearch` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/elasticsearch#creating-slos-with-elasticsearch) (see [below for nested schema](#nestedblock--objective--raw_metric--query--elasticsearch)) -- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--raw_metric--query--gcm)) +- `gcm` (Block Set) [Configuration documentation](https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring) (see [below for nested schema](#nestedblock--objective--raw_metric--query--gcm)) - `grafana_loki` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/grafana-loki#creating-slos-with-grafana-loki) (see [below for nested schema](#nestedblock--objective--raw_metric--query--grafana_loki)) - `graphite` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/graphite#creating-slos-with-graphite) (see [below for nested schema](#nestedblock--objective--raw_metric--query--graphite)) - `honeycomb` (Block Set) [Configuration documentation](https://docs.nobl9.com/Sources/honeycomb#creating-slos-with-honeycomb) (see [below for nested schema](#nestedblock--objective--raw_metric--query--honeycomb)) @@ -1938,7 +1954,11 @@ Required: Required: - `project_id` (String) Project ID -- `query` (String) Query for the metrics + +Optional: + +- `promql` (String) Query for the metrics in PromQL format +- `query` (String) Query for the metrics in MQL format ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql)) diff --git a/nobl9/resource_slo.go b/nobl9/resource_slo.go index 39d99fc5..3629e0d2 100644 --- a/nobl9/resource_slo.go +++ b/nobl9/resource_slo.go @@ -1664,7 +1664,7 @@ func unmarshalElasticsearchMetric(metric interface{}) map[string]interface{} { /** * Google Cloud Monitoring (GCM) Metric - * https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring + * https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring */ const gcmMetric = "gcm" @@ -1674,7 +1674,7 @@ func schemaMetricGCM() map[string]*schema.Schema { Type: schema.TypeSet, Optional: true, Description: "[Configuration documentation]" + - "(https://docs.nobl9.com/Sources/google-cloud-monitoring#creating-slos-with-google-cloud-monitoring)", + "(https://docs.nobl9.com/sources/google-cloud-monitoring/#creating-slos-with-google-cloud-monitoring)", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "project_id": { @@ -1683,9 +1683,15 @@ func schemaMetricGCM() map[string]*schema.Schema { Description: "Project ID", }, "query": { + Type: schema.TypeString, + Optional: true, + Description: "Query for the metrics in MQL format" + + " ([deprecated](https://cloud.google.com/stackdriver/docs/deprecations/mql))", + }, + "promql": { Type: schema.TypeString, - Required: true, - Description: "Query for the metrics", + Optional: true, + Description: "Query for the metrics in PromQL format", }, }, }, @@ -1703,6 +1709,7 @@ func marshalGCMMetric(s *schema.Set) *v1alphaSLO.GCMMetric { return &v1alphaSLO.GCMMetric{ ProjectID: metric["project_id"].(string), Query: metric["query"].(string), + PromQL: metric["promql"].(string), } } @@ -1714,6 +1721,7 @@ func unmarshalGCMMetric(metric interface{}) map[string]interface{} { res := make(map[string]interface{}) res["project_id"] = gMetric.ProjectID res["query"] = gMetric.Query + res["promql"] = gMetric.PromQL return res } diff --git a/nobl9/resource_slo_test.go b/nobl9/resource_slo_test.go index c41b6eb4..bc11f51e 100644 --- a/nobl9/resource_slo_test.go +++ b/nobl9/resource_slo_test.go @@ -33,6 +33,7 @@ func TestAcc_Nobl9SLO(t *testing.T) { {"test-composite-with-value", testCompositeSLOValueZeroBackwardCompatibility}, {"test-datadog", testDatadogSLO}, {"test-dynatrace", testDynatraceSLO}, + {"test-google-cloud-monitoring", testGoogleCloudMonitoringPromQLSLO}, {"test-grafanaloki", testGrafanaLokiSLO}, {"test-graphite", testGraphiteSLO}, {"test-honeycomb", testHoneycombSLO}, @@ -1325,6 +1326,67 @@ resource "nobl9_slo" ":name" { return config } +func testGoogleCloudMonitoringPromQLSLO(name string) string { + var serviceName = name + "-tf-service" + var agentName = name + "-tf-agent" + config := + testService(serviceName) + + testGoogleCloudMonitoringAgent(agentName) + ` +resource "nobl9_slo" ":name" { + name = ":name" + display_name = ":name" + project = ":project" + service = nobl9_service.:serviceName.name + + label { + key = "team" + values = ["green","sapphire"] + } + + label { + key = "env" + values = ["dev", "staging", "prod"] + } + + budgeting_method = "Occurrences" + + objective { + display_name = "obj1" + name = "tf-objective-1" + target = 0.7 + value = 1 + op = "lt" + raw_metric { + query { + gcm { + project_id = "project1" + promql = "sum(rate(http_requests_total{job=\"api-server\"}[5m]))" + } + } + } + } + + time_window { + count = 10 + is_rolling = true + unit = "Minute" + } + + indicator { + name = nobl9_agent.:agentName.name + project = ":project" + kind = "Agent" + } +} +` + config = strings.ReplaceAll(config, ":name", name) + config = strings.ReplaceAll(config, ":serviceName", serviceName) + config = strings.ReplaceAll(config, ":agentName", agentName) + config = strings.ReplaceAll(config, ":project", testProject) + + return config +} + func testGrafanaLokiSLO(name string) string { var serviceName = name + "-tf-service" var agentName = name + "-tf-agent"