Skip to content

Commit

Permalink
Merge pull request #248 from claranet/feature/lasting
Browse files Browse the repository at this point in the history
  • Loading branch information
xp-1000 committed Feb 22, 2021
2 parents ca40e67 + 4efe269 commit 4efcea8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/templates/detector.tf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ resource "signalfx_detector" "{{ id }}" {
{%- else %}
{%- set negative_comparator = reverse_comparator ~ '=' %}
{%- endif %}
detect(when(signal {{ rule.comparator }} ${var.{{ id }}_threshold_{{ severity }}})
detect(when(signal {{ rule.comparator }} ${var.{{ id }}_threshold_{{ severity }}}{%- if rule.lasting_duration is string %}, lasting='${var.{{ id }}_lasting_duration_{{severity}}}'{%- endif %}{%- if rule.lasting_at_least is number %}, at_least=${var.{{ id }}_at_least_percentage_{{ severity }}}{%- endif %})
{%- if 'dependency' in rule %} and when(signal {{ negative_comparator }} ${var.{{ id }}_threshold_{{ rule.dependency }}}){%- endif -%})
{%- endif -%}
.publish('{{ severity_label }}')
Expand Down
12 changes: 12 additions & 0 deletions scripts/templates/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,15 @@ rules:
## This will add another condition to negate the dependecy like:
## when(signal > {{severity}}) and when(signal <= {{severity.dependency}})
#dependency:

## @param lasting_duration - string - optional
## Minimum duration that conditions must be true
## before raising alert
lasting_duration:

## @param lasting_at_least - number - option
## Percentage of lasting that conditions must be true
## before raising alert (>= 0.0 and <= 1.0)
## lasting value is mandatory to use this parameter
lasting_at_least:

15 changes: 14 additions & 1 deletion scripts/templates/variables.tf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,20 @@ variable "{{ id }}_disabled_{{ severity }}" {
type = bool
default = null
}

{% if rule.lasting_duration is string %}
variable "{{ id }}_lasting_duration_{{ severity }}" {
description = "Minimum duration that conditions must be true before raising alert"
type = string
default = "{{ rule.lasting_duration }}"
}
{% endif -%}
{% if rule.lasting_at_least is number %}
variable "{{ id }}_at_least_percentage_{{ severity }}" {
description = "Percentage of lasting that conditions must be true before raising alert (>= 0.0 and <= 1.0)"
type = number
default = "{{ rule.lasting_at_least }}"
}
{% endif %}
{% endfor -%}
{% endif -%}

Expand Down

0 comments on commit 4efcea8

Please sign in to comment.