Skip to content

Commit

Permalink
feat : convert module integration_gcp-pubsub-topic to generator format
Browse files Browse the repository at this point in the history
  • Loading branch information
haedri committed Dec 8, 2023
1 parent ca7c5c8 commit b1e816e
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 209 deletions.
2 changes: 0 additions & 2 deletions modules/integration_gcp-pubsub-subscription/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Module specific

variable "gcp_project_id" {
description = "GCP project id used for default filtering while lables are not synced"
type = string
Expand Down
2 changes: 1 addition & 1 deletion modules/integration_gcp-pubsub-topic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Note the following parameters:

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).
[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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module: "GCP Pub/Sub Topic sending"
name: "Messages operations"
id: "sending_operations"

transformation: ".sum(over='30m')"
aggregation: true
filtering: "filter('monitored_resource', 'pubsub_topic') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))"

signals:
signal:
metric: "topic/send_message_operation_count"
rollup: "sum"
extrapolation: "zero"

rules:
major:
threshold: 1
comparator: "<"

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module: "GCP Pub/Sub Topic sending"
name: "Unavailable messages"
id: "unavailable_sending_operations"

transformation: ".sum(over='15m')"
aggregation: true
filtering: "filter('monitored_resource', 'pubsub_topic') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))"

signals:
signal:
metric: "topic/send_message_operation_count"
rollup: "sum"
extrapolation: "zero"

rules:
critical:
threshold: 5
comparator: ">"

major:
threshold: 0
comparator: ">"
dependency: "critical"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module: "GCP Pub/Sub Topic sending"
name: "Unavailable messages ratio"
id: "unavailable_sending_operations_ratio"

transformation: ".sum(over='15m')"
aggregation: true


signals:
A:
metric: "topic/send_message_operation_count"
rollup: "sum"
extrapolation: "zero"
filter: "filter('monitored_resource', 'pubsub_topic') and filter('response_code', 'unavailable') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))"
B:
metric: "topic/send_message_operation_count"
rollup: "sum"
extrapolation: "zero"
filter: "filter('monitored_resource', 'pubsub_topic')"
signal:
formula: "(A/B).scale(100).fill(value=0)"

rules:
critical:
threshold: 20
comparator: ">"

major:
threshold: 0
comparator: ">"
dependency: "critical"
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ resource "signalfx_detector" "sending_operations" {
tags = compact(concat(local.common_tags, local.tags, var.extra_tags))

program_text = <<-EOF
reserved_topics = (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))
signal = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and reserved_topics and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.sending_operations_aggregation_function}${var.sending_operations_transformation_function}.publish('signal')
detect(when(signal < ${var.sending_operations_threshold_major})).publish('MAJOR')
base_filtering = filter('monitored_resource', 'pubsub_topic') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))
signal = data('topic/send_message_operation_count', filter=base_filtering and ${module.filtering.signalflow}, rollup='sum', extrapolation='zero')${var.sending_operations_aggregation_function}${var.sending_operations_transformation_function}.publish('signal')
detect(when(signal < ${var.sending_operations_threshold_major}%{if var.sending_operations_lasting_duration_major != null}, lasting='${var.sending_operations_lasting_duration_major}', at_least=${var.sending_operations_at_least_percentage_major}%{endif})).publish('MAJOR')
EOF

rule {
description = "are too low < ${var.sending_operations_threshold_major}"
description = "is too low < ${var.sending_operations_threshold_major}"
severity = "Major"
detect_label = "MAJOR"
disabled = coalesce(var.sending_operations_disabled, var.detectors_disabled)
Expand All @@ -34,14 +34,14 @@ resource "signalfx_detector" "unavailable_sending_operations" {
tags = compact(concat(local.common_tags, local.tags, var.extra_tags))

program_text = <<-EOF
reserved_topics = (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))
signal = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and reserved_topics and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.unavailable_sending_operations_aggregation_function}${var.unavailable_sending_operations_transformation_function}.publish('signal')
detect(when(signal > ${var.unavailable_sending_operations_threshold_critical})).publish('CRIT')
detect(when(signal > ${var.unavailable_sending_operations_threshold_major}) and (not when(signal > ${var.unavailable_sending_operations_threshold_critical}))).publish('MAJOR')
base_filtering = filter('monitored_resource', 'pubsub_topic') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))
signal = data('topic/send_message_operation_count', filter=base_filtering and ${module.filtering.signalflow}, rollup='sum', extrapolation='zero')${var.unavailable_sending_operations_aggregation_function}${var.unavailable_sending_operations_transformation_function}.publish('signal')
detect(when(signal > ${var.unavailable_sending_operations_threshold_critical}%{if var.unavailable_sending_operations_lasting_duration_critical != null}, lasting='${var.unavailable_sending_operations_lasting_duration_critical}', at_least=${var.unavailable_sending_operations_at_least_percentage_critical}%{endif})).publish('CRIT')
detect(when(signal > ${var.unavailable_sending_operations_threshold_major}%{if var.unavailable_sending_operations_lasting_duration_major != null}, lasting='${var.unavailable_sending_operations_lasting_duration_major}', at_least=${var.unavailable_sending_operations_at_least_percentage_major}%{endif}) and (not when(signal > ${var.unavailable_sending_operations_threshold_critical}%{if var.unavailable_sending_operations_lasting_duration_critical != null}, lasting='${var.unavailable_sending_operations_lasting_duration_critical}', at_least=${var.unavailable_sending_operations_at_least_percentage_critical}%{endif}))).publish('MAJOR')
EOF

rule {
description = "are too high > ${var.unavailable_sending_operations_threshold_critical}"
description = "is too high > ${var.unavailable_sending_operations_threshold_critical}"
severity = "Critical"
detect_label = "CRIT"
disabled = coalesce(var.unavailable_sending_operations_disabled_critical, var.unavailable_sending_operations_disabled, var.detectors_disabled)
Expand All @@ -53,7 +53,7 @@ EOF
}

rule {
description = "are too high > ${var.unavailable_sending_operations_threshold_major}"
description = "is too high > ${var.unavailable_sending_operations_threshold_major}"
severity = "Major"
detect_label = "MAJOR"
disabled = coalesce(var.unavailable_sending_operations_disabled_major, var.unavailable_sending_operations_disabled, var.detectors_disabled)
Expand All @@ -75,16 +75,15 @@ resource "signalfx_detector" "unavailable_sending_operations_ratio" {
tags = compact(concat(local.common_tags, local.tags, var.extra_tags))

program_text = <<-EOF
reserved_topics = (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr'))
A = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and filter('response_code', 'unavailable') and reserved_topics and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.unavailable_sending_operations_ratio_aggregation_function}${var.unavailable_sending_operations_ratio_transformation_function}
B = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.unavailable_sending_operations_ratio_aggregation_function}${var.unavailable_sending_operations_ratio_transformation_function}
A = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and filter('response_code', 'unavailable') and (not filter('topic_id', 'container-analysis-occurrences*', 'container-analysis-notes*', 'cloud-builds', 'gcr')) and ${module.filtering.signalflow}, rollup='sum', extrapolation='zero')${var.unavailable_sending_operations_ratio_aggregation_function}${var.unavailable_sending_operations_ratio_transformation_function}
B = data('topic/send_message_operation_count', filter=filter('monitored_resource', 'pubsub_topic') and ${module.filtering.signalflow}, rollup='sum', extrapolation='zero')${var.unavailable_sending_operations_ratio_aggregation_function}${var.unavailable_sending_operations_ratio_transformation_function}
signal = (A/B).scale(100).fill(value=0).publish('signal')
detect(when(signal > ${var.unavailable_sending_operations_ratio_threshold_critical})).publish('CRIT')
detect(when(signal > ${var.unavailable_sending_operations_ratio_threshold_major}) and (not when(signal > ${var.unavailable_sending_operations_ratio_threshold_critical}))).publish('MAJOR')
detect(when(signal > ${var.unavailable_sending_operations_ratio_threshold_critical}%{if var.unavailable_sending_operations_ratio_lasting_duration_critical != null}, lasting='${var.unavailable_sending_operations_ratio_lasting_duration_critical}', at_least=${var.unavailable_sending_operations_ratio_at_least_percentage_critical}%{endif})).publish('CRIT')
detect(when(signal > ${var.unavailable_sending_operations_ratio_threshold_major}%{if var.unavailable_sending_operations_ratio_lasting_duration_major != null}, lasting='${var.unavailable_sending_operations_ratio_lasting_duration_major}', at_least=${var.unavailable_sending_operations_ratio_at_least_percentage_major}%{endif}) and (not when(signal > ${var.unavailable_sending_operations_ratio_threshold_critical}%{if var.unavailable_sending_operations_ratio_lasting_duration_critical != null}, lasting='${var.unavailable_sending_operations_ratio_lasting_duration_critical}', at_least=${var.unavailable_sending_operations_ratio_at_least_percentage_critical}%{endif}))).publish('MAJOR')
EOF

rule {
description = "is too high >= ${var.unavailable_sending_operations_ratio_threshold_critical}"
description = "is too high > ${var.unavailable_sending_operations_ratio_threshold_critical}"
severity = "Critical"
detect_label = "CRIT"
disabled = coalesce(var.unavailable_sending_operations_ratio_disabled_critical, var.unavailable_sending_operations_ratio_disabled, var.detectors_disabled)
Expand All @@ -96,7 +95,7 @@ EOF
}

rule {
description = "is too high >= ${var.unavailable_sending_operations_ratio_threshold_major}"
description = "is too high > ${var.unavailable_sending_operations_ratio_threshold_major}"
severity = "Major"
detect_label = "MAJOR"
disabled = coalesce(var.unavailable_sending_operations_ratio_disabled_major, var.unavailable_sending_operations_ratio_disabled, var.detectors_disabled)
Expand Down
Loading

0 comments on commit b1e816e

Please sign in to comment.