diff options
author | Will Chandler <wchandler@gitlab.com> | 2023-01-06 06:39:59 +0300 |
---|---|---|
committer | Will Chandler <wchandler@gitlab.com> | 2023-01-17 20:28:17 +0300 |
commit | 1d88c6c19e5bac15fc40334a3913ceb2090eb854 (patch) | |
tree | 97ef034ba5773482e600a5d2c5e0bd9643ad3295 /_support | |
parent | f4bbc120cc27cd3f4600e803225f9d4a12e52cc2 (diff) |
benchmarking: Add role to create benchmark hosts
Basic benchmarking will require two hosts, a Gitaly instance and a
client instance to send traffic from. Gitaly Cluster is beyond the scope
of this initial effort.
Create a terraform job that creates both hosts, with port 8075 open on
the Gitaly node for traffic. We use a `t2d` instance for Gitaly as these
provide 4 physical cores, as opposed to 2 hyperthreaded cores. In theory
this could reduce performance jitter, though I have not measured this to
be sure.
A disk image containing the test repositories is attached to the Gitaly
node on creation. These repositories are:
- git.git - A smaller repository with a fair amount of history.
- gitlab.git - Uses an object pool and has ~6,000,000 refs.
- linux.git - A large and well-groomed repository.
- homebrew-core.git - Has very large trees.
- chromium.git - Extremely large (40 GiB), with ~4,000,000 refs.
This task borrows its structure from the old Gitaly Cluster demo script in
`_support/terraform`.
Diffstat (limited to '_support')
-rw-r--r-- | _support/benchmarking/.gitignore | 4 | ||||
-rwxr-xr-x | _support/benchmarking/create-benchmark-instance | 2 | ||||
-rw-r--r-- | _support/benchmarking/create.yml | 21 | ||||
-rw-r--r-- | _support/benchmarking/roles/deploy/handlers/main.yml | 16 | ||||
-rw-r--r-- | _support/benchmarking/roles/deploy/tasks/main.yml | 38 | ||||
-rw-r--r-- | _support/benchmarking/roles/deploy/templates/all.yml.j2 | 2 | ||||
-rw-r--r-- | _support/benchmarking/roles/deploy/templates/hosts.ini.j2 | 5 | ||||
-rw-r--r-- | _support/benchmarking/roles/deploy/templates/terraform.tfvars.j2 | 3 | ||||
-rw-r--r-- | _support/benchmarking/terraform/main.tf | 111 |
9 files changed, 202 insertions, 0 deletions
diff --git a/_support/benchmarking/.gitignore b/_support/benchmarking/.gitignore new file mode 100644 index 000000000..aa8762020 --- /dev/null +++ b/_support/benchmarking/.gitignore @@ -0,0 +1,4 @@ +/hosts.ini +/terraform/* +!/terraform/main.tf +/group_vars/all.yml diff --git a/_support/benchmarking/create-benchmark-instance b/_support/benchmarking/create-benchmark-instance new file mode 100755 index 000000000..0173ac095 --- /dev/null +++ b/_support/benchmarking/create-benchmark-instance @@ -0,0 +1,2 @@ +#!/bin/sh +exec ansible-playbook -l localhost create.yml "$@" diff --git a/_support/benchmarking/create.yml b/_support/benchmarking/create.yml new file mode 100644 index 000000000..1e4942ba2 --- /dev/null +++ b/_support/benchmarking/create.yml @@ -0,0 +1,21 @@ +--- +- name: Set user-defined variables + hosts: localhost + vars_prompt: + - name: gitaly_revision + prompt: "Enter Gitaly revision to build" + default: HEAD + private: false + + - name: gitaly_benchmarking_instance_name + prompt: "Enter a name for your benchmark instance" + default: "{{ lookup('env', 'USER') }}-{{ lookup('pipe', 'date +%Y-%m-%d') }}" + private: false + + - name: ssh_pubkey + prompt: "Enter the path to your SSH public key" + default: "{{ lookup('env', 'HOME') }}/.ssh/id_ed25519.pub" + private: false + roles: + - deploy + gather_facts: false diff --git a/_support/benchmarking/roles/deploy/handlers/main.yml b/_support/benchmarking/roles/deploy/handlers/main.yml new file mode 100644 index 000000000..d5d2716a9 --- /dev/null +++ b/_support/benchmarking/roles/deploy/handlers/main.yml @@ -0,0 +1,16 @@ +--- +- name: scan SSH keys + command: "ssh-keyscan {{ item }}" + register: ssh_keys + loop: "{{ [tfstate.outputs.gitaly_ssh_ip.value] | list + [tfstate.outputs.client_ssh_ip.value] }}" + listen: add hostkeys + retries: 15 + until: ssh_keys is not failed + delay: 10 + +- name: add SSH keys to known hosts + known_hosts: + name: "{{ item.item }}" + key: "{{ item.stdout }}" + loop: "{{ ssh_keys.results }}" + listen: add hostkeys diff --git a/_support/benchmarking/roles/deploy/tasks/main.yml b/_support/benchmarking/roles/deploy/tasks/main.yml new file mode 100644 index 000000000..fc167cd23 --- /dev/null +++ b/_support/benchmarking/roles/deploy/tasks/main.yml @@ -0,0 +1,38 @@ +--- +- name: GCloud login + block: + - name: GCloud login status + command: gcloud auth application-default print-access-token + changed_when: false + rescue: + - name: GCloud login + command: gcloud auth application-default login + +- name: terraform.tfvars + template: + src: terraform.tfvars.j2 + dest: "{{ playbook_dir }}/terraform/terraform.tfvars" + +- name: terraform apply + terraform: + project_path: "{{ playbook_dir }}/terraform" + variables_file: terraform.tfvars + force_init: true + register: tfstate + notify: + - add hostkeys + +- name: hosts.ini + template: + src: hosts.ini.j2 + dest: "{{ playbook_dir }}/hosts.ini" + +- name: Create group_vars directory + file: + path: "{{ playbook_dir }}/group_vars" + state: directory + +- name: all.yml + template: + src: all.yml.j2 + dest: "{{ playbook_dir }}/group_vars/all.yml" diff --git a/_support/benchmarking/roles/deploy/templates/all.yml.j2 b/_support/benchmarking/roles/deploy/templates/all.yml.j2 new file mode 100644 index 000000000..e6ae9a89b --- /dev/null +++ b/_support/benchmarking/roles/deploy/templates/all.yml.j2 @@ -0,0 +1,2 @@ +--- +gitaly_revision: "{{ gitaly_revision }}" diff --git a/_support/benchmarking/roles/deploy/templates/hosts.ini.j2 b/_support/benchmarking/roles/deploy/templates/hosts.ini.j2 new file mode 100644 index 000000000..fb48fefa9 --- /dev/null +++ b/_support/benchmarking/roles/deploy/templates/hosts.ini.j2 @@ -0,0 +1,5 @@ +[gitaly] +{{ tfstate.outputs.gitaly_ssh_ip.value }} internal={{ tfstate.outputs.gitaly_internal_ip.value }} ansible_user=gitaly_bench + +[client] +{{ tfstate.outputs.client_ssh_ip.value }} internal={{ tfstate.outputs.client_internal_ip.value }} ansible_user=gitaly_bench diff --git a/_support/benchmarking/roles/deploy/templates/terraform.tfvars.j2 b/_support/benchmarking/roles/deploy/templates/terraform.tfvars.j2 new file mode 100644 index 000000000..e8c156c55 --- /dev/null +++ b/_support/benchmarking/roles/deploy/templates/terraform.tfvars.j2 @@ -0,0 +1,3 @@ +# This variable will be prefixed to all machines created by terraform +gitaly_benchmarking_instance_name = "{{ gitaly_benchmarking_instance_name }}" +ssh_pubkey = "{{ lookup('file', ssh_pubkey) }}" diff --git a/_support/benchmarking/terraform/main.tf b/_support/benchmarking/terraform/main.tf new file mode 100644 index 000000000..59f701d95 --- /dev/null +++ b/_support/benchmarking/terraform/main.tf @@ -0,0 +1,111 @@ +variable "project" { default = "gitaly-benchmark-0150d6cf" } +variable "benchmark_region" { default = "us-central1" } +variable "benchmark_zone" { default = "us-central1-a" } +variable "gitaly_benchmarking_instance_name" { } +variable "ssh_pubkey" { } +variable "os_image" { default = "ubuntu-os-cloud/ubuntu-2204-lts" } +variable "startup_script" { + default = <<EOF + set -e + if [ -d /src/gitaly ] ; then exit; fi + EOF +} +variable "gitaly_machine_type" { default = "t2d-standard-4" } +variable "client_machine_type" { default = "n1-standard-1" } +variable "boot_disk_size" { default = "20" } + +provider "google" { + project = var.project + region = var.benchmark_region + zone = var.benchmark_zone +} + +resource "google_compute_network" "default" { + name = "test-network" +} + +data "google_compute_disk" "repository-disk" { + name = "git-repos" + project = "gitaly-benchmark-0150d6cf" +} + +resource "google_compute_disk" "repository-disk" { + name = format("%s-repository-disk", var.gitaly_benchmarking_instance_name) + type = "pd-balanced" + image = format("projects/%s/global/images/git-repositories", var.project) +} + +resource "google_compute_instance" "gitaly" { + name = format("%s-gitaly", var.gitaly_benchmarking_instance_name) + machine_type = var.gitaly_machine_type + + boot_disk { + initialize_params { + image = var.os_image + size = var.boot_disk_size + } + } + + attached_disk { + source = google_compute_disk.repository-disk.name + device_name = "repository-disk" + } + + network_interface { + network = "default" + subnetwork = "default" + access_config {} + } + + metadata = { + ssh-keys = format("gitaly_bench:%s", var.ssh_pubkey) + startup-script = <<EOF + ${var.startup_script} + EOF + } + + tags = ["gitaly"] + + lifecycle { + ignore_changes = [attached_disk] + } +} + +resource "google_compute_instance" "client" { + name = format("%s-client", var.gitaly_benchmarking_instance_name) + machine_type = var.client_machine_type + + boot_disk { + initialize_params { + image = var.os_image + size = var.boot_disk_size + } + } + + network_interface { + subnetwork = "default" + access_config {} + } + + metadata = { + ssh-keys = format("gitaly_bench:%s", var.ssh_pubkey) + startup-script = <<EOF + ${var.startup_script} + EOF + } +} + +output "gitaly_internal_ip" { + value = google_compute_instance.gitaly.network_interface[0].network_ip +} +output "gitaly_ssh_ip" { + value = google_compute_instance.gitaly.network_interface[0].access_config[0].nat_ip +} + +output "client_internal_ip" { + value = google_compute_instance.client.network_interface[0].network_ip +} + +output "client_ssh_ip" { + value = google_compute_instance.client.network_interface[0].access_config[0].nat_ip +} |