From 33838099f5b38bf60ab20fc62eb8b73180f95349 Mon Sep 17 00:00:00 2001 From: JakubKotkowiak <52407257+JakubKotkowiak@users.noreply.github.com> Date: Wed, 3 Feb 2021 03:36:26 +0100 Subject: [PATCH] Couchbase debian recipe (#162) * feat(debian): add recipe for couchbase * feat(debian): add test definition for couchbase * feat(debian): add test file containing ansible plays * refactor(debian): decrease resources * refactor(debian): try localhost * refactor(debian): add pause after installing couchbase * refactor(debian): increase memory * refactor(debian): increase instance size * refactor(debian): adapt cluster ramsize * refactor(debian): change url * refactor(debian): fix passing port variable to config * refactor(debian): remove -a flag from tee command * refactor(debian): fix config variables * refactor(debian): change process match * refactor(debian): fix username * refactor(debian): modify process match * refactor(debian): check different recipe construction * refactor(debian): fix logmatch * refactor(debian): change silent to false * refactor(debian): fix variables * refactor(debian): change silent to true * chore: move to new ohi directory * chore(nit): adjusting username and capitalization Co-authored-by: Justin Eveland --- .../infrastructure/ohi/couchbase/debian.yml | 121 ++++++++++++++++++ .../ohi/linux/couchbase-debian.json | 59 +++++++++ .../debian/roles/configure/tasks/main.yml | 56 ++++++++ 3 files changed, 236 insertions(+) create mode 100644 recipes/newrelic/infrastructure/ohi/couchbase/debian.yml create mode 100644 test/definitions/ohi/linux/couchbase-debian.json create mode 100644 test/deploy/linux/couchbase/install/debian/roles/configure/tasks/main.yml diff --git a/recipes/newrelic/infrastructure/ohi/couchbase/debian.yml b/recipes/newrelic/infrastructure/ohi/couchbase/debian.yml new file mode 100644 index 000000000..44cdff350 --- /dev/null +++ b/recipes/newrelic/infrastructure/ohi/couchbase/debian.yml @@ -0,0 +1,121 @@ +name: couchbase-open-source-integration +displayName: Couchbase Open Source Integration +description: New Relic install recipe for default Couchbase Open Source on-host integration (via Infra-Agent) +repository: https://github.com/newrelic/nri-couchbase + +installTargets: + - type: host + os: linux + platform: "debian" + - type: host + os: linux + platform: "ubuntu" + +# keyword convention for dealing with search terms that could land someone on this instrumentation project +keywords: + - Infrastructure + - Integration + - couchbase + +# CLI runs process detection; this is used to filter recipes that are appropriate for matched processes +processMatch: + - couchbase + +# Matches partial list of the Log forwarding parameters +logMatch: + - name: Couchbase Error + file: /opt/couchbase/var/lib/couchbase/logs/error.log + - name: Couchbase General + file: /opt/couchbase/var/lib/couchbase/logs/couchdb.log + +validationNrql: "SELECT count(*) from CouchbaseNodeSample where hostname like '{{.HOSTNAME}}%' FACET entityGuid SINCE 10 minutes ago" + +inputVars: + - name: "NR_CLI_API_USERNAME" + prompt: "Couchbase Username" + - name: "NR_CLI_API_PASSWORD" + prompt: "Couchbase Password" + - name: "NR_CLI_API_HOSTNAME" + prompt: "Couchbase Hostname (default: localhost)" + default: "localhost" + - name: "NR_CLI_API_PORT" + prompt: "Couchbase Port (default: 8091)" + default: 8091 + - name: "NR_CLI_API_QUERY_PORT" + prompt: "Couchbase Query Port (default: 8093)" + default: 8093 + - name: "NR_CLI_API_USE_SSL" + prompt: "Use SSL to connect? (true/false)" + default: false + - name: "NR_CLI_API_CA_BUNDLE_DIR" + prompt: "SSL Certificate Directory (if applicable)" + - name: "NR_CLI_API_CA_BUNDLE_FILE" + prompt: "SSL Certificate File (if applicable)" + +install: + + version: "3" + silent: true + + tasks: + default: + cmds: + - task: assert_pre_req + - task: setup + + assert_pre_req: + cmds: + - | + SERVICE_EXIST=$(sudo systemctl status newrelic-infra.service | grep "Active" | wc -l) + if [ $SERVICE_EXIST -eq 0 ]; then + echo "The newrelic-infra agent service is NOT installed on the host, but is required to install this integration." >> /dev/stderr + exit 1 + fi + setup: + label: "Installing couchbase integration..." + cmds: + - | + sudo mkdir -p "/etc/newrelic-infra/integrations.d" + - | + sudo apt-get update -y + - | + sudo apt-get install nri-couchbase -y + - | + if [ -f /etc/newrelic-infra/integrations.d/couchbase-config.yml ]; then + sudo rm /etc/newrelic-infra/integrations.d/couchbase-config.yml; + fi + sudo touch /etc/newrelic-infra/integrations.d/couchbase-config.yml; + - | + if [ {{.NR_CLI_API_USE_SSL}} == false ]; then + sudo tee -a /etc/newrelic-infra/integrations.d/couchbase-config.yml > /dev/null <<"EOT" + integration_name: com.newrelic.couchbase + instances: + - name: couchbase + command: all_data + arguments: + hostname: {{.NR_CLI_API_HOSTNAME}} + port: {{.NR_CLI_API_PORT}} + query_port: {{.NR_CLI_API_QUERY_PORT}} + username: {{.NR_CLI_API_USERNAME}} + password: {{.NR_CLI_API_PASSWORD}} + use_ssl: {{.NR_CLI_API_USE_SSL}} + EOT + else + sudo tee -a /etc/newrelic-infra/integrations.d/couchbase-config.yml > /dev/null <<"EOT" + integration_name: com.newrelic.couchbase + instances: + - name: couchbase + command: all_data + arguments: + hostname: {{.NR_CLI_API_HOSTNAME}} + port: {{.NR_CLI_API_PORT}} + query_port: {{.NR_CLI_API_QUERY_PORT}} + username: {{.NR_CLI_API_USERNAME}} + password: {{.NR_CLI_API_PASSWORD}} + use_ssl: {{.NR_CLI_API_USE_SSL}} + ca_bundle_dir: {{.NR_CLI_API_CA_BUNDLE_DIR}} + ca_bundle_file: {{.NR_CLI_API_CA_BUNDLE_FILE}} + EOT + fi + + - sudo systemctl restart newrelic-infra.service diff --git a/test/definitions/ohi/linux/couchbase-debian.json b/test/definitions/ohi/linux/couchbase-debian.json new file mode 100644 index 000000000..b9eee0e09 --- /dev/null +++ b/test/definitions/ohi/linux/couchbase-debian.json @@ -0,0 +1,59 @@ +{ + "global_tags": { + "owning_team": "OpenSource", + "Environment": "development", + "Department": "Product", + "Product": "Virtuoso" + }, + + "resources": [{ + "id": "host1", + "display_name": "Debian10InfraCouchbaseInstallHost", + "provider": "aws", + "type": "ec2", + "size": "t3.small", + "ami_name": "SupportedImages debian-10-amd64-*", + "user_name": "admin" + }], + + "services": [{ + "id": "couchbase1", + "destinations": ["host1"], + "source_repository": "https://github.com/newrelic/open-install-library.git", + "deploy_script_path": "test/deploy/linux/couchbase/install/debian/roles", + "port": 80, + "params":{ + "create_env_var": true, + "initialize_cluster": true + } + }], + + "instrumentations": { + "resources": [ + { + "id": "nr_infra_couchbase", + "resource_ids": ["host1"], + "provider": "newrelic", + "source_repository": "https://github.com/newrelic/open-install-library.git", + "deploy_script_path": "test/deploy/linux/newrelic-cli/install-recipe/roles", + "params": { + "recipe_content_url": [ + "https://raw.githubusercontent.com/newrelic/open-install-library/main/recipes/newrelic/infrastructure/debian.yml", + "https://raw.githubusercontent.com/newrelic/open-install-library/main/recipes/newrelic/infrastructure/ohi/couchbase/debian.yml" + ] + } + }, + { + "id": "nr_infra_is_having_data", + "resource_ids": ["host1"], + "provider": "newrelic", + "source_repository": "https://github.com/newrelic/open-install-library.git", + "deploy_script_path": "test/deploy/assertions/recipe-is-valid/roles", + "params": { + "recipe_validation_nrql_url": "https://raw.githubusercontent.com/newrelic/open-install-library/main/recipes/newrelic/infrastructure/ohi/couchbase/debian.yml" + } + } + ] + } + } + diff --git a/test/deploy/linux/couchbase/install/debian/roles/configure/tasks/main.yml b/test/deploy/linux/couchbase/install/debian/roles/configure/tasks/main.yml new file mode 100644 index 000000000..27e9a6512 --- /dev/null +++ b/test/deploy/linux/couchbase/install/debian/roles/configure/tasks/main.yml @@ -0,0 +1,56 @@ +--- +- debug: + msg: Install Couchbase + +- name: Set default initialize_cluster (default not create) + set_fact: + initialize_cluster: "false" + when: initialize_cluster is undefined + +- name: Set default create_env_var (default not create) + set_fact: + create_env_var: "false" + when: create_env_var is undefined + +- name: Download the meta package + shell: curl -O https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-amd64.deb + +- name: Install the meta package + shell: dpkg -i ./couchbase-release-1.0-amd64.deb + become: true + +- name: Reload local package database + shell: apt-get update -y + become: true + +- name: Install latest release of couchbase-server-community + shell: apt-get install couchbase-server-community + become: true + +- name: Wait for couchbase + pause: + seconds: 20 + +- block: + - name: Initialize cluster + shell: /opt/couchbase/bin/couchbase-cli cluster-init --cluster 127.0.0.1:8091 --cluster-name Test --cluster-username newrelic --cluster-password Virtuoso4all! --cluster-ramsize 1300 --cluster-analytics-ramsize 1024 --services data + when: initialize_cluster|bool + +- block: + - name: Export NR_CLI_USERNAME + shell: "echo export NR_CLI_API_USERNAME=newrelic >> ~/.bashrc" + - name: Export NR_CLI_PASSWORD + shell: "echo export NR_CLI_API_PASSWORD=Virtuoso4all! >> ~/.bashrc" + - name: Export NR_CLI_API_PORT + shell: "echo export NR_CLI_API_PORT=8091 >> ~/.bashrc" + - name: Export NR_CLI_QUERY_PORT + shell: "echo export NR_CLI_API_QUERY_PORT=8093 >> ~/.bashrc" + - name: Export NR_CLI_HOSTNAME + shell: "echo export NR_CLI_API_HOSTNAME=localhost >> ~/.bashrc" + - name: Export USE_SSL + shell: "echo export NR_CLI_API_USE_SSL=false >> ~/.bashrc" + - name: Export CA_BUNDLE_DIR + shell: "echo export NR_CLI_API_CA_BUNDLE_DIR=notUsed >> ~/.bashrc" + - name: Export CA_BUNDLE_FILE + shell: "echo export NR_CLI_API_CA_BUNDLE_FILE=notUsed >> ~/.bashrc" + when: create_env_var|bool