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 infra support and helper function to create real datasource #1146

Merged
merged 27 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
be94338
Add infra support and helper function to create real datasource
derek-ho Mar 14, 2024
1b315ac
Remove logs from previous change
derek-ho Mar 14, 2024
7146b08
Add test that uses the helper function to verify functionality
derek-ho Mar 15, 2024
8364c60
Change to request and add it to appropriate workflows
derek-ho Mar 22, 2024
5319fe8
Add basic auth remote cluster
derek-ho Apr 3, 2024
f7d2337
Call function
derek-ho Apr 3, 2024
47c4784
Move action
derek-ho Apr 18, 2024
190a460
Update action and usage in docs
derek-ho Apr 19, 2024
42dd612
Checkout before access
derek-ho Apr 19, 2024
b5bc25a
Add relative path
derek-ho Apr 19, 2024
1037a22
Fix spelling
derek-ho Apr 19, 2024
ccf3955
Merge branch 'main' of github.com:opensearch-project/opensearch-dashb…
derek-ho Apr 19, 2024
3521a62
Remove -d
derek-ho Apr 19, 2024
26f4063
Move port logic
derek-ho Apr 19, 2024
bd6b99c
Cat log
derek-ho Apr 19, 2024
10ed3c2
Allow modification
derek-ho Apr 19, 2024
5929aab
Duplicate download
derek-ho Apr 19, 2024
8ef0669
Change directory
derek-ho Apr 19, 2024
05f710d
Change name
derek-ho Apr 19, 2024
adf18e4
Remove extra chmod
derek-ho Apr 19, 2024
466639d
Within test directory
derek-ho Apr 19, 2024
6394859
Fix
derek-ho Apr 19, 2024
ca96d3a
Fix for windows, add helper function, show usage
derek-ho Apr 19, 2024
5c2e239
Remove pwd
derek-ho Apr 19, 2024
5263a92
Move to temp dire
derek-ho Apr 19, 2024
46d3442
Address PR feedback and try to spin up an instance with security
derek-ho Apr 22, 2024
d0839fa
Small action change and documentation add
derek-ho Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions .github/actions/start-opensearch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: 'Launch OpenSearch'
description: 'Downloads OpenSearch and runs it'

inputs:
opensearch-version:
description: 'The version of OpenSearch that should be used, e.g "3.0.0"'
required: true

plugins:
description: 'A comma separated list of plugins to install. Leave empty to not install any. Each entry should be a full path prefixed with `file: `, for example: `file:$(pwd)/my-plugin.zip`'
required: false

security-enabled:
description: 'Whether security is enabled'
required: true

admin-password:
description: 'The admin password uses for the cluster'
required: false

security_config_file:
description: 'Path to a security config file to replace the default. Leave empty if security is not enabled or using the default config'
required: false

port:
description: 'Port to run OpenSearch. Leave empty to use the default config (9200)'
required: false
default: '9200'

runs:
using: "composite"
steps:

# Configure longpath names if on Windows
- name: Enable Longpaths if on Windows
if: ${{ runner.os == 'Windows' }}
run: git config --system core.longpaths true
shell: pwsh

- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11

- name: Change directory
run: |
mkdir test
shell: bash

# Download OpenSearch
- name: Download OpenSearch for Windows
uses: peternied/download-file@v2
if: ${{ runner.os == 'Windows' }}
with:
url: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ inputs.opensearch-version }}/latest/windows/x64/zip/dist/opensearch/opensearch-${{ inputs.opensearch-version }}-windows-x64.zip


- name: Download OpenSearch for Linux
uses: peternied/download-file@v2
if: ${{ runner.os == 'Linux' }}
with:
url: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ inputs.opensearch-version }}/latest/linux/x64/tar/dist/opensearch/opensearch-${{ inputs.opensearch-version }}-linux-x64.tar.gz

# Extract downloaded zip
- name: Extract downloaded tar
if: ${{ runner.os == 'Linux' }}
run: |
tar -xzf opensearch-*.tar.gz -C test && mv test/opensearch-${{ inputs.opensearch-version }} test/opensearch-${{inputs.opensearch-version}}-SNAPSHOT${{ inputs.port }}
rm -f opensearch-*.tar.gz
shell: bash

- name: Extract downloaded zip
if: ${{ runner.os == 'Windows' }}
run: |
Expand-Archive -Path "opensearch-${{ inputs.opensearch-version }}-windows-x64.zip.1" -DestinationPath "temp"
Move-Item -Path "temp/*" -Destination "test/opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}"
Remove-Item -Path "temp" -Recurse
Remove-Item -Path "opensearch-${{ inputs.opensearch-version }}-windows-x64.zip.1"
shell: pwsh

# Setup security if it's enabled
- name: Setup security demo configuration
if: ${{ runner.os == 'Linux' && inputs.security-enabled == 'true' }}
run: |
echo "running linux security demo configuration setup"
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=${{ inputs.admin-password }}
chmod +x ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh
opensearch_version="${{ inputs.opensearch-version }}"
opensearch_major_version=$(echo "$opensearch_version" | awk -F'.' '{print $1}')
opensearch_minor_version=$(echo "$opensearch_version" | awk -F'.' '{print $2}')
if [ "$opensearch_major_version" -lt 2 ] || ([ "$opensearch_major_version" -eq 2 ] && [ "$opensearch_minor_version" -lt 12 ]); then
echo "Running the command without -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh"
else
echo "Running the command with -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh -t"
fi
echo "plugins.security.unsupported.restapi.allow_securityconfig_modification: true" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
working-directory: test

- name: Setup security demo configuration for Windows
if: ${{ runner.os == 'Windows' && inputs.security-enabled == 'true' }}
run: |
echo "running windows security demo configuration setup"
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=${{ inputs.admin-password }}
chmod +x ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat
opensearch_version="${{ inputs.opensearch-version }}"
opensearch_major_version=$(echo "$opensearch_version" | cut -d'.' -f1)
opensearch_minor_version=$(echo "$opensearch_version" | cut -d'.' -f2)
if [ "$opensearch_major_version" -lt 2 ] || ([ "$opensearch_major_version" -eq 2 ] && [ "$opensearch_minor_version" -lt 12 ]); then
echo "Running the command without -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat -y -i -s"
else
echo "Running the command with -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat -t -y -i -s"
fi
echo "plugins.security.unsupported.restapi.allow_securityconfig_modification: true" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
working-directory: test

# Disable security if it's disabled
- name: Disable security
if: ${{ inputs.security-enabled == 'false' }}
run: |
echo "Remove OpenSearch Security"
echo "plugins.security.disabled: true" >> ./opensearch-${{inputs.opensearch-version}}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
working-directory: test

- name: Use more space
run: |
echo '' >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
echo "cluster.routing.allocation.disk.threshold_enabled: false" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
echo "http.port: ${{ inputs.port }}" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
working-directory: test

# Run OpenSearch
- name: Run OpenSearch with plugin on Linux
if: ${{ runner.os == 'Linux'}}
run: /bin/bash -c "./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/bin/opensearch &"
shell: bash
working-directory: test

- name: Run OpenSearch with plugin on Windows
if: ${{ runner.os == 'Windows'}}
run: start .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}\bin\opensearch.bat
shell: pwsh
working-directory: test

# Give the OpenSearch process some time to boot up before sending any requires, might need to increase the default time!
- name: Sleep while OpenSearch starts
uses: peternied/action-sleep@v1
with:
seconds: 30

# Verify that the server is operational
- name: Check OpenSearch Running on Linux
if: ${{ runner.os != 'Windows'}}
run: |
if [ "${{ inputs.security-enabled }}" == "true" ]; then
curl https://localhost:${{ inputs.port || 9200 }}/_cat/plugins -u 'admin:${{ inputs.admin-password }}' -k -v --fail-with-body
else
curl http://localhost:${{ inputs.port || 9200 }}/_cat/plugins -v
fi
shell: bash
working-directory: test

- name: Check OpenSearch Running on Windows
if: ${{ runner.os == 'Windows'}}
run: |
if ("${{ inputs.security-enabled }}" -eq "true") {
$credentialBytes = [Text.Encoding]::ASCII.GetBytes("admin:${{ inputs.admin-password }}")
$encodedCredentials = [Convert]::ToBase64String($credentialBytes)
$baseCredentials = "Basic $encodedCredentials"
$Headers = @{ Authorization = $baseCredentials }
$url = 'https://localhost:${{ inputs.port || 9200 }}/_cat/plugins'
} else {
$Headers = @{ }
$url = 'http://localhost:${{ inputs.port || 9200 }}/_cat/plugins'
}
Invoke-WebRequest -SkipCertificateCheck -Uri $url -Headers $Headers;
shell: pwsh
working-directory: test

- if: always()
run: cat ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/logs/opensearch.log
shell: bash
working-directory: test

- if: always()
run: cat ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
working-directory: test
7 changes: 7 additions & 0 deletions .github/workflows/release-e2e-workflow-template-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
# 2.12 onwards security demo configuration require a custom admin password
OPENSEARCH_INITIAL_ADMIN_PASSWORD: 'myStrongPassword123!'
steps:
- name: Checkout Branch
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -69,6 +71,11 @@ jobs:
fi
netstat -anP tcp | grep LISTEN | grep 9200 || netstat -ntlp | grep 9200
shell: bash
- uses: ./.github/actions/start-opensearch
with:
opensearch-version: ${{ env.VERSION }}
security-enabled: false
port: 9201
- name: Get and run OpenSearch-Dashboards
run: |
curl -SLO https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/${{ env.VERSION }}/latest/${{ env.PLATFORM }}/x64/zip/dist/opensearch-dashboards/opensearch-dashboards-${{ env.VERSION }}-${{ env.PLATFORM }}-x64.zip
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/release-e2e-workflow-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
# 2.12 onwards security demo configuration require a custom admin password
OPENSEARCH_INITIAL_ADMIN_PASSWORD: 'myStrongPassword123!'
steps:
- name: Checkout Branch
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v1
with:
Expand Down Expand Up @@ -66,6 +68,11 @@ jobs:
timeout 900 bash -c 'while [[ "$(curl -o /dev/null -w ''%{http_code}'' -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} -k https://localhost:9200)" != "200" ]]; do sleep 5; done'
curl https://localhost:9200 -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} --insecure
fi
- uses: ./.github/actions/start-opensearch
with:
opensearch-version: ${{ env.VERSION }}
security-enabled: false
port: 9201
- name: Get OpenSearch-Dashboards
run: |
wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/${{ env.VERSION }}/latest/linux/x64/tar/dist/opensearch-dashboards/opensearch-dashboards-${{ env.VERSION }}-linux-x64.tar.gz
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release-signoff-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
cd opensearch-${{ env.VERSION }}/
./opensearch-tar-install.sh &
timeout 900 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} -k https://localhost:9200)" != "200" ]]; do sleep 5; done'
- uses: ./.github/actions/start-opensearch
with:
opensearch-version: ${{ env.VERSION }}
security-enabled: false
port: 9201
- name: Get OpenSearch-Dashboards
run: |
wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/${{ env.VERSION }}/latest/linux/x64/tar/dist/opensearch-dashboards/opensearch-dashboards-${{ env.VERSION }}-linux-x64.tar.gz
Expand Down
21 changes: 21 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ Tests for plugins that are not a part of the [OpenSearch Dashboards](https://git
/<YOUR_PLUGIN_NAME>
```

### Tests for Multiple Datasources
derek-ho marked this conversation as resolved.
Show resolved Hide resolved

Tests surrounding the multiple datasources feature can use the start-opensearch action that lives in this repo.

Example usage:
```
- uses: ./.github/actions/start-opensearch
with:
opensearch-version: 3.0.0
security-enabled: false
port: 9201
```
This will spin up an OpenSearch backend with version 3.0.0 on port 9201 within the same github runner. This OpenSearch can then be added as an datasource.

The DataSourceManagement Plugin exposes a helper function to create a helper function on this port:
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
```
const id = cy.createDataSourceNoAuth();

# Add tests that make calls to resp.body.id
```

### Experimental Features

When writing tests for experimental features, please follow these steps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ const miscUtils = new MiscUtils(cy);
const username = Cypress.env('username');
const password = Cypress.env('password');

export const CreateDataSourceBasicAuth = () => {
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
miscUtils.visitPage(
'app/management/opensearch-dashboards/dataSources/create'
);

cy.get('[data-test-subj="createDataSourceButton"]').should('be.disabled');
cy.get('[name="dataSourceTitle"]').type('9201');
cy.get('[name="endpoint"]').type('https://localhost:9202');
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
cy.get('[data-test-subj="createDataSourceFormAuthTypeSelect"]').select(
'username_password'
);
cy.get('[data-test-subj="createDataSourceFormUsernameField"]').type('admin');
cy.get('[data-test-subj="createDataSourceFormPasswordField"]').type('admin');
cy.get('[data-test-subj="createDataSourceButton"]').should('be.enabled');
cy.get('[name="dataSourceDescription"]').type(
'cypress test basic auth data source'
);
cy.get('[data-test-subj="createDataSourceButton"]').click();
cy.location('pathname', { timeout: 6000 }).should(
'include',
'app/management/opensearch-dashboards/dataSources'
);
};
derek-ho marked this conversation as resolved.
Show resolved Hide resolved

// TODO: create datasource with basic auth and sigv4

if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
describe('Create datasources', () => {
before(() => {
Expand Down Expand Up @@ -385,6 +411,10 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
'app/management/opensearch-dashboards/dataSources'
);
});

it('creates a datasources to a real opensearch instance', () => {
cy.createDataSourceNoAuth();
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ Cypress.Commands.add('deleteAllDataSources', () => {
);
});

Cypress.Commands.add('createDataSourceNoAuth', () => {
cy.request({
method: 'POST',
url: `${Cypress.config('baseUrl')}/api/saved_objects/data-source`,
headers: {
'osd-xsrf': true,
},
body: {
attributes: {
title: `9201`,
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
endpoint: `http://localhost:9201`,
derek-ho marked this conversation as resolved.
Show resolved Hide resolved
auth: {
type: 'no_auth',
},
},
},
}).then((resp) => {
if (resp && resp.body && resp.body.id) {
return resp.body.id;
}
});
});

Cypress.Commands.add('createDataSource', (dataSourceJSON) => {
cy.request({
method: 'POST',
Expand Down
Loading