Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration gcp cloud sql postgresql #568

Merged
merged 12 commits into from
Sep 12, 2024
8 changes: 8 additions & 0 deletions docs/severity.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- [integration_gcp-cloud-sql-common](#integration_gcp-cloud-sql-common)
- [integration_gcp-cloud-sql-failover](#integration_gcp-cloud-sql-failover)
- [integration_gcp-cloud-sql-mysql](#integration_gcp-cloud-sql-mysql)
- [integration_gcp-cloud-sql-postgresql](#integration_gcp-cloud-sql-postgresql)
- [integration_gcp-compute-engine](#integration_gcp-compute-engine)
- [integration_gcp-load-balancing](#integration_gcp-load-balancing)
- [integration_gcp-memorystore-redis](#integration_gcp-memorystore-redis)
Expand Down Expand Up @@ -775,6 +776,13 @@
|GCP Cloud SQL MySQL replication lag|X|X|-|-|-|


## integration_gcp-cloud-sql-postgresql

|Detector|Critical|Major|Minor|Warning|Info|
|---|---|---|---|---|---|
|GCP Cloud SQL PostgreSQL replication lag|X|X|-|-|-|


## integration_gcp-compute-engine

|Detector|Critical|Major|Minor|Warning|Info|
Expand Down
107 changes: 107 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# GCP-CLOUD-SQL-POSTGRESQL SignalFx detectors

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
:link: **Contents**

- [How to use this module?](#how-to-use-this-module)
- [What are the available detectors in this module?](#what-are-the-available-detectors-in-this-module)
- [How to collect required metrics?](#how-to-collect-required-metrics)
- [Metrics](#metrics)
- [Related documentation](#related-documentation)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## How to use this module?

This directory defines a [Terraform](https://www.terraform.io/)
[module](https://www.terraform.io/language/modules/syntax) you can use in your
existing [stack](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#stack) by adding a
`module` configuration and setting its `source` parameter to URL of this folder:

```hcl
module "signalfx-detectors-integration-gcp-cloud-sql-postgresql" {
source = "github.com/claranet/terraform-signalfx-detectors.git//modules/integration_gcp-cloud-sql-postgresql?ref={revision}"

environment = var.environment
notifications = local.notifications
gcp_project_id = "fillme"
}
```

Note the following parameters:

* `source`: Use this parameter to specify the URL of the module. The double slash (`//`) is intentional and required.
Terraform uses it to specify subfolders within a Git repo (see [module
sources](https://www.terraform.io/language/modules/sources)). The `ref` parameter specifies a specific Git tag in
this repository. It is recommended to use the latest "pinned" version in place of `{revision}`. Avoid using a branch
like `master` except for testing purpose. Note that every modules in this repository are available on the Terraform
[registry](https://registry.terraform.io/modules/claranet/detectors/signalfx) and we recommend using it as source
instead of `git` which is more flexible but less future-proof.

* `environment`: Use this parameter to specify the
[environment](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#environment) used by this
instance of the module.
Its value will be added to the `prefixes` list at the start of the [detector
name](https://github.com/claranet/terraform-signalfx-detectors/wiki/Templating#example).
In general, it will also be used in the `filtering` internal sub-module to [apply
filters](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance#filtering) based on our default
[tagging convention](https://github.com/claranet/terraform-signalfx-detectors/wiki/Tagging-convention) by default.

* `notifications`: Use this parameter to define where alerts should be sent depending on their severity. It consists
of a Terraform [object](https://www.terraform.io/language/expressions/type-constraints#object) where each key represents an available
[detector rule severity](https://docs.splunk.com/observability/alerts-detectors-notifications/create-detectors-for-alerts.html#severity)
and its value is a list of recipients. Every recipients must respect the [detector notification
format](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector#notification-format).
Check the [notification binding](https://github.com/claranet/terraform-signalfx-detectors/wiki/Notifications-binding)
documentation to understand the recommended role of each severity.

These 3 parameters along with all variables defined in [common-variables.tf](common-variables.tf) are common to all
[modules](../) in this repository. Other variables, specific to this module, are available in
[variables.tf](variables.tf) and [variables-gen.tf](variables-gen.tf).
In general, the default configuration "works" but all of these Terraform
[variables](https://www.terraform.io/language/values/variables) make it possible to
customize the detectors behavior to better fit your needs.

Most of them represent usual tips and rules detailed in the
[guidance](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance) documentation and listed in the
common [variables](https://github.com/claranet/terraform-signalfx-detectors/wiki/Variables) dedicated documentation.

Feel free to explore the [wiki](https://github.com/claranet/terraform-signalfx-detectors/wiki) for more information about
general usage of this repository.

## What are the available detectors in this module?

This module creates the following SignalFx detectors which could contain one or multiple alerting rules:

|Detector|Critical|Major|Minor|Warning|Info|
|---|---|---|---|---|---|
|GCP Cloud SQL PostgreSQL replication lag|X|X|-|-|-|

## How to collect required metrics?

This module deploys detectors using metrics reported by the
[GCP integration](https://docs.splunk.com/observability/en/gdi/get-data-in/connect/gcp/gcp-metrics.html) configurable
with [this Terraform module](https://github.com/claranet/terraform-signalfx-integrations/tree/master/cloud/gcp).


Check the [Related documentation](#related-documentation) section for more detailed and specific information about this module dependencies.



### Metrics


Here is the list of required metrics for detectors in this module.

* `database/postgresql/replication/replica_byte_lag`




## Related documentation

* [Terraform SignalFx provider](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs)
* [Terraform SignalFx detector](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector)
* [Splunk Observability integrations](https://docs.splunk.com/Observability/gdi/get-data-in/integrations.html)
* [Stackdriver metrics](https://cloud.google.com/monitoring/api/metrics_gcp#gcp-cloudsql)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module: "GCP Cloud SQL PostgreSQL"
name: "Replication lag"
id: "replication_lag"

transformation: ".min(over='10m')"
aggregation: true


signals:
signal:
metric: "database/postgresql/replication/replica_byte_lag"

rules:
critical:
threshold: 180
comparator: ">"

major:
threshold: 90
comparator: ">"
dependency: "critical"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
documentations:
- name: Stackdriver metrics
url: 'https://cloud.google.com/monitoring/api/metrics_gcp#gcp-cloudsql'
40 changes: 40 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/detectors-gen.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "signalfx_detector" "replication_lag" {
name = format("%s %s", local.detector_name_prefix, "GCP Cloud SQL PostgreSQL replication lag")

authorized_writer_teams = var.authorized_writer_teams
teams = try(coalescelist(var.teams, var.authorized_writer_teams), null)
tags = compact(concat(local.common_tags, local.tags, var.extra_tags))

program_text = <<-EOF
signal = data('database/postgresql/replication/replica_byte_lag', filter=${module.filtering.signalflow})${var.replication_lag_aggregation_function}${var.replication_lag_transformation_function}.publish('signal')
detect(when(signal > ${var.replication_lag_threshold_critical}%{if var.replication_lag_lasting_duration_critical != null}, lasting='${var.replication_lag_lasting_duration_critical}', at_least=${var.replication_lag_at_least_percentage_critical}%{endif})).publish('CRIT')
detect(when(signal > ${var.replication_lag_threshold_major}%{if var.replication_lag_lasting_duration_major != null}, lasting='${var.replication_lag_lasting_duration_major}', at_least=${var.replication_lag_at_least_percentage_major}%{endif}) and (not when(signal > ${var.replication_lag_threshold_critical}%{if var.replication_lag_lasting_duration_critical != null}, lasting='${var.replication_lag_lasting_duration_critical}', at_least=${var.replication_lag_at_least_percentage_critical}%{endif}))).publish('MAJOR')
EOF

rule {
description = "is too high > ${var.replication_lag_threshold_critical}"
severity = "Critical"
detect_label = "CRIT"
disabled = coalesce(var.replication_lag_disabled_critical, var.replication_lag_disabled, var.detectors_disabled)
notifications = try(coalescelist(lookup(var.replication_lag_notifications, "critical", []), var.notifications.critical), null)
runbook_url = try(coalesce(var.replication_lag_runbook_url, var.runbook_url), "")
tip = var.replication_lag_tip
parameterized_subject = var.message_subject == "" ? local.rule_subject : var.message_subject
parameterized_body = var.message_body == "" ? local.rule_body : var.message_body
}

rule {
description = "is too high > ${var.replication_lag_threshold_major}"
severity = "Major"
detect_label = "MAJOR"
disabled = coalesce(var.replication_lag_disabled_major, var.replication_lag_disabled, var.detectors_disabled)
notifications = try(coalescelist(lookup(var.replication_lag_notifications, "major", []), var.notifications.major), null)
runbook_url = try(coalesce(var.replication_lag_runbook_url, var.runbook_url), "")
tip = var.replication_lag_tip
parameterized_subject = var.message_subject == "" ? local.rule_subject : var.message_subject
parameterized_body = var.message_body == "" ? local.rule_body : var.message_body
}

max_delay = var.replication_lag_max_delay
}

4 changes: 4 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/filters.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
filters = "filter('project_id', '${var.gcp_project_id}')"
}

5 changes: 5 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "replication_lag" {
description = "Detector resource for replication_lag"
value = signalfx_detector.replication_lag
}

3 changes: 3 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "gcp-cloud-sql-postgresql"]
}
90 changes: 90 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/variables-gen.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# replication_lag detector

variable "replication_lag_notifications" {
description = "Notification recipients list per severity overridden for replication_lag detector"
type = map(list(string))
default = {}
}

variable "replication_lag_aggregation_function" {
description = "Aggregation function and group by for replication_lag detector (i.e. \".mean(by=['host'])\")"
type = string
default = ""
}

variable "replication_lag_transformation_function" {
description = "Transformation function for replication_lag detector (i.e. \".mean(over='5m')\")"
type = string
default = ".min(over='10m')"
}

variable "replication_lag_max_delay" {
description = "Enforce max delay for replication_lag detector (use \"0\" or \"null\" for \"Auto\")"
type = number
default = null
}

variable "replication_lag_tip" {
description = "Suggested first course of action or any note useful for incident handling"
type = string
default = ""
}

variable "replication_lag_runbook_url" {
description = "URL like SignalFx dashboard or wiki page which can help to troubleshoot the incident cause"
type = string
default = ""
}

variable "replication_lag_disabled" {
description = "Disable all alerting rules for replication_lag detector"
type = bool
default = null
}

variable "replication_lag_disabled_critical" {
description = "Disable critical alerting rule for replication_lag detector"
type = bool
default = null
}

variable "replication_lag_disabled_major" {
description = "Disable major alerting rule for replication_lag detector"
type = bool
default = null
}

variable "replication_lag_threshold_critical" {
description = "Critical threshold for replication_lag detector"
type = number
default = 180
}

variable "replication_lag_lasting_duration_critical" {
description = "Minimum duration that conditions must be true before raising alert"
type = string
default = null
}

variable "replication_lag_at_least_percentage_critical" {
description = "Percentage of lasting that conditions must be true before raising alert (>= 0.0 and <= 1.0)"
type = number
default = 1
}
variable "replication_lag_threshold_major" {
description = "Major threshold for replication_lag detector"
type = number
default = 90
}

variable "replication_lag_lasting_duration_major" {
description = "Minimum duration that conditions must be true before raising alert"
type = string
default = null
}

variable "replication_lag_at_least_percentage_major" {
description = "Percentage of lasting that conditions must be true before raising alert (>= 0.0 and <= 1.0)"
type = number
default = 1
}
4 changes: 4 additions & 0 deletions modules/integration_gcp-cloud-sql-postgresql/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "gcp_project_id" {
description = "GCP project id used for default filtering while lables are not synced"
type = string
}
Loading