Skip to content

Commit

Permalink
#104 add default tags and extra tags variable (#293)
Browse files Browse the repository at this point in the history
* #104 add default tags and extra tags variable

* #104 fix locals

* fix azure app service and appmanagement

* add tags support to generator

* support tags for module bootstrapping
  • Loading branch information
xp-1000 authored Jun 24, 2021
1 parent 8bd2df4 commit 4fbd174
Show file tree
Hide file tree
Showing 188 changed files with 665 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/module/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ locals {
local.not_running_vm_filters_azure
)
detector_name_prefix = "${join("", formatlist("[%s]", var.prefixes))}[${var.environment}]"
common_tags = concat(["terraform", var.environment], var.teams)
rule_subject_prefix = "[{{ruleSeverity}}]{{{detectorName}}} {{{readableRule}}}"
rule_subject_suffix = "on {{{dimensions}}}"
rule_subject = format("%s ({{inputs.signal.value}}) %s", local.rule_subject_prefix, local.rule_subject_suffix)
Expand Down
6 changes: 6 additions & 0 deletions common/module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ variable "message_body" {
default = ""
}

variable "extra_tags" {
description = "List of tags to add to the detectors resources, useful to find detectors "
type = list(string)
default = []
}

7 changes: 7 additions & 0 deletions modules/integration_aws-alb/detectors-alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "heartbeat" {

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
from signalfx.detectors.not_reporting import not_reporting
Expand All @@ -28,6 +29,7 @@ resource "signalfx_detector" "no_healthy_instances" {

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
A = data('HealthyHostCount', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'lower') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow})${var.no_healthy_instances_aggregation_function}${var.no_healthy_instances_transformation_function}
Expand Down Expand Up @@ -67,6 +69,7 @@ resource "signalfx_detector" "latency" {

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('TargetResponseTime', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'mean') and filter('TargetGroup', '*') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='average')${var.latency_aggregation_function}${var.latency_transformation_function}.publish('signal')
Expand Down Expand Up @@ -104,6 +107,7 @@ resource "signalfx_detector" "alb_5xx" {

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
A = data('HTTPCode_ELB_5XX_Count', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'sum') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.alb_5xx_aggregation_function}${var.alb_5xx_transformation_function}
Expand Down Expand Up @@ -143,6 +147,7 @@ resource "signalfx_detector" "alb_4xx" {

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
A = data('HTTPCode_ELB_4XX_Count', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'sum') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.alb_4xx_aggregation_function}${var.alb_4xx_transformation_function}
Expand Down Expand Up @@ -182,6 +187,7 @@ resource "signalfx_detector" "target_5xx" {

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
A = data('HTTPCode_Target_5XX_Count', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'sum') and filter('TargetGroup', '*') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.target_5xx_aggregation_function}${var.target_5xx_transformation_function}
Expand Down Expand Up @@ -221,6 +227,7 @@ resource "signalfx_detector" "target_4xx" {

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
A = data('HTTPCode_Target_4XX_Count', filter=filter('namespace', 'AWS/ApplicationELB') and filter('stat', 'sum') and filter('TargetGroup', '*') and (not filter('AvailabilityZone', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.target_4xx_aggregation_function}${var.target_4xx_transformation_function}
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-alb/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-alb"]
}
3 changes: 3 additions & 0 deletions modules/integration_aws-apigateway/detectors-api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resource "signalfx_detector" "latency" {

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('Latency', filter=filter('namespace', 'AWS/ApiGateway') and filter('stat', 'sum') and (not filter('Stage', '*')) and (not filter('Method', '*')) and (not filter('Resource', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='average')${var.latency_aggregation_function}${var.latency_transformation_function}.publish('signal')
Expand Down Expand Up @@ -42,6 +43,7 @@ resource "signalfx_detector" "http_5xx" {

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
A = data('${var.is_v2 ? "5xx" : "5XXError"}', filter=filter('namespace', 'AWS/ApiGateway') and filter('stat', 'sum') and (not filter('Stage', '*')) and (not filter('Method', '*')) and (not filter('Resource', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.http_5xx_aggregation_function}${var.http_5xx_transformation_function}
Expand Down Expand Up @@ -82,6 +84,7 @@ resource "signalfx_detector" "http_4xx" {

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
A = data('${var.is_v2 ? "4xx" : "4XXError"}', filter=filter('namespace', 'AWS/ApiGateway') and filter('stat', 'sum') and (not filter('Stage', '*')) and (not filter('Method', '*')) and (not filter('Resource', '*')) and ${module.filtering.signalflow}, extrapolation='zero', rollup='sum')${var.http_4xx_aggregation_function}${var.http_4xx_transformation_function}
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-apigateway/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-apigateway"]
}
5 changes: 5 additions & 0 deletions modules/integration_aws-beanstalk/detectors-beanstalk.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "heartbeat" {

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
from signalfx.detectors.not_reporting import not_reporting
Expand All @@ -28,6 +29,7 @@ resource "signalfx_detector" "health" {

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('EnvironmentHealth', filter=filter('namespace', 'AWS/ElasticBeanstalk') and filter('stat', 'upper') and ${module.filtering.signalflow})${var.health_aggregation_function}${var.health_transformation_function}.publish('signal')
Expand Down Expand Up @@ -65,6 +67,7 @@ resource "signalfx_detector" "latency_p90" {

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('ApplicationLatencyP90', filter=filter('namespace', 'AWS/ElasticBeanstalk') and filter('stat', 'lower') and (not filter('InstanceId', '*')) and ${module.filtering.signalflow})${var.latency_p90_aggregation_function}${var.latency_p90_transformation_function}.publish('signal')
Expand Down Expand Up @@ -102,6 +105,7 @@ resource "signalfx_detector" "app_5xx_error_rate" {

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
A = data('ApplicationRequests5xx', filter=filter('namespace', 'AWS/ElasticBeanstalk') and filter('stat', 'sum') and (not filter('InstanceId', '*')) and ${module.filtering.signalflow})${var.app_5xx_error_rate_aggregation_function}${var.app_5xx_error_rate_transformation_function}
Expand Down Expand Up @@ -142,6 +146,7 @@ resource "signalfx_detector" "root_filesystem_usage" {

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('RootFilesystemUtil', filter=filter('namespace', 'AWS/ElasticBeanstalk') and filter('stat', 'lower') and (not filter('InstanceId', '*')) and ${module.filtering.signalflow})${var.root_filesystem_usage_aggregation_function}${var.root_filesystem_usage_transformation_function}.publish('signal')
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-beanstalk/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-beanstalk"]
}
3 changes: 3 additions & 0 deletions modules/integration_aws-ecs-cluster/detectors-ecs-cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "heartbeat" {

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
from signalfx.detectors.not_reporting import not_reporting
Expand All @@ -28,6 +29,7 @@ resource "signalfx_detector" "cpu_utilization" {

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('CPUUtilization', filter=filter('namespace', 'AWS/ECS') and filter('stat', 'mean') and not filter('ServiceName', '*') and ${module.filtering.signalflow}).mean(by=['ClusterName'])${var.cpu_utilization_aggregation_function}${var.cpu_utilization_transformation_function}.publish('signal')
Expand Down Expand Up @@ -65,6 +67,7 @@ resource "signalfx_detector" "memory_utilization" {

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('MemoryUtilization', filter=filter('namespace', 'AWS/ECS') and filter('stat', 'mean') and not filter('ServiceName', '*') and ${module.filtering.signalflow}).mean(by=['ClusterName'])${var.memory_utilization_aggregation_function}${var.memory_utilization_transformation_function}.publish('signal')
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-ecs-cluster/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-ecs-cluster"]
}
3 changes: 3 additions & 0 deletions modules/integration_aws-ecs-service/detectors-ecs-service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "heartbeat" {

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
from signalfx.detectors.not_reporting import not_reporting
Expand All @@ -29,6 +30,7 @@ resource "signalfx_detector" "cpu_utilization" {

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('CPUUtilization', filter=filter('namespace', 'AWS/ECS') and filter('stat', 'mean') and filter('ServiceName', '*') and ${module.filtering.signalflow}).mean(by=['ServiceName'])${var.cpu_utilization_aggregation_function}${var.cpu_utilization_transformation_function}.publish('signal')
Expand Down Expand Up @@ -66,6 +68,7 @@ resource "signalfx_detector" "memory_utilization" {

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('MemoryUtilization', filter=filter('namespace', 'AWS/ECS') and filter('stat', 'mean') and filter('ServiceName', '*') and ${module.filtering.signalflow}).mean(by=['ServiceName'])${var.memory_utilization_aggregation_function}${var.memory_utilization_transformation_function}.publish('signal')
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-ecs-service/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-ecs-service"]
}
6 changes: 6 additions & 0 deletions modules/integration_aws-efs/detectors-gen.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "used_space" {

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))

viz_options {
label = "signal"
Expand Down Expand Up @@ -47,6 +48,7 @@ resource "signalfx_detector" "io_limit" {

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))

viz_options {
label = "signal"
Expand Down Expand Up @@ -90,6 +92,7 @@ resource "signalfx_detector" "read_throughput" {

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))

viz_options {
label = "signal"
Expand Down Expand Up @@ -135,6 +138,7 @@ resource "signalfx_detector" "write_throughput" {

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))

viz_options {
label = "signal"
Expand Down Expand Up @@ -180,6 +184,7 @@ resource "signalfx_detector" "percent_of_permitted_throughput" {

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))

viz_options {
label = "signal"
Expand Down Expand Up @@ -225,6 +230,7 @@ resource "signalfx_detector" "burst_credit_balance" {

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))

viz_options {
label = "signal"
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-efs/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-efs"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resource "signalfx_detector" "heartbeat" {

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
from signalfx.detectors.not_reporting import not_reporting
Expand All @@ -28,6 +29,7 @@ resource "signalfx_detector" "evictions" {

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('Evictions', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'mean') and filter('CacheNodeId', '*') and ${module.filtering.signalflow})${var.evictions_aggregation_function}${var.evictions_transformation_function}.publish('signal')
Expand Down Expand Up @@ -65,6 +67,7 @@ resource "signalfx_detector" "max_connection" {

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('CurrConnections', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'upper') and filter('CacheNodeId', '*') and ${module.filtering.signalflow})${var.max_connection_aggregation_function}${var.max_connection_transformation_function}.publish('signal')
Expand All @@ -89,6 +92,7 @@ resource "signalfx_detector" "no_connection" {

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('CurrConnections', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'lower') and filter('CacheNodeId', '*') and ${module.filtering.signalflow})${var.no_connection_aggregation_function}${var.no_connection_transformation_function}.publish('signal')
Expand All @@ -113,6 +117,7 @@ resource "signalfx_detector" "swap" {

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('SwapUsage', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'upper') and filter('CacheNodeId', '*') and ${module.filtering.signalflow})${var.swap_aggregation_function}${var.swap_transformation_function}.publish('signal')
Expand Down Expand Up @@ -150,6 +155,7 @@ resource "signalfx_detector" "free_memory" {

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('FreeableMemory', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'lower') and filter('CacheNodeId', '*') and ${module.filtering.signalflow}).rateofchange()${var.free_memory_aggregation_function}${var.free_memory_transformation_function}.publish('signal')
Expand Down Expand Up @@ -187,6 +193,7 @@ resource "signalfx_detector" "evictions_growing" {

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('Evictions', filter=filter('namespace', 'AWS/ElastiCache') and filter('stat', 'mean') and filter('CacheNodeId', '*') and ${module.filtering.signalflow})${var.evictions_growing_aggregation_function}${var.evictions_growing_transformation_function}.rateofchange().scale(100).publish('signal')
Expand Down
3 changes: 3 additions & 0 deletions modules/integration_aws-elasticache-common/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = ["integration", "aws-elasticache-common"]
}
Loading

0 comments on commit 4fbd174

Please sign in to comment.