diff --git a/inventory.yml b/inventory.yml index 63373f58..ef22e019 100644 --- a/inventory.yml +++ b/inventory.yml @@ -43,3 +43,8 @@ all: barman: true barman_server_private_ip: xxx.xxx.xxx.xxx barman_backup_method: postgres + hammerdbserver: + hosts: + hammerdb1: + ansible_host: xxx.xxx.xxx.xxx + private_ip: xxx.xxx.xxx.xxx diff --git a/plugins/lookup/hammerdb_server.py b/plugins/lookup/hammerdb_server.py new file mode 100644 index 00000000..557f33cd --- /dev/null +++ b/plugins/lookup/hammerdb_server.py @@ -0,0 +1,71 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = """ + name: hammerdb_server + author: Mark Wong + short_description: Lookup HammerDB server, based on its private_ip + description: + - "Lookup HammerDB server, based on its private_ip" + options: + _terms: + description: Private IP of the HammerDB server. + required: False + default: + description: hammerdb_server_private_ip of the current node. +""" + +EXAMPLES = """ +- name: Show HammerDB server informations + debug: msg="{{ lookup('hammerdb_server') }}" +""" + +RETURN = """ +_value: + description: + - List of HammerDB server nodes + type: list + elements: + - dict: node_type, hostname, ansible_host (public IP address), private_ip +""" + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + def run(self, terms, variables=None, **kwargs): + + myvars = getattr(self._templar, '_available_variables', {}) + inventory_hostname = variables['inventory_hostname'] + + # If no terms, we'll used the current HammerDB server private IP + if len(terms) == 0: + if 'hammerdb_server_private_ip' not in myvars['hostvars'][inventory_hostname]: + # hammerdb_server_private_ip not set, return None + return [] + hammerdb_server_private_ip = myvars['hostvars'][inventory_hostname]['hammerdb_server_private_ip'] + else: + hammerdb_server_private_ip = terms[0] + + # If no hammerdbserver found in the inventory file, just return None + if 'hammerdbserver' not in variables['groups']: + return [] + if len(variables['groups']['hammerdbserver']) == 0: + return [] + + # Lookup for hammerdb servers with a matching private_ip + for host in variables['groups']['hammerdbserver']: + hostvars = myvars['hostvars'][host] + + if hostvars['private_ip'] != hammerdb_server_private_ip: + continue + + return [ + dict( + node_type='hammerdbserver', + ansible_host=hostvars['ansible_host'], + hostname=hostvars.get('hostname', hostvars['ansible_hostname']), + private_ip=hostvars['private_ip'], + inventory_hostname=hostvars['inventory_hostname'] + ) + ] diff --git a/plugins/lookup/supported_roles.py b/plugins/lookup/supported_roles.py index 6c51a1f9..dad6e7b1 100644 --- a/plugins/lookup/supported_roles.py +++ b/plugins/lookup/supported_roles.py @@ -65,6 +65,10 @@ 'setup_repo', 'setup_barmanserver', 'install_dbserver' + ], + 'hammerdbserver': [ + 'setup_repo', + 'setup_hammerdbserver' ] } @@ -106,4 +110,12 @@ def run(self, terms, variables=None, **kwargs): set(supported_roles) | set(['setup_barman']) ) + # Special case for the primary nodes when the host variable + # hammerdb is set to true. + if (group in ['primary'] + and myvars['hostvars'][hostname].get('hammerdb', False)): + supported_roles = list( + set(supported_roles) + | set(['setup_hammerdb']) + ) return supported_roles diff --git a/roles/setup_hammerdb/README.md b/roles/setup_hammerdb/README.md new file mode 100644 index 00000000..04866c23 --- /dev/null +++ b/roles/setup_hammerdb/README.md @@ -0,0 +1,22 @@ +# setup_hammerdb + +This role is for installing HammerDB. + +## Requirements + +Following are the requirements of this role. + 1. Ansible + 2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository on + the systems. + +## License + +BSD + +## Author information + +Author: + + * Mark Wong + * EDB Postgres + * edb-devops@enterprisedb.com www.enterprisedb.com diff --git a/roles/setup_hammerdb/defaults/main.yml b/roles/setup_hammerdb/defaults/main.yml new file mode 100644 index 00000000..3342b913 --- /dev/null +++ b/roles/setup_hammerdb/defaults/main.yml @@ -0,0 +1,5 @@ +--- + +supported_os: + - CentOS8 + - RHEL8 diff --git a/roles/setup_hammerdb/meta/main.yml b/roles/setup_hammerdb/meta/main.yml new file mode 100644 index 00000000..6c1f0653 --- /dev/null +++ b/roles/setup_hammerdb/meta/main.yml @@ -0,0 +1,22 @@ +--- +galaxy_info: + author: EDB + description: Setup HammerDB + company: "EnterpriseDB" + + license: BSD + + min_ansible_version: 2.8 + + platforms: + - name: CentOS + versions: + - 8 + - name: Red Hat + versions: + - 8 + + galaxy_tags: + - database + +dependencies: [] diff --git a/roles/setup_hammerdb/tasks/configure_postgres_params.yml b/roles/setup_hammerdb/tasks/configure_postgres_params.yml new file mode 100644 index 00000000..7e50e146 --- /dev/null +++ b/roles/setup_hammerdb/tasks/configure_postgres_params.yml @@ -0,0 +1,35 @@ +--- + +- name: Update PostgreSQL parameters for TPROC-C + include_role: + name: manage_dbserver + tasks_from: manage_postgres_params + vars: + pg_postgres_conf_params: + - name: max_connections + value: 300 + - name: shared_buffers + value: "16384MB" + - name: work_mem + value: "64MB" + - name: maintenance_work_mem + value: "620MB" + - name: effective_cache_size + value: "45 GB" + - name: random_page_cost + value: 1.25 + - name: effective_io_concurrency + value: 200 + - name: checkpoint_timeout + value: "15min" + - name: checkpoint_completion_target + value: 0.9 + - name: max_wal_size + value: "30GB" + - name: min_wal_size + value: "10GB" + - name: wal_buffers + value: "512MB" + - name: jit + value: on + no_log: "{{ disable_logging }}" diff --git a/roles/setup_hammerdb/tasks/main.yml b/roles/setup_hammerdb/tasks/main.yml new file mode 100644 index 00000000..0b7fc5c8 --- /dev/null +++ b/roles/setup_hammerdb/tasks/main.yml @@ -0,0 +1,31 @@ +--- + +- name: Include the HBA file update tasks + include_tasks: update_pg_hba.yml + +- name: Include Postgres configuration for TPROC-C + include_tasks: configure_postgres_params.yml + +- name: Include HammerDB installation + include_role: + name: setup_hammerdbserver + tasks_from: install_hammerdb + +- name: Include Touchstone installation + include_role: + name: setup_touchstone + tasks_from: main + +- name: Create TPROC-C loader.tcl + template: + dest: loader.tcl + src: ./templates/loader.tcl.template + mode: 0644 + become: no + +- name: Create TPROC-C load script + template: + src: ./templates/load-tproc-c.template + dest: /usr/local/bin/load-tproc-c + mode: 0755 + become: yes diff --git a/roles/setup_hammerdb/tasks/update_pg_hba.yml b/roles/setup_hammerdb/tasks/update_pg_hba.yml new file mode 100644 index 00000000..cc172b1b --- /dev/null +++ b/roles/setup_hammerdb/tasks/update_pg_hba.yml @@ -0,0 +1,35 @@ +--- + +- name: Reference pg_type variables + include_vars: "{{ role_path }}/../init_dbserver/vars/{{ pg_type }}.yml" + +- name: Initialize the hba_entries variable + set_fact: + hba_entries: >- + [ + { + 'users': 'all', + 'databases': 'all', + 'contype': 'host', + 'source': '{{ hostvars[inventory_hostname].hammerdb_server_private_ip | default("127.0.0.1") }}/32', + 'method': 'trust' + }, + { + 'users': 'all', + 'databases': 'all', + 'contype': 'host', + 'source': '{{ hostvars['primary1'].private_ip | default("127.0.0.1") }}/32', + 'method': 'trust' + } + ] + +- name: Allow access from the hammerdb server + include_role: + name: manage_dbserver + tasks_from: manage_hba_conf + vars: + pg_hba_ip_addresses: "{{ hba_entries }}" + +- name: Reset hba_entries + set_fact: + hba_entries: [] diff --git a/roles/setup_hammerdb/templates/load-tproc-c.template b/roles/setup_hammerdb/templates/load-tproc-c.template new file mode 100644 index 00000000..79f49e9d --- /dev/null +++ b/roles/setup_hammerdb/templates/load-tproc-c.template @@ -0,0 +1,7 @@ +#!/bin/sh +(cd ${HOME}/HammerDB-{{ hammerdb_version }} && \ +./hammerdbcli << ! +source ${HOME}/loader.tcl +! +) +echo "load complete" diff --git a/roles/setup_hammerdb/templates/loader.tcl.template b/roles/setup_hammerdb/templates/loader.tcl.template new file mode 100644 index 00000000..8a97968d --- /dev/null +++ b/roles/setup_hammerdb/templates/loader.tcl.template @@ -0,0 +1,16 @@ +#!/usr/bin/env tclsh +global complete +proc wait_to_complete {} { + global complete + set complete [vucomplete] + if {!$complete} {after 5000 wait_to_complete} else { exit } +} +dbset db pg +diset connection pg_host {{ hostvars['primary1'].private_ip }} +diset connection pg_port {{ pg_port }} +diset tpcc pg_count_ware 600 +diset tpcc pg_num_vu {{ ansible_processor_vcpus }} +diset tpcc pg_raiseerror true +diset tpcc pg_superuser postgres +buildschema +wait_to_complete diff --git a/roles/setup_hammerdbserver/README.md b/roles/setup_hammerdbserver/README.md new file mode 100644 index 00000000..32a09637 --- /dev/null +++ b/roles/setup_hammerdbserver/README.md @@ -0,0 +1,42 @@ + +# setup_hammerdbserver + +This role is for setting up a server for [HammerDB](https://hammerdb.com/). +HammerDB is the leading benchmarking and load testing software for the worlds +most popular databases. + +## Requirements + +Following are the requirements of this role. + 1. Ansible + 2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository + on the systems. + +## Role Variables + +The variables that can be configured and are available in the: + + * [roles/setup_hammerdbserver/defaults/main.yml](./defaults/main.yml) + +Below is the documentation of the rest of the main variables: + +### `hammerdb_version` + +The release version of HammerDB. Default: 3.3 + +Example: +```yaml +hammerdb_version: 3.3 +``` + +## License + +BSD + +## Author information + +Author: + + * Mark Wong + * EDB Postgres + * edb-devops@enterprisedb.com www.enterprisedb.com diff --git a/roles/setup_hammerdbserver/defaults/main.yml b/roles/setup_hammerdbserver/defaults/main.yml new file mode 100644 index 00000000..af603a9d --- /dev/null +++ b/roles/setup_hammerdbserver/defaults/main.yml @@ -0,0 +1,6 @@ +--- + +hammerdb_version: 3.3 +supported_os: + - CentOS8 + - RHEL8 diff --git a/roles/setup_hammerdbserver/meta/main.yml b/roles/setup_hammerdbserver/meta/main.yml new file mode 100644 index 00000000..f173a245 --- /dev/null +++ b/roles/setup_hammerdbserver/meta/main.yml @@ -0,0 +1,22 @@ +--- +galaxy_info: + author: EDB + description: Setup HammerDB server + company: "EnterpriseDB" + + license: BSD + + min_ansible_version: 2.8 + + platforms: + - name: CentOS + versions: + - 8 + - name: Red Hat + versions: + - 8 + + galaxy_tags: + - database + +dependencies: [] diff --git a/roles/setup_hammerdbserver/tasks/install_hammerdb.yml b/roles/setup_hammerdbserver/tasks/install_hammerdb.yml new file mode 100644 index 00000000..d8127206 --- /dev/null +++ b/roles/setup_hammerdbserver/tasks/install_hammerdb.yml @@ -0,0 +1,9 @@ +--- + +- name: Download HammerDB + raw: curl -OL https://github.com/TPC-Council/HammerDB/releases/download/v{{ hammerdb_version }}/HammerDB-{{ hammerdb_version }}-Linux.tar.gz + become: no + +- name: Install HammerDB + raw: tar -xvf HammerDB-{{ hammerdb_version }}-Linux.tar.gz + become: no diff --git a/roles/setup_hammerdbserver/tasks/main.yml b/roles/setup_hammerdbserver/tasks/main.yml new file mode 100644 index 00000000..cfe43114 --- /dev/null +++ b/roles/setup_hammerdbserver/tasks/main.yml @@ -0,0 +1,32 @@ +--- + +- name: Install packages + yum: + name: + - curl + - tcl + - libpq + become: yes + ignore_errors: yes + +- name: Include Touchstone installation + include_role: + name: setup_touchstone + tasks_from: main + +- name: Include HammerDB installation + include_tasks: install_hammerdb.yml + +- name: Create TPROC-C runner.tcl + template: + dest: runner.tcl + src: ./templates/runner.tcl.template + mode: 0644 + become: no + +- name: Create TPROC-C run script + template: + src: ./templates/run-tproc-c.template + dest: /usr/local/bin/run-tproc-c + mode: 0755 + become: yes diff --git a/roles/setup_hammerdbserver/templates/run-tproc-c.template b/roles/setup_hammerdbserver/templates/run-tproc-c.template new file mode 100644 index 00000000..83a4d3d5 --- /dev/null +++ b/roles/setup_hammerdbserver/templates/run-tproc-c.template @@ -0,0 +1,14 @@ +#!/bin/sh + +DATE=`date +"%Y-%m-%dT%T%:z"` +LDIR="${HOME}/results/driver/${DATE}" +RDIR="${HOME}/results/sut/${DATE}" + +ssh -fn {{ hostvars['primary1'].private_ip }} ts-sysstat -o $RDIR +(cd ${HOME}/HammerDB-{{ hammerdb_version }} && \\ +ts-sysstat -o $LDIR ./hammerdbcli << ! +source ${HOME}/runner.tcl +! +) +ssh -fn {{ hostvars['primary1'].private_ip }} ts-sysstat -o $RDIR -s +grep "TEST RESULT" /tmp/hammerdb.log | tail -n 1 > ${LDIR}/hammerdb.txt diff --git a/roles/setup_hammerdbserver/templates/runner.tcl.template b/roles/setup_hammerdbserver/templates/runner.tcl.template new file mode 100644 index 00000000..0095227f --- /dev/null +++ b/roles/setup_hammerdbserver/templates/runner.tcl.template @@ -0,0 +1,31 @@ +#!/usr/bin/env tclsh +proc runtimer { seconds } { + set x 0 + set timerstop 0 + while {!$timerstop} { + incr x + after 1000 + if { ![ expr {$x % 60} ] } { + set y [ expr $x / 60 ] + } + update + if { [ vucomplete ] || $x eq $seconds } { set timerstop 1 } + } + return +} +dbset db pg +diset connection pg_host {{ hostvars['primary1'].private_ip }} +diset connection pg_port {{ pg_port }} +diset tpcc pg_raiseerror true +diset tpcc pg_superuser enterprisedb +diset tpcc pg_driver timed +diset tpcc pg_duration 30 +diset tpcc pg_rampup 5 +vuset logtotemp 1 +loadscript +vuset vu 96 +vucreate +vurun +runtimer 2200 +vudestroy +exit diff --git a/roles/setup_touchstone/README.md b/roles/setup_touchstone/README.md new file mode 100644 index 00000000..3675e09a --- /dev/null +++ b/roles/setup_touchstone/README.md @@ -0,0 +1,40 @@ +# setup_touchstone + +This role is for setting up additional packages and software for characterizing +system performance. + +## Requirements + +Following are the requirements of this role. + 1. Ansible + 2. `edb_devops.edb_postgres` -> `setup_repo` role for setting the repository on + the systems. + +## Role Variables + +The variables that can be configured and are available in the: + + * [roles/setup_touchstone/defaults/main.yml](./defaults/main.yml) + +Below is the documentation of the rest of the main variables: + +### `touchstone_version` + +The version of Touchstone. Default: 0.2.0 + +Example: +```yaml +touchstone_version: 0.2.0 +``` + +## License + +BSD + +## Author information + +Author: + + * Mark Wong + * EDB Postgres + * edb-devops@enterprisedb.com www.enterprisedb.com diff --git a/roles/setup_touchstone/defaults/main.yml b/roles/setup_touchstone/defaults/main.yml new file mode 100644 index 00000000..65b1b916 --- /dev/null +++ b/roles/setup_touchstone/defaults/main.yml @@ -0,0 +1,6 @@ +--- + +touchstone_version: 0.2.2 +supported_os: + - CentOS8 + - RHEL8 diff --git a/roles/setup_touchstone/meta/main.yml b/roles/setup_touchstone/meta/main.yml new file mode 100644 index 00000000..6c1f0653 --- /dev/null +++ b/roles/setup_touchstone/meta/main.yml @@ -0,0 +1,22 @@ +--- +galaxy_info: + author: EDB + description: Setup HammerDB + company: "EnterpriseDB" + + license: BSD + + min_ansible_version: 2.8 + + platforms: + - name: CentOS + versions: + - 8 + - name: Red Hat + versions: + - 8 + + galaxy_tags: + - database + +dependencies: [] diff --git a/roles/setup_touchstone/tasks/main.yml b/roles/setup_touchstone/tasks/main.yml new file mode 100644 index 00000000..0fb9f933 --- /dev/null +++ b/roles/setup_touchstone/tasks/main.yml @@ -0,0 +1,31 @@ +--- + +- name: Install packages for Touchstone + yum: + name: + - cmake + - gcc + - make + - sysstat + become: yes + ignore_errors: yes + +- name: Download Touchstone + raw: curl -OL https://gitlab.com/touchstone/touchstone/-/archive/v{{ touchstone_version }}/touchstone-v{{ touchstone_version }}.tar.gz + become: no + +- name: Unpack Touchstone + raw: tar -xvf touchstone-v{{ touchstone_version }}.tar.gz + become: no + +- name: Build Touchstone + shell: + cmd: make release + chdir: touchstone-v{{ touchstone_version }} + become: no + +- name: Install Touchstone + shell: + cmd: make install + chdir: touchstone-v{{ touchstone_version }}/build/release + become: yes