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

Add heartbeat monitor for statuscake #3128

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ Accessing a live console on production requires a
[PIM (Privileged Identity Management) request](docs/privileged-identity-management-requests.md).
Follow the steps outlined in [Connect to an instance running in Azure](docs/connecting-to-azure.md).

### Restarting worker via the command line

1. [Connect to the desired Kubernetes cluster](docs/connecting-to-azure.md#1-authenticate-to-the-kubernetes-cluster)
1. Identify the worker deployment via kubectl on the command prompt: `kubectl -n <namespace> get deployments`
1. Restart the deployment: `kubectl -n <namespace> rollout restart deployment <deployment-name>`
1. Verify successful restart: `kubectl -n <namespace> get pods`. The column "AGE" should be updated.

### Usage

When accessing the Rails console on a live system, do so in sandbox mode to
Expand Down
14 changes: 10 additions & 4 deletions app/jobs/heartbeat_job.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Writes "Heartbeat job performed" to the logs every minute. This message is
# evidence that the worker is working properly. We can use a log alerting tool
# to alert us if too much time passes without seeing one of these messages.
require "net/http"

class HeartbeatJob < CronJob
self.cron_expression = "* * * * *"

queue_as :heartbeat

def perform
logger.info "Heartbeat job performed"
if ENV.key?("HEARTBEAT_CHECK_URL") # Not available in dev and review environments
uri = URI(ENV["HEARTBEAT_CHECK_URL"])
res = Net::HTTP.get_response(uri)

unless res.is_a?(Net::HTTPSuccess)
Rails.logger.error "Error connecting to StatusCake: #{res.code} #{res.msg}"
end
end
end
end
11 changes: 8 additions & 3 deletions terraform/application/application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ module "application_configuration" {
PGSSLMODE = local.postgres_ssl_mode
CANONICAL_HOSTNAME = local.canonical_hostname
})
secret_variables = {
DATABASE_URL = module.postgres.url
}
secret_variables = merge(
{
DATABASE_URL = module.postgres.url
},
var.enable_monitoring ? {
HEARTBEAT_CHECK_URL = module.statuscake[0].heartbeat_check_urls[local.heartbeat_check_name]
saliceti marked this conversation as resolved.
Show resolved Hide resolved
} : {}
)
}

module "web_application" {
Expand Down
2 changes: 2 additions & 0 deletions terraform/application/statuscake.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module "statuscake" {
ssl_urls = compact([var.external_url])

contact_groups = var.statuscake_contact_groups

heartbeat_names = [local.heartbeat_check_name]
}
johnake marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions terraform/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ locals {
canonical_hostname = var.canonical_hostname != null ? var.canonical_hostname : "${var.service_name}-${var.environment}-web.test.teacherservices.cloud"
app_env_values_from_yml = yamldecode(file("${path.module}/config/${var.config}_app_env.yml"))
app_env_values = merge(local.app_env_values_from_yml)
heartbeat_check_name = "${var.service_name}-${var.environment}-worker"
}
Loading