From b25feef636cc48effc584eb2a976f54950e2a4b5 Mon Sep 17 00:00:00 2001 From: Sophia Hanley Date: Mon, 27 Jan 2025 13:38:22 -0800 Subject: [PATCH] [sc-119944] add logging query to monitor (#98) https://buildkite.com/chronosphere/terraform-provider-scenarios-tests-oss/builds/27#_ --- CHANGELOG.md | 5 +++++ chronosphere/intschema/monitor.go | 1 + chronosphere/resource_monitor.go | 2 ++ chronosphere/tfschema/monitor.go | 4 ++++ examples/monitors-logging/collection.tf | 1 + examples/monitors-logging/email.tf | 1 + examples/monitors-logging/main.tf | 16 ++++++++++++++++ examples/monitors-logging/team.tf | 1 + examples/monitors-logging/version.tf | 1 + 9 files changed, 32 insertions(+) create mode 120000 examples/monitors-logging/collection.tf create mode 120000 examples/monitors-logging/email.tf create mode 100644 examples/monitors-logging/main.tf create mode 120000 examples/monitors-logging/team.tf create mode 120000 examples/monitors-logging/version.tf diff --git a/CHANGELOG.md b/CHANGELOG.md index c533ddb..7a7a771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 1.7.0 + +Added: +* Adds support for logging query in the `chronosphere_monitor` resource. + ## 1.6.2 Added: diff --git a/chronosphere/intschema/monitor.go b/chronosphere/intschema/monitor.go index 39f8d92..717f8e1 100644 --- a/chronosphere/intschema/monitor.go +++ b/chronosphere/intschema/monitor.go @@ -87,5 +87,6 @@ type MonitorScheduleRange struct { type MonitorQuery struct { GraphiteExpr string `intschema:"graphite_expr,optional"` + LoggingExpr string `intschema:"logging_expr,optional"` PrometheusExpr string `intschema:"prometheus_expr,optional"` } diff --git a/chronosphere/resource_monitor.go b/chronosphere/resource_monitor.go index 2ab6fcb..c090cbf 100644 --- a/chronosphere/resource_monitor.go +++ b/chronosphere/resource_monitor.go @@ -136,6 +136,7 @@ func (monitorConverter) toModel( SeriesConditions: seriesConditions, SignalGrouping: monitorSignalGroupingToModel(m.SignalGrouping), Slug: m.Slug, + LoggingQuery: m.Query.LoggingExpr, }, nil } @@ -155,6 +156,7 @@ func (monitorConverter) fromModel( Query: intschema.MonitorQuery{ GraphiteExpr: m.GraphiteQuery, PrometheusExpr: m.PrometheusQuery, + LoggingExpr: m.LoggingQuery, }, SeriesConditions: monitorSeriesConditionsFromModel(m.SeriesConditions), Annotations: m.Annotations, diff --git a/chronosphere/tfschema/monitor.go b/chronosphere/tfschema/monitor.go index 0068a47..2a1e75c 100644 --- a/chronosphere/tfschema/monitor.go +++ b/chronosphere/tfschema/monitor.go @@ -80,6 +80,10 @@ var Monitor = map[string]*schema.Schema{ Type: schema.TypeString, Optional: true, }, + "logging_expr": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, diff --git a/examples/monitors-logging/collection.tf b/examples/monitors-logging/collection.tf new file mode 120000 index 0000000..2224a39 --- /dev/null +++ b/examples/monitors-logging/collection.tf @@ -0,0 +1 @@ +../collection-notification-policy/main.tf \ No newline at end of file diff --git a/examples/monitors-logging/email.tf b/examples/monitors-logging/email.tf new file mode 120000 index 0000000..ec080ea --- /dev/null +++ b/examples/monitors-logging/email.tf @@ -0,0 +1 @@ +../notifiers/email.tf \ No newline at end of file diff --git a/examples/monitors-logging/main.tf b/examples/monitors-logging/main.tf new file mode 100644 index 0000000..cf3a292 --- /dev/null +++ b/examples/monitors-logging/main.tf @@ -0,0 +1,16 @@ +resource "chronosphere_monitor" "monitor_with_logging_query" { + name = "Monitor With Logging Query" + collection_id = chronosphere_collection.infra.id + query { + logging_expr = <<-EOF + service = "nginx" | make-series by chronosphere_namespace + EOF + } + series_conditions { + condition { + severity = "warn" + value = 20 + op = "GT" + } + } +} diff --git a/examples/monitors-logging/team.tf b/examples/monitors-logging/team.tf new file mode 120000 index 0000000..8c202b0 --- /dev/null +++ b/examples/monitors-logging/team.tf @@ -0,0 +1 @@ +../collection/teams.tf \ No newline at end of file diff --git a/examples/monitors-logging/version.tf b/examples/monitors-logging/version.tf new file mode 120000 index 0000000..061373c --- /dev/null +++ b/examples/monitors-logging/version.tf @@ -0,0 +1 @@ +../version.tf \ No newline at end of file