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

Support 1 Kibana and 1 Elasticsearch URL as input params #9760

Merged
merged 14 commits into from
Apr 18, 2018

Conversation

LeeDr
Copy link

@LeeDr LeeDr commented Jan 6, 2017

This will allow running Kibana tests against and Elasticsearch and Kibana instance like;

Usage:
TEST_ES_URL=<protocol>://<username>:<password>@<host>:<port>  TEST_KIBANA_URL=<protocol>://<username>:<password>@<host>:<port> npm run test:ui:runner


Example:
TEST_ES_URL=https://elastic:changeme@localhost:9201  TEST_KIBANA_URL=https://elastic:changeme@localhost:9201 npm run test:ui:runner

And also still supports individual parameters like;

TEST_ES_PORT=9220 npm run test:ui:runner

@jbudz
Copy link
Member

jbudz commented Mar 30, 2018

@LeeDr is this still WIP? Can we close it out?

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Mar 30, 2018

Oops. This slipped out of my radar. Yes, this would still be good to get in as we are driving to run kibana tests on Cloud. I'll rebase and get this going again.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Apr 2, 2018

jenkins test this

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@LeeDr LeeDr requested a review from jbudz April 2, 2018 19:21
@LeeDr LeeDr changed the title [WIP] Support 1 Kibana and 1 Elasticsearch URL as input params Support 1 Kibana and 1 Elasticsearch URL as input params Apr 2, 2018
@LeeDr LeeDr added the review label Apr 2, 2018
@LeeDr LeeDr requested a review from rhoboat April 2, 2018 19:23
@LeeDr LeeDr mentioned this pull request Apr 3, 2018
8 tasks
port: testEsPort,
auth: testEsUsername + ':' + testEsPassword,
username: testEsUsername,
password: testEsPassword,
Copy link

@rhoboat rhoboat Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk in doing:

getUrlParts() {
  let protocol;
  let hostname;
  let port;
  let auth;
  let username;
  let password;

  if (process.env.TEST_ES_URL) {
    // Allow setting one complete TEST_ES_URL for Es like
    // https://elastic:changeme@myCloudInstance:9200
    const testEsUrl = url.parse(process.env.TEST_ES_URL);
    // have to remove the ":" off protocol
    protocol = testEsUrl.protocol.slice(0, -1);
    hostname = testEsUrl.hostname;
    port = parseInt(testEsUrl.port, 10);
    username = testEsUrl.username;
    password = testEsUrl.password;
  } else {
    // Allow setting any individual component(s) of the URL,
    // or use default values (username and password from shield.js)
    protocol = process.env.TEST_ES_PROTOCOL || 'http';
    hostname = process.env.TEST_ES_HOSTNAME || 'localhost';
    port = parseInt(process.env.TEST_ES_PORT, 10) || 9220;
    username = process.env.TEST_ES_USERNAME || admin.username;
    password = process.env.TEST_ES_PASSWORD || admin.password;
  }
  console.log(protocol);

  return {
    protocol,
    hostname,
    port,
    auth: `${username}:${password}`,
    username,
    password,
  };
}

(edited: removed too much first time)

port: testKibanaPort,
username: testKibanaUsername,
password: testKibanaPassword,
auth: `${testKibanaUsername}:${testKibanaPassword}`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { kibanaUser } from './shield';
import url from 'url';

let protocol;
let hostname;
let port;
let username;
let password;
let auth;

// Allow setting one complete TEST_KIBANA_URL for Kibana like
// https://elastic:changeme@myCloudInstance:5601
if (process.env.TEST_KIBANA_URL) {
  const testKibanaUrl = url.parse(process.env.TEST_KIBANA_URL);
  // have to remove the ":" off protocol
  protocol = testKibanaUrl.protocol.slice(0, -1);
  hostname = testKibanaUrl.hostname;
  port = parseInt(testKibanaUrl.port, 10);
  username = testKibanaUrl.username;
  password = testKibanaUrl.password;
} else {
  // Allow setting any individual component(s) of the URL,
  // or use default values (username and password from shield.js)
  protocol = process.env.TEST_KIBANA_PROTOCOL || 'http';
  hostname = process.env.TEST_KIBANA_HOSTNAME || 'localhost';
  port = parseInt(process.env.TEST_KIBANA_PORT, 10) || 5620;
  username = process.env.TEST_KIBANA_USERNAME || kibanaUser.username;
  password = process.env.TEST_KIBANA_PASSWORD || kibanaUser.password;
}

export const kibanaTestServerUrlParts = {
  protocol,
  hostname,
  port,
  auth: `${username}:${password}`,
  username,
  password,
};

maybe make things more consistent with the ES file, too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I made that change and it is cleaner.

testEsUsername = process.env.TEST_ES_USERNAME || admin.username;
testEsPassword = process.env.TEST_ES_PASSWORD || admin.password;
}
console.log(testEsProtocol);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these console.logs

Copy link

@rhoboat rhoboat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with some minor suggestions.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

let password;

// Allow setting one complete TEST_ES_URL for Es like https://elastic:changeme@myCloudInstance:9200
if (process.env.TEST_ES_URL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just return an object here if TEST_ES_URL is defined? Then we can get rid of all the variables and last return.

Copy link
Contributor

@tylersmalley tylersmalley Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUrlParts() {
  // allow setting one complete TEST_ES_URL for ES like https://elastic:changeme@example.com:9200
  if (process.env.TEST_ES_URL) {
    const testEsUrl = url.parse(process.env.TEST_ES_URL);

    return {
      ...testEsUrl,
      port: parseInt(testEsUrl.port, 10),
      auth: `${testEsUrl.username}:${testEsUrl.password}`,
      testEsUrl.protocol.slice(0, -1),
    };
  }
  
  const username = process.env.TEST_ES_USERNAME || admin.username;
  const password = process.env.TEST_ES_PASSWORD || admin.password;
  return {
    protocol: process.env.TEST_ES_PROTOCOL || 'http',
    hostname: process.env.TEST_ES_HOSTNAME || 'localhost',
    port: parseInt(process.env.TEST_ES_PORT, 10) || 9220,
    auth: `${username}:${password}`,
    username,
    password, 
  };
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds pretty good. I'll try it that way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I can do that for both the kibana and elasticsearch files;

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Kibana:

import { kibanaUser } from './shield';
import url from 'url';

function getUrlParts() {
  // allow setting one complete TEST_KIBANA_URL for ES like https://elastic:changeme@example.com:9200
  if (process.env.TEST_KIBANA_URL) {
    const testKibanaUrl = url.parse(process.env.TEST_KIBANA_URL);

    return {
      ...testKibanaUrl,
      port: parseInt(testKibanaUrl.port, 10),
      auth: `${testKibanaUrl.username}:${testKibanaUrl.password}`,
      protocol: testKibanaUrl.protocol.slice(0, -1),
    };
  }

  const username = process.env.TEST_KIBANA_USERNAME || kibanaUser.username;
  const password = process.env.TEST_KIBANA_PASSWORD || kibanaUser.password;
  return {
    protocol: process.env.TEST_KIBANA_PROTOCOL || 'http',
    hostname: process.env.TEST_KIBANA_HOSTNAME || 'localhost',
    port: parseInt(process.env.TEST_KIBANA_PORT, 10) || 9220,
    auth: `${username}:${password}`,
    username,
    password,
  };
}

export const kibanaTestServerUrlParts = getUrlParts();

} else {
// Allow setting any individual component(s) of the URL,
// or use default values (username and password from shield.js)
protocol = process.env.TEST_ES_PROTOCOL || 'http';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need/use the other TEST_ES_* environment variables? Can we get rid of them if we are now providing the full URL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to break backward compatibility if anybody was just overriding a port or something like that. I don't know if anybody is using any of them, but they were documented.

let password;

// Allow setting one complete TEST_ES_URL for Es like https://elastic:changeme@myCloudInstance:9200
if (process.env.TEST_ES_URL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Kibana:

import { kibanaUser } from './shield';
import url from 'url';

function getUrlParts() {
  // allow setting one complete TEST_KIBANA_URL for ES like https://elastic:changeme@example.com:9200
  if (process.env.TEST_KIBANA_URL) {
    const testKibanaUrl = url.parse(process.env.TEST_KIBANA_URL);

    return {
      ...testKibanaUrl,
      port: parseInt(testKibanaUrl.port, 10),
      auth: `${testKibanaUrl.username}:${testKibanaUrl.password}`,
      protocol: testKibanaUrl.protocol.slice(0, -1),
    };
  }

  const username = process.env.TEST_KIBANA_USERNAME || kibanaUser.username;
  const password = process.env.TEST_KIBANA_PASSWORD || kibanaUser.password;
  return {
    protocol: process.env.TEST_KIBANA_PROTOCOL || 'http',
    hostname: process.env.TEST_KIBANA_HOSTNAME || 'localhost',
    port: parseInt(process.env.TEST_KIBANA_PORT, 10) || 9220,
    auth: `${username}:${password}`,
    username,
    password,
  };
}

export const kibanaTestServerUrlParts = getUrlParts();

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Apr 12, 2018

jenkins test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Apr 12, 2018

I've never seen this failure before where it logged page crashed and tab crashed;

20:04:18        │ debg  navigate to: http://localhost:5620/app/kibana#/discover
20:04:18        │ debg  --- tryForTime failure: [POST http://localhost:9515/session/fc612b86f34d294859f63706fa2c6386/url / {"url":"http://localhost:5620/app/kibana?_t=1523563458134#/discover"}] unknown error: session deleted because of page crash
20:04:18        │       from unknown error: cannot determine loading status
20:04:18        │       from tab crashed
20:04:18        │         (Session info: chrome=65.0.3325.162)
20:04:18        │         (Driver info: chromedriver=2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 4.4.0-1044-aws x86_64)

@LeeDr
Copy link
Author

LeeDr commented Apr 12, 2018

jenkins test this

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@LeeDr
Copy link
Author

LeeDr commented Apr 12, 2018

@tylersmalley would you please check the latest commits and see if you're good with it?

@tylersmalley
Copy link
Contributor

@LeeDr did you want to update the ES part, or keep as is?

@LeeDr
Copy link
Author

LeeDr commented Apr 13, 2018

@tylersmalley oops, yes, testing that change now...

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Apr 13, 2018

jenkins test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@LeeDr
Copy link
Author

LeeDr commented Apr 13, 2018

Unrelated timelion test failure which needs some fix;

18:02:36            │ debg  in findAllByCssSelector: .suggestions .suggestion

18:02:37          └- ✖ fail: "timelion app expression typeahead dynamic suggestions for argument values .es() should show field suggestions for split argument when index pattern set"

18:02:37          │        [POST http://localhost:9515/session/39e692cd16e72c40c9f84f0aa2516bca/element/0.3484768890432888-38/click] stale element reference: element is not attached to the page document

@LeeDr
Copy link
Author

LeeDr commented Apr 13, 2018

jenkins test this

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@LeeDr
Copy link
Author

LeeDr commented Apr 13, 2018

@tylersmalley back to you. I made es_test_config.js similar to kibana_test_server_url_parts.js

@LeeDr LeeDr merged commit 842ed48 into elastic:master Apr 18, 2018
LeeDr pushed a commit to LeeDr/kibana that referenced this pull request Apr 19, 2018
* Support 1 Kibana and 1 Elasticsearch URL as input params

* Revert a previous change to test char substitution

* Allow setting TEST_KIBANA_URL and TEST_ES_URL for Cloud testing

* cleanup comment

* Update docs

* Refactor after PR review

* Changes from review

* fix default Kibana port to 5620

* Change es_test_config.js similar to kibana_test_server_url_parts.js
LeeDr pushed a commit that referenced this pull request May 8, 2018
)

* Support 1 Kibana and 1 Elasticsearch URL as input params

* Revert a previous change to test char substitution

* Allow setting TEST_KIBANA_URL and TEST_ES_URL for Cloud testing

* cleanup comment

* Update docs

* Refactor after PR review

* Changes from review

* fix default Kibana port to 5620

* Change es_test_config.js similar to kibana_test_server_url_parts.js
@LeeDr LeeDr deleted the enableCloudTesting branch August 20, 2020 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants