Skip to content

Commit

Permalink
Calculate number of devices needed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Sep 26, 2024
1 parent 3e96b07 commit e18af55
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions deployment/modules/monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ resource "google_project_service" "monitoring_api" {
locals {
distributor_service = "distributor-service-${var.env}"
duration = "5m"
# Calculate the threshold for majority.
# For odd numbers of devices, ceil(N/2) is fine, but if N is even we need to detect that and add 1:
majority = ceil(var.num_expected_devices / 2) + 1 - (ceil(var.num_expected_devices / 2) - floor(var.num_expected_devices / 2))
majority_percent = local.majority / var.num_expected_devices * 100
}

resource "google_monitoring_dashboard" "witness_dashboard" {
Expand Down Expand Up @@ -93,6 +97,9 @@ resource "google_monitoring_dashboard" "witness_dashboard" {
},
"plotType": "STACKED_AREA"
}],
"thresholds": [{
"value": ${local.majority}
}],
"timeshiftDuration": "0s",
"yAxis": {
"label": "Devices",
Expand All @@ -110,7 +117,7 @@ resource "google_monitoring_dashboard" "witness_dashboard" {
"plotType": "STACKED_AREA"
}],
"thresholds": [{
"value": 51
"value": ${local.majority_percent}
}],
"timeshiftDuration": "0s",
"yAxis": {
Expand Down Expand Up @@ -143,7 +150,7 @@ resource "google_monitoring_alert_policy" "witness_liveness" {
# timeseries across instances overlap, take the average. This ensures
# that the count for each witness is not double-counted across instances.
# Finally, add all the counts together to compare against the threshold.
query = <<-EOT
query = <<-EOT
fetch prometheus_target
| metric
'prometheus.googleapis.com/distributor_update_checkpoint_success/counter'
Expand Down

0 comments on commit e18af55

Please sign in to comment.