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

AP-565 enable monitoring in soak #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions terraform/examples/multi-node-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,20 @@ module "dist" {
pop_id = var.edge01_pop_id
server_id = var.edge01_host
}

module "monitoring_edge" {
source = "../../modules/monitoring_edge"
docker_host = "${var.docker_protocol}${var.edge01_host}"
docker_network = docker_network.edge01.name
docker_image_username = var.docker_image_username
docker_image_repository = "${var.docker_image_repository}_monitoring_edge"
docker_image_tag = var.docker_image_tag
docker_registry_address = var.docker_registry_address
docker_registry_username = var.docker_registry_username
docker_registry_password = var.docker_registry_password
docker_log_driver = var.docker_log_driver
hostname = var.monitoring_edge_hostname
pop_id = var.edge01_pop_id
server_id = var.edge01_host
core_hosts = [element(split("@", var.control01_host), 1)]
}
6 changes: 6 additions & 0 deletions terraform/examples/multi-node-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,9 @@ variable "docker_log_driver" {
default = "json-file"
description = "Docker log driver to use, see https://docs.docker.com/config/containers/logging/configure/"
}

variable "monitoring_edge_hostname" {
default = "monitoring_edge"
description = "Hostmaster email address used in SOA records"
}

95 changes: 95 additions & 0 deletions terraform/modules/monitoring_edge/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
terraform {
required_version = ">= 0.12"
}

locals {
docker_image_name = "${var.docker_image_username}/${var.docker_image_repository}:${var.docker_image_tag}"
}

provider "docker" {
host = var.docker_host

# If registry address is provided, configure registry_auth
dynamic "registry_auth" {
for_each = var.docker_registry_address != null ? list(var.docker_registry_address) : []
iterator = address
content {
address = address.value
username = var.docker_registry_username
password = var.docker_registry_password
}
}
}

data "docker_registry_image" "monitoring_edge" {
count = var.docker_registry_address != null ? 1 : 0
name = local.docker_image_name
}

resource "docker_image" "monitoring_edge" {
count = var.docker_registry_address != null ? 1 : 0
name = data.docker_registry_image.monitoring_edge[count.index].name
pull_triggers = [data.docker_registry_image.monitoring_edge[count.index].sha256_digest]
keep_locally = true
}

resource "docker_volume" "monitoring_edge" {
name = "ns1monitoring_edge"
}

resource "docker_container" "monitoring_edge" {
name = "monitoring_edge"
# If using registry, use sha of found image, otherwise use name that should be found on docker host
image = var.docker_registry_address != null ? docker_image.monitoring_edge[0].latest : local.docker_image_name

env = [
# "CONFIG_PORT=3305",
"CONTAINER_NAME=${var.container_name}",
]

restart = "unless-stopped"

hostname = var.hostname

log_driver = var.docker_log_driver

healthcheck {
test = ["CMD", "supd", "health"]
interval = "15s"
timeout = "10s"
retries = 3
}

volumes {
volume_name = docker_volume.monitoring_edge.name
container_path = "/ns1/data"
}


command = [
"--pop_id",
var.pop_id,
"--server_id",
var.server_id,
"--core_host",
join(",", var.core_hosts),
"--monitoring_region",
var.monitoring_region,
"--digest_service_def_id",
var.digest_service_def_id,
"--log_level",
var.log_level,
"--metrics_addr_base",
var.metrics_addr_base,
"--inst_id",
var.inst_id,
"--use_privileged_ping",
var.use_privileged_ping,
"--jitter_seconds",
var.jitter_seconds,
]

network_mode = "host"

privileged = true
}
103 changes: 103 additions & 0 deletions terraform/modules/monitoring_edge/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
variable "docker_image_tag" {
default = "2.5.0"
description = "The image tag of the Docker image. Defaults to the latest GA version number."
}

variable "docker_image_username" {
default = "ns1inc"
description = "The username used in the Docker image name. This should not need to be changed."
}

variable "docker_image_repository" {
default = "privatedns_monitoring_edge"
description = "The repository name used in the Docker image name. This should not need to be changed."
}

variable "docker_registry_address" {
default = null
description = "The absolute URL of the Docker registry (i.e. 'https://registry.hub.docker.com') to pull the container images from. If not provided, it's assumed the container image is already loaded on the Docker host."
}

variable "docker_registry_username" {
default = null
description = "Username for authentication to Docker registry. Only required if 'docker_registry_address' is provided."
}

variable "docker_registry_password" {
default = null
description = "Password for authentication to Docker registry. Only required if 'docker_registry_address' is provided."
}

variable "docker_host" {
description = "The address of the Docker host to deploy the container on. Both ssh:// and tcp:// are supported. See https://www.terraform.io/docs/providers/docker/index.html for more details."
}

variable "docker_network" {
description = "The name of the Docker network to connect to the container. Must already exist on the Docker host."
}

variable "container_name" {
default = "monitoring_edge"
description = "The name of the Docker container."
}

variable "pop_id" {
default = "mypop"
description = "Specifies the location (datacenter/pop) of the server where the data container is running"
}

variable "server_id" {
default = "myserver"
description = "Identifies a specific server in a location where the data container is running"
}

variable "inst_id" {
default = "1"
description = "Identifies a specific instance of the service"
}

variable "core_hosts" {
type = list(string)
default = ["core"]
description = "List of upstream core containers. If core containers are on same Docker host, container name can be used. If core containers are on a seperate Docker host, IP or FQDN of host should be used."
}

variable "hostname" {
default = "monitoring_edge"
description = "Hostname to give the running container"
}

variable "docker_log_driver" {
default = "json-file"
description = "Docker log driver to use, see https://docs.docker.com/config/containers/logging/configure/"
}

variable "monitoring_region" {
default = "lga"
description = "Monitoring region code of the service definition"
}

variable "digest_service_def_id" {
default = "4"
description = "ID of the monitoring service definition for reading the monitoring jobs digest"
}

variable "log_level" {
default = "info"
description = "Logs level of monprobed service"
}

variable "metrics_addr_base" {
default = "unix:///var/run/ns1daemons/"
description = "Unix socket that monprobed serves metrics over"
}

variable "use_privileged_ping" {
default = "true"
description = "Use privileged to create the necessary raw ICMP sockets for ping probes"
}

variable "jitter_seconds" {
default = "5"
description = "A probe will take between 0 and jitter_seconds seconds to start running after it is created"
}