Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 455e3f8

Browse files
authored
Add support for running CI with security (#263)
1 parent 2a4a4bb commit 455e3f8

File tree

10 files changed

+197
-42
lines changed

10 files changed

+197
-42
lines changed

.cypress/integration/ad/dashboard/ad_dashboard.spec.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ context('AD Dashboard', () => {
6868
cy.get('[data-test-subj=comboBoxToggleListButton]')
6969
.first()
7070
.click({ force: true });
71-
cy.get('.euiFilterSelectItem')
72-
.first()
73-
.click({ force: true });
71+
cy.get('.euiFilterSelectItem').first().click({ force: true });
7472
cy.get('.euiPageSideBar').click({ force: true });
7573

7674
cy.contains('feature-required-detector'); // first one in the list returned by multiple_detectors_response.json
@@ -89,9 +87,7 @@ context('AD Dashboard', () => {
8987
cy.get('[data-test-subj=comboBoxToggleListButton]')
9088
.eq(1)
9189
.click({ force: true });
92-
cy.get('.euiFilterSelectItem')
93-
.first()
94-
.click({ force: true });
90+
cy.get('.euiFilterSelectItem').first().click({ force: true });
9591
cy.get('.euiPageSideBar').click({ force: true });
9692

9793
cy.contains('stopped-detector'); // because stopped is the first item in the detector state dropdown

.cypress/integration/ad/detectorList/detector_list.spec.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ context('Detector list', () => {
8989
cy.mockGetDetectorOnAction('single_stopped_detector_response.json', () => {
9090
cy.visit(buildAdAppUrl(DETECTORS));
9191
});
92-
cy.get('.euiCheckbox__input')
93-
.last()
94-
.click({ force: true });
92+
cy.get('.euiCheckbox__input').last().click({ force: true });
9593
cy.get('[data-test-subj=listActionsButton]').click({ force: true });
9694
cy.get('[data-test-subj=startDetectors]').click({ force: true });
9795
cy.contains('The following detectors will begin initializing.');
@@ -110,9 +108,7 @@ context('Detector list', () => {
110108
cy.mockGetDetectorOnAction('single_running_detector_response.json', () => {
111109
cy.visit(buildAdAppUrl(DETECTORS));
112110
});
113-
cy.get('.euiCheckbox__input')
114-
.last()
115-
.click({ force: true });
111+
cy.get('.euiCheckbox__input').last().click({ force: true });
116112
cy.get('[data-test-subj=listActionsButton]').click({ force: true });
117113
cy.get('[data-test-subj=stopDetectors]').click({ force: true });
118114
cy.contains('The following detectors will be stopped.');
@@ -131,9 +127,7 @@ context('Detector list', () => {
131127
cy.mockGetDetectorOnAction('single_stopped_detector_response.json', () => {
132128
cy.visit(buildAdAppUrl(DETECTORS));
133129
});
134-
cy.get('.euiCheckbox__input')
135-
.last()
136-
.click({ force: true });
130+
cy.get('.euiCheckbox__input').last().click({ force: true });
137131
cy.get('[data-test-subj=listActionsButton]').click({ force: true });
138132
cy.get('[data-test-subj=deleteDetectors]').click({ force: true });
139133
cy.contains(
@@ -183,9 +177,7 @@ context('Detector list', () => {
183177
cy.get('[data-test-subj=comboBoxToggleListButton]')
184178
.first()
185179
.click({ force: true });
186-
cy.get('.euiFilterSelectItem')
187-
.first()
188-
.click({ force: true });
180+
cy.get('.euiFilterSelectItem').first().click({ force: true });
189181
cy.get('.euiPageSideBar').click({ force: true });
190182

191183
cy.contains('stopped-detector'); // because stopped is the first item in the detector state dropdown

.cypress/support/commands.ts

+30-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,29 @@ import {
2323
} from '../utils/constants';
2424
import { buildAdApiUrl } from '../utils/helpers';
2525

26-
Cypress.Commands.add('mockGetDetectorOnAction', function(
26+
Cypress.Commands.overwrite('visit', (orig, url, options) => {
27+
if (Cypress.env('SECURITY_ENABLED')) {
28+
let newOptions = options;
29+
if (options) {
30+
newOptions['auth'] = {
31+
username: 'admin',
32+
password: 'admin',
33+
};
34+
} else {
35+
newOptions = {
36+
auth: {
37+
username: 'admin',
38+
password: 'admin',
39+
},
40+
};
41+
}
42+
orig(url, newOptions);
43+
} else {
44+
orig(url, options);
45+
}
46+
});
47+
48+
Cypress.Commands.add('mockGetDetectorOnAction', function (
2749
fixtureFileName: string,
2850
funcMockedOn: VoidFunction
2951
) {
@@ -39,7 +61,7 @@ Cypress.Commands.add('mockGetDetectorOnAction', function(
3961
cy.wait('@getDetectors');
4062
});
4163

42-
Cypress.Commands.add('mockCreateDetectorOnAction', function(
64+
Cypress.Commands.add('mockCreateDetectorOnAction', function (
4365
fixtureFileName: string,
4466
funcMockedOn: VoidFunction
4567
) {
@@ -55,7 +77,7 @@ Cypress.Commands.add('mockCreateDetectorOnAction', function(
5577
cy.wait('@createDetector');
5678
});
5779

58-
Cypress.Commands.add('mockSearchIndexOnAction', function(
80+
Cypress.Commands.add('mockSearchIndexOnAction', function (
5981
fixtureFileName: string,
6082
funcMockedOn: VoidFunction
6183
) {
@@ -71,7 +93,7 @@ Cypress.Commands.add('mockSearchIndexOnAction', function(
7193
cy.wait('@getIndices');
7294
});
7395

74-
Cypress.Commands.add('mockSearchOnAction', function(
96+
Cypress.Commands.add('mockSearchOnAction', function (
7597
fixtureFileName: string,
7698
funcMockedOn: VoidFunction
7799
) {
@@ -85,7 +107,7 @@ Cypress.Commands.add('mockSearchOnAction', function(
85107
cy.wait('@searchES');
86108
});
87109

88-
Cypress.Commands.add('mockGetIndexMappingsOnAction', function(
110+
Cypress.Commands.add('mockGetIndexMappingsOnAction', function (
89111
fixtureFileName: string,
90112
funcMockedOn: VoidFunction
91113
) {
@@ -101,7 +123,7 @@ Cypress.Commands.add('mockGetIndexMappingsOnAction', function(
101123
cy.wait('@getMappings');
102124
});
103125

104-
Cypress.Commands.add('mockStartDetectorOnAction', function(
126+
Cypress.Commands.add('mockStartDetectorOnAction', function (
105127
fixtureFileName: string,
106128
detectorId: string,
107129
funcMockedOn: VoidFunction
@@ -118,7 +140,7 @@ Cypress.Commands.add('mockStartDetectorOnAction', function(
118140
cy.wait('@startDetector');
119141
});
120142

121-
Cypress.Commands.add('mockStopDetectorOnAction', function(
143+
Cypress.Commands.add('mockStopDetectorOnAction', function (
122144
fixtureFileName: string,
123145
detectorId: string,
124146
funcMockedOn: VoidFunction
@@ -135,7 +157,7 @@ Cypress.Commands.add('mockStopDetectorOnAction', function(
135157
cy.wait('@stopDetector');
136158
});
137159

138-
Cypress.Commands.add('mockDeleteDetectorOnAction', function(
160+
Cypress.Commands.add('mockDeleteDetectorOnAction', function (
139161
fixtureFileName: string,
140162
detectorId: string,
141163
funcMockedOn: VoidFunction
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3'
2+
services:
3+
odfe-node1:
4+
image: odfe-ad:test
5+
container_name: odfe-node1
6+
environment:
7+
- cluster.name=odfe-cluster
8+
- node.name=odfe-node1
9+
- discovery.seed_hosts=odfe-node1
10+
- cluster.initial_master_nodes=odfe-node1
11+
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
12+
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m' # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
13+
ulimits:
14+
memlock:
15+
soft: -1
16+
hard: -1
17+
nofile:
18+
soft: 65536 # maximum number of open files for the Elasticsearch user, set to at least 65536 on modern systems
19+
hard: 65536
20+
volumes:
21+
- odfe-data1:/usr/share/elasticsearch/data
22+
ports:
23+
- 9200:9200
24+
- 9600:9600 # required for Performance Analyzer
25+
expose:
26+
- '9200'
27+
networks:
28+
- odfe-net
29+
kibana:
30+
image: odfe-ad-kibana:test
31+
container_name: odfe-kibana
32+
ports:
33+
- 5601:5601
34+
expose:
35+
- '5601'
36+
environment:
37+
ELASTICSEARCH_URL: https://odfe-node1:9200
38+
ELASTICSEARCH_HOSTS: https://odfe-node1:9200
39+
networks:
40+
- odfe-net
41+
42+
volumes:
43+
odfe-data1:
44+
45+
networks:
46+
odfe-net:

.github/workflows/CD.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ on:
33
push:
44
tags:
55
- v*
6-
6+
env:
7+
KIBANA_VERSION: 7.8.0
78
jobs:
89
Build-and-upload:
910
name: Build and upload artifacts
@@ -20,7 +21,7 @@ jobs:
2021
uses: actions/checkout@v2
2122
with:
2223
repository: opendistro-for-elasticsearch/kibana-oss
23-
ref: 7.8.0
24+
ref: ${{ env.KIBANA_VERSION }}
2425
token: ${{ secrets.KIBANA_OSS_ACCESS }}
2526
path: kibana
2627

.github/workflows/e2e-tests-workflow.yml

+97-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,99 @@ name: E2E tests workflow
22
on:
33
push:
44
branches:
5-
- master
5+
- securityCI
6+
env:
7+
KIBANA_VERSION: 7.8.0
8+
ODFE_VERSION: 1.9.0
69
jobs:
7-
tests:
8-
name: Run e2e tests
10+
test-with-security:
11+
name: Run e2e tests with security
12+
strategy:
13+
matrix:
14+
os: [ubuntu-16.04] # use ubuntu-16.04 as required by cypress: https://github.com/marketplace/actions/cypress-io#important
15+
java: [14]
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- name: Checkout Kibana
19+
uses: actions/checkout@v2
20+
with:
21+
repository: opendistro-for-elasticsearch/kibana-oss
22+
ref: ${{ env.KIBANA_VERSION }}
23+
token: ${{ secrets.KIBANA_OSS_ACCESS }}
24+
path: kibana
25+
26+
- name: Get node and yarn versions
27+
id: versions_step
28+
run: |
29+
echo "::set-output name=node_version::$(node -p "(require('./kibana/package.json').engines.node).match(/[.0-9]+/)[0]")"
30+
echo "::set-output name=yarn_version::$(node -p "(require('./kibana/package.json').engines.yarn).match(/[.0-9]+/)[0]")"
31+
32+
- name: Setup node
33+
uses: actions/setup-node@v1
34+
with:
35+
node-version: ${{ steps.versions_step.outputs.node_version }}
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
- name: Install correct yarn version for Kibana
39+
run: |
40+
npm uninstall -g yarn
41+
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}"
42+
npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }}
43+
44+
- name: Checkout Anomaly Detection Kibana plugin
45+
uses: actions/checkout@v2
46+
with:
47+
path: kibana/plugins/anomaly-detection-kibana-plugin
48+
49+
- name: Bootstrap the plugin
50+
run: |
51+
cd kibana/plugins/anomaly-detection-kibana-plugin
52+
yarn kbn bootstrap
53+
54+
- name: Build the artifact
55+
run: |
56+
cd kibana/plugins/anomaly-detection-kibana-plugin
57+
yarn build
58+
59+
- name: Create tagged images for ES and Kibana
60+
run: |
61+
cd kibana/plugins/anomaly-detection-kibana-plugin
62+
odfe_version=$ODFE_VERSION
63+
plugin_version=$(node -pe "require('./package.json').version")
64+
echo odfe version: $odfe_version
65+
echo plugin version: $plugin_version
66+
if docker pull opendistroforelasticsearch/opendistroforelasticsearch:$odfe_version
67+
then
68+
## Populate the Dockerfiles
69+
echo "FROM opendistroforelasticsearch/opendistroforelasticsearch:$odfe_version" >> Dockerfile-AD
70+
echo "FROM opendistroforelasticsearch/opendistroforelasticsearch-kibana:$odfe_version" >> Dockerfile-AD-Kibana
71+
echo "COPY build/opendistro-anomaly-detection-kibana-$plugin_version.zip ." >> Dockerfile-AD-Kibana
72+
## Uninstall existing AD artifact and install new one
73+
echo "RUN if [ -d /usr/share/kibana/plugins/opendistro-anomaly-detection-kibana ]; then /usr/share/kibana/bin/kibana-plugin remove opendistro-anomaly-detection-kibana; fi" >> Dockerfile-AD-Kibana
74+
echo "RUN bin/kibana-plugin install file:///usr/share/kibana/opendistro-anomaly-detection-kibana-$plugin_version.zip;" >> Dockerfile-AD-Kibana
75+
76+
## Create the tagged images
77+
docker build -f ./Dockerfile-AD -t odfe-ad:test .
78+
docker build -f ./Dockerfile-AD-Kibana -t odfe-ad-kibana:test .
79+
fi
80+
docker images
81+
82+
- name: Start ES and Kibana
83+
run: |
84+
cd kibana/plugins/anomaly-detection-kibana-plugin/.github/configurations
85+
## Need to increase max map count for running the docker container
86+
sudo sysctl -w vm.max_map_count=262144
87+
docker-compose up -d
88+
sleep 180
89+
90+
- name: Run e2e tests
91+
uses: cypress-io/github-action@v1
92+
with:
93+
working-directory: kibana/plugins/anomaly-detection-kibana-plugin
94+
command: yarn cy:run --env SECURITY_ENABLED=true
95+
96+
test-without-security:
97+
name: Run e2e tests without security
998
strategy:
1099
matrix:
11100
os: [ubuntu-16.04] # use ubuntu-16.04 as required by cypress: https://github.com/marketplace/actions/cypress-io#important
@@ -14,11 +103,11 @@ jobs:
14103
steps:
15104
- name: Pull and Run Docker
16105
run: |
17-
version=1.9.0
18-
echo $version
19-
if docker pull opendistroforelasticsearch/opendistroforelasticsearch:$version
106+
odfe_version=$ODFE_VERSION
107+
echo odfe version: $odfe_version
108+
if docker pull opendistroforelasticsearch/opendistroforelasticsearch:$odfe_version
20109
then
21-
echo "FROM opendistroforelasticsearch/opendistroforelasticsearch:$version" >> Dockerfile
110+
echo "FROM opendistroforelasticsearch/opendistroforelasticsearch:$odfe_version" >> Dockerfile
22111
## The ESRestTest Client uses http by default.
23112
## Need to disable the security plugin to call the rest api over http.
24113
echo "RUN if [ -d /usr/share/elasticsearch/plugins/opendistro_security ]; then /usr/share/elasticsearch/bin/elasticsearch-plugin remove opendistro_security; fi" >> Dockerfile
@@ -29,12 +118,11 @@ jobs:
29118
docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" odfe-ad:test
30119
sleep 90
31120
curl -XGET http://localhost:9200/_cat/plugins
32-
33121
- name: Checkout Kibana
34122
uses: actions/checkout@v2
35123
with:
36124
repository: opendistro-for-elasticsearch/kibana-oss
37-
ref: 7.8.0
125+
ref: ${{ env.KIBANA_VERSION }}
38126
token: ${{ secrets.KIBANA_OSS_ACCESS }}
39127
path: kibana
40128
- name: Get node and yarn versions

.github/workflows/unit-tests-workflow.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ on:
33
push:
44
branches:
55
- master
6-
6+
env:
7+
KIBANA_VERSION: 7.8.0
78
jobs:
89
tests:
910
name: Run unit tests
@@ -16,7 +17,7 @@ jobs:
1617
uses: actions/checkout@v2
1718
with:
1819
repository: opendistro-for-elasticsearch/kibana-oss
19-
ref: 7.8.0
20+
ref: ${{ env.KIBANA_VERSION }}
2021
token: ${{ secrets.KIBANA_OSS_ACCESS }}
2122
path: kibana
2223
- name: Get node and yarn versions

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ Example output: `./build/opendistro-anomaly-detection-kibana-1.9.0.0.zip`
6767

6868
Start Kibana, wait for it to be available on `localhost:5601`, and runs end-to-end tests.
6969

70+
- `yarn cy:run`
71+
72+
Runs end-to-end tests on a currently running Kibana server. Defaults to run the tests on `localhost:5601`, although you can change this to run on any
73+
Kibana server with the command `yarn cy:run --config baseUrl=<your-custom-URL>`
74+
7075
## Contributing to Open Distro for Elasticsearch Anomaly detection Kibana
7176

7277
We welcome you to get involved in development, documentation, testing the anomaly detection plugin. See our [CONTRIBUTING.md](./CONTRIBUTING.md) and join in.

0 commit comments

Comments
 (0)