Skip to content

Commit

Permalink
Add support for using apm-data
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Apr 22, 2024
1 parent 34a8c9c commit 0423d59
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 5 deletions.
6 changes: 6 additions & 0 deletions testing/cloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ module "ec_deployment" {
region = var.ess_region
stack_version = local.stack_version

# TODO(axw) make this optional
delete_integration_index_templates = true
elasticsearch_user_settings_yaml = <<EOF
xpack.apm_data.enabled: true
EOF

deployment_template = var.deployment_template
deployment_name_prefix = "apm-server-testing"

Expand Down
7 changes: 7 additions & 0 deletions testing/cloud/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ variable "apm_server_zone_count" {
description = "Optional apm server zone count"
}

# TODO(axw) make it configurable
#variable "use_elasticsearch_apmdata_plugin" {
# default = false
# type = bool
# description = "Enable the Elasticsearch apm-data plugin, and disable integration package index templates."
#}

variable "elasticsearch_size" {
default = "8g"
type = string
Expand Down
6 changes: 1 addition & 5 deletions testing/infra/terraform/modules/ec_deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
scripts/enable_expvar.sh
scripts/secret_token.sh
scripts/index_shards.sh
scripts/custom-apm-integration-pkg.sh
scripts/drop_pipeline.sh
scripts/*.sh
26 changes: 26 additions & 0 deletions testing/infra/terraform/modules/ec_deployment/deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ resource "ec_deployment" "deployment" {
}
}
dynamic "config" {
# TODO(axw) fix the dynamic block to consider user_settings_yaml too
# or create multiple dynamic blocks and merge them?
for_each = var.docker_image_tag_override["elasticsearch"] != "" ? [var.docker_image["elasticsearch"]] : []
content {
docker_image = "${config.value}:${var.docker_image_tag_override["elasticsearch"]}"
user_settings_yaml = var.elasticsearch_user_settings_yaml
}
}
}
Expand Down Expand Up @@ -236,3 +239,26 @@ resource "local_file" "drop_pipeline" {
})
filename = "${path.module}/scripts/drop_pipeline.sh"
}

resource "null_resource" "delete_integration_index_templates" {
count = var.delete_integration_index_templates ? 1 : 0
triggers = {
deployment_id = ec_deployment.deployment.id
shell_hash = local_file.delete_integration_index_templates.0.id
}
provisioner "local-exec" {
command = "scripts/delete_integration_index_templates.sh"
interpreter = ["/bin/bash", "-c"]
working_dir = path.module
}
}

resource "local_file" "delete_integration_index_templates" {
count = var.delete_integration_index_templates ? 1 : 0
content = templatefile("${path.module}/scripts/delete_integration_index_templates.tfpl", {
elasticsearch_url = ec_deployment.deployment.elasticsearch.0.https_endpoint,
elasticsearch_password = ec_deployment.deployment.elasticsearch_password,
elasticsearch_username = ec_deployment.deployment.elasticsearch_username,
})
filename = "${path.module}/scripts/delete_integration_index_templates.sh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

index_templates=(
"logs-apm.app"
"logs-apm.error"
"metrics-apm.app"
"metrics-apm.internal"
"metrics-apm.service_destination.1m"
"metrics-apm.service_destination.10m"
"metrics-apm.service_destination.60m"
"metrics-apm.service_summary.1m"
"metrics-apm.service_summary.10m"
"metrics-apm.service_summary.60m"
"metrics-apm.service_transaction.1m"
"metrics-apm.service_transaction.10m"
"metrics-apm.service_transaction.60m"
"metrics-apm.transaction.1m"
"metrics-apm.transaction.10m"
"metrics-apm.transaction.60m"
"traces-apm"
"traces-apm.rum"
"traces-apm.sampled"
)

for tpl in $${index_templates[@]}; do
curl -s --fail -XDELETE -u ${elasticsearch_username}:${elasticsearch_password} "${elasticsearch_url}/_index_template/$${tpl}"
# TODO(axw) check exit code. curl exits with 22 on a status code >= 400.
# We want the operation to be idempotent, so we should not fail if the index template does not exist (404).
# We should fail on other errors though.
done
exit 0
11 changes: 11 additions & 0 deletions testing/infra/terraform/modules/ec_deployment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ variable "elasticsearch_size" {
description = "Optional Elasticsearch instance size"
}

variable "elasticsearch_user_settings_yaml" {
type = string
description = "Optional Elasticsearch user settings"
}

variable "elasticsearch_zone_count" {
default = 2
type = number
Expand Down Expand Up @@ -143,3 +148,9 @@ variable "drop_pipeline" {
description = "Whether or not to install an Elasticsearch ingest pipeline to drop all incoming APM documents. Defaults to false"
type = bool
}

variable "delete_integration_index_templates" {
default = false
description = "Whether or not to delete the APM integration Elasticsearch index templates after setup. Defaults to false"
type = bool
}

0 comments on commit 0423d59

Please sign in to comment.