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 option to enable TBS in benchmark terraform #14985

Merged
merged 14 commits into from
Dec 17, 2024
6 changes: 6 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: false
type: boolean
default: false
enableTailSampling:
description: 'Enable tail-based sampling on the APM server'
required: false
type: boolean
default: false
profile:
description: 'The system profile used to run the benchmarks'
required: false
Expand Down Expand Up @@ -52,6 +57,7 @@ jobs:
TF_VAR_private_key: ./id_rsa_terraform
TF_VAR_public_key: ./id_rsa_terraform.pub
TF_VAR_run_standalone: ${{ inputs.runStandalone || github.event.schedule=='0 5 */5 * *' }}
TF_VAR_apm_server_tail_sampling: ${{ inputs.enableTailSampling }}
RUN_STANDALONE: ${{ inputs.runStandalone || github.event.schedule=='0 5 */5 * *' }}
TFVARS_SOURCE: ${{ inputs.profile || 'system-profiles/8GBx1zone.tfvars' }} # // Default to use an 8gb profile
TF_VAR_BUILD_ID: ${{ github.run_id }}
Expand Down
1 change: 1 addition & 0 deletions testing/benchmark/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ module "ec_deployment" {
drop_pipeline = var.drop_pipeline
apm_server_expvar = true
apm_server_pprof = true
apm_server_tail_sampling = var.apm_server_tail_sampling

elasticsearch_size = var.elasticsearch_size
elasticsearch_zone_count = var.elasticsearch_zone_count
Expand Down
6 changes: 6 additions & 0 deletions testing/benchmark/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ variable "drop_pipeline" {
type = bool
}

variable "apm_server_tail_sampling" {
default = false
description = "Whether or not to enable APM Server tail-based sampling. Defaults to false"
type = bool
}

# Standalone

variable "apm_server_bin_path" {
Expand Down
9 changes: 5 additions & 4 deletions testing/infra/terraform/modules/ec_deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ used to configure the module, please refer to the [EC Provider docs](https://reg
| [ec_deployment.deployment](https://registry.terraform.io/providers/elastic/ec/0.5.1/docs/resources/deployment) | resource |
| [local_file.custom_apm_integration_pkg](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.drop_pipeline](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.enable_expvar](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.enable_features](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.secret_token](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [local_file.shard_settings](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [null_resource.custom_apm_integration_pkg](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.drop_pipeline](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.enable_expvar](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.enable_features](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.secret_token](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [null_resource.shard_settings](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [ec_stack.deployment_version](https://registry.terraform.io/providers/elastic/ec/0.5.1/docs/data-sources/stack) | data source |
Expand All @@ -47,12 +47,13 @@ used to configure the module, please refer to the [EC Provider docs](https://reg
| <a name="input_apm_server_expvar"></a> [apm\_server\_expvar](#input\_apm\_server\_expvar) | Whether or not to enable APM Server's expvar endpoint. Defaults to false | `bool` | `false` | no |
| <a name="input_apm_server_pprof"></a> [apm\_server\_pprof](#input\_apm\_server\_pprof) | Whether or not to enable APM Server's pprof endpoint. Defaults to false | `bool` | `false` | no |
| <a name="input_apm_server_size"></a> [apm\_server\_size](#input\_apm\_server\_size) | Optional apm server instance size | `string` | `"1g"` | no |
| <a name="input_apm_server_tail_sampling"></a> [apm\_server\_tbs](#input\_apm\_server\_tbs) | Whether or not to enable APM Server tail-based sampling. Defaults to false | `bool` | `false` | no |
| <a name="input_apm_server_zone_count"></a> [apm\_server\_zone\_count](#input\_apm\_server\_zone\_count) | Optional apm server zone count | `number` | `1` | no |
| <a name="input_custom_apm_integration_pkg_path"></a> [custom\_apm\_integration\_pkg\_path](#input\_custom\_apm\_integration\_pkg\_path) | Path to the zipped custom APM integration package, if empty custom apm integration pkg is not installed | `string` | `""` | no |
| <a name="input_deployment_name_prefix"></a> [deployment\_name\_prefix](#input\_deployment\_name\_prefix) | Optional ESS or ECE region. Defaults to GCP US West 2 (Los Angeles) | `string` | `"apmserver"` | no |
| <a name="input_deployment_template"></a> [deployment\_template](#input\_deployment\_template) | Optional deployment template. Defaults to the CPU optimized template for GCP | `string` | `"gcp-cpu-optimized"` | no |
| <a name="input_docker_image"></a> [docker\_image](#input\_docker\_image) | Optional docker image overrides. The full map needs to be specified | `map(string)` | <pre>{<br> "apm": "docker.elastic.co/cloud-release/elastic-agent-cloud",<br> "elasticsearch": "docker.elastic.co/cloud-release/elasticsearch-cloud-ess",<br> "kibana": "docker.elastic.co/cloud-release/kibana-cloud"<br>}</pre> | no |
| <a name="input_docker_image_tag_override"></a> [docker\_image\_tag\_override](#input\_docker\_image\_tag\_override) | Optional docker image tag overrides, The full map needs to be specified | `map(string)` | <pre>{<br> "apm": "",<br> "elasticsearch": "",<br> "kibana": ""<br>}</pre> | no |
| <a name="input_docker_image"></a> [docker\_image](#input\_docker\_image) | Optional docker image overrides. The full map needs to be specified | `map(string)` | <pre>{<br/> "apm": "docker.elastic.co/cloud-release/elastic-agent-cloud",<br/> "elasticsearch": "docker.elastic.co/cloud-release/elasticsearch-cloud-ess",<br/> "kibana": "docker.elastic.co/cloud-release/kibana-cloud"<br/>}</pre> | no |
| <a name="input_docker_image_tag_override"></a> [docker\_image\_tag\_override](#input\_docker\_image\_tag\_override) | Optional docker image tag overrides, The full map needs to be specified | `map(string)` | <pre>{<br/> "apm": "",<br/> "elasticsearch": "",<br/> "kibana": ""<br/>}</pre> | no |
| <a name="input_drop_pipeline"></a> [drop\_pipeline](#input\_drop\_pipeline) | Whether or not to install an Elasticsearch ingest pipeline to drop all incoming APM documents. Defaults to false | `bool` | `false` | no |
| <a name="input_elasticsearch_autoscale"></a> [elasticsearch\_autoscale](#input\_elasticsearch\_autoscale) | Optional autoscale the Elasticsearch cluster | `bool` | `false` | no |
| <a name="input_elasticsearch_dedicated_masters"></a> [elasticsearch\_dedicated\_masters](#input\_elasticsearch\_dedicated\_masters) | Optionally use dedicated masters for the Elasticsearch cluster | `bool` | `false` | no |
Expand Down
13 changes: 7 additions & 6 deletions testing/infra/terraform/modules/ec_deployment/deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ resource "ec_deployment" "dedicated_observability_deployment" {
kibana {}
}

resource "local_file" "enable_expvar" {
content = templatefile("${path.module}/scripts/enable_expvar.tftpl", {
resource "local_file" "enable_features" {
content = templatefile("${path.module}/scripts/enable_features.tftpl", {
kibana_url = ec_deployment.deployment.kibana.0.https_endpoint,
elastic_password = ec_deployment.deployment.elasticsearch_password,
enable_expvar = var.apm_server_expvar
enable_pprof = var.apm_server_pprof
enable_tail_sampling = var.apm_server_tail_sampling
})
filename = "${path.module}/scripts/enable_expvar.sh"
filename = "${path.module}/scripts/enable_features.sh"
}

resource "local_file" "secret_token" {
Expand Down Expand Up @@ -153,13 +154,13 @@ resource "local_file" "custom_apm_integration_pkg" {
filename = "${path.module}/scripts/custom-apm-integration-pkg.sh"
}

resource "null_resource" "enable_expvar" {
resource "null_resource" "enable_features" {
triggers = {
shell_hash = local_file.enable_expvar.id
shell_hash = local_file.enable_features.id
integrations_server = var.integrations_server
}
provisioner "local-exec" {
command = "scripts/enable_expvar.sh"
command = "scripts/enable_features.sh"
interpreter = ["/bin/bash", "-c"]
working_dir = path.module
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ if [[ "$${POLICY}" == *"$${NOT_FOUND_MSG}"* ]]; then
exit 0
fi

echo $${POLICY} | grep '"expvar_enabled":{"type":"bool","value":true}' > /dev/null 2>&1 && EXPVAR_ENABLED=true
echo $${POLICY} | grep '"pprof_enabled":{"type":"bool","value":true}' > /dev/null 2>&1 && PPROF_ENABLED=true
if [[ $${EXPVAR_ENABLED} || $${PPROF_ENABLED} ]] ; then
echo "expvar or pprof already enabled"
exit 0
fi
# Abort early if features are already set as desired
carsonip marked this conversation as resolved.
Show resolved Hide resolved
echo $${POLICY} | jq -e '.item | select(.inputs[].policy_template == "apmserver").inputs[].vars.expvar_enabled.value == ${enable_expvar}' &&
echo $${POLICY} | jq -e '.item | select(.inputs[].policy_template == "apmserver").inputs[].vars.pprof_enabled.value == ${enable_pprof}' &&
echo $${POLICY} | jq -e '.item | select(.inputs[].policy_template == "apmserver").inputs[].vars.tail_sampling_enabled.value == ${enable_tail_sampling}' &&
echo "Features already set as desired" && exit 0

# Download and modify the APM policy
echo $${POLICY} | jq '.item' | \
jq 'del(.id)' | jq 'del(.elasticsearch)'| jq 'del(.inputs[].compiled_input)' | jq 'del(.revision)' |\
jq 'del(.created_at)' | jq 'del(.created_by)' | jq 'del(.updated_at)' | jq 'del(.updated_by)' |\
jq 'select(.inputs[].policy_template == "apmserver").inputs[].vars.expvar_enabled = {type: "bool", value: ${enable_expvar}}' |\
jq 'select(.inputs[].policy_template == "apmserver").inputs[].vars.pprof_enabled = {type: "bool", value: ${enable_pprof}}' > policy.json
jq 'select(.inputs[].policy_template == "apmserver").inputs[].vars.pprof_enabled = {type: "bool", value: ${enable_pprof}}' |\
jq 'select(.inputs[].policy_template == "apmserver").inputs[].vars.tail_sampling_storage_limit = {"value":"10GB","type":"text"}' |\ # set TBS storage limit to 10GB by default
jq 'select(.inputs[].policy_template == "apmserver").inputs[].vars.tail_sampling_enabled = {type: "bool", value: ${enable_tail_sampling}}' > policy.json

# Update the policy
curl -s -H 'content-type: application/json' -H 'kbn-xsrf: true' -X PUT -k [email protected] -u $${KIBANA_AUTH} $${KIBANA_ENDPOINT}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ variable "docker_image" {
description = "Optional docker image overrides. The full map needs to be specified"
}

# Enable APM Server's expvar
# Enable APM Server's features

variable "apm_server_expvar" {
default = false
Expand All @@ -122,6 +122,12 @@ variable "apm_server_pprof" {
type = bool
}

variable "apm_server_tail_sampling" {
default = false
description = "Whether or not to enable APM Server tail-based sampling. Defaults to false"
type = bool
}

variable "apm_index_shards" {
default = 0
description = "The number of shards to set for APM Indices"
Expand Down
Loading