Skip to content

Commit

Permalink
Merge branch 'main' into 1479
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarrrr authored Dec 23, 2022
2 parents 7dd01d6 + 5116f16 commit 63789ed
Show file tree
Hide file tree
Showing 16 changed files with 377 additions and 620 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/add_untriaged_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Apply 'untriaged' label during issue lifecycle

on:
issues:
types: [opened, reopened, transferred]

jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['untriaged']
})
1 change: 1 addition & 0 deletions .github/workflows/changelog_verifier.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "Changelog Verifier"
on:
pull_request:
branches: [ '**', '!feature/**' ]
types: [opened, edited, review_requested, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Update `leaflet-vega` and fix its usage ([#3005](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3005))
- [Table Visualization][BUG] Fix Url content display issue in table ([#2918](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2918))
- Fixes misleading embaddable plugin error message ([#3043](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3043))
- [MD] Update dummy url in tests to follow lychee url allowlist ([#3099](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3099))

### 🚞 Infrastructure

Expand All @@ -99,12 +100,14 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- Adding @zhongnansu as maintainer. ([#2590](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2590))
- Removes `minimatch` manual resolution ([#3019](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3019))
- Remove `github-checks-reporter`, an unused dependency ([#3126](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3126))

### 🪛 Refactoring

- [MD] Refactor data source error handling ([#2661](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2661))
- Refactor and improve Discover field summaries ([#2391](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2391))
- [Vis Builder] Removed Hard Coded Strings and Used i18n to transalte([#2867](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2867))
- [Console] Replace jQuery.ajax with core.http when calling OSD APIs in console ([#3080]https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3080))

### 🔩 Tests

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
"@elastic/eslint-config-kibana": "0.15.0",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/filesaver": "1.1.2",
"@elastic/github-checks-reporter": "0.0.20b3",
"@elastic/makelogs": "^6.1.0",
"@microsoft/api-documenter": "^7.13.78",
"@microsoft/api-extractor": "^7.19.3",
Expand Down
23 changes: 1 addition & 22 deletions src/dev/ci_setup/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ yarn config set yarn-offline-mirror "$cacheDir/yarn-offline-cache"
yarnGlobalDir="$(yarn global bin)"
export PATH="$PATH:$yarnGlobalDir"

# TODO: Find out if these are OSD's or if this entire file should be removed
# use a proxy to fetch chromedriver/geckodriver asset
export GECKODRIVER_CDNURL="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache"
export CHROMEDRIVER_CDNURL="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache"
export RE2_DOWNLOAD_MIRROR="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache"
export CYPRESS_DOWNLOAD_MIRROR="https://us-central1-elastic-kibana-184716.cloudfunctions.net/kibana-ci-proxy-cache/cypress"

export CHECKS_REPORTER_ACTIVE=false

# This is mainly for release-manager builds, which run in an environment that doesn't have Chrome installed
if [[ "$(which google-chrome-stable)" || "$(which google-chrome)" ]]; then
echo "Chrome detected, setting DETECT_CHROMEDRIVER_VERSION=true"
Expand All @@ -143,26 +142,6 @@ else
echo "Chrome not detected, installing default chromedriver binary for the package version"
fi

### only run on pr jobs for opensearch-project/OpenSearch-Dashboards, checks-reporter doesn't work for other repos
if [[ "$ghprbPullId" && "$ghprbGhRepository" == 'opensearch-project/OpenSearch-Dashboards' ]] ; then
export CHECKS_REPORTER_ACTIVE=true
fi

###
### Implements github-checks-reporter kill switch when scripts are called from the command line
### $@ - all arguments
###
function checks-reporter-with-killswitch() {
if [ "$CHECKS_REPORTER_ACTIVE" == "true" ] ; then
yarn run github-checks-reporter "$@"
else
arguments=("$@");
"${arguments[@]:1}";
fi
}

export -f checks-reporter-with-killswitch

source "$OPENSEARCH_DASHBOARDS_DIR/src/dev/ci_setup/load_env_keys.sh"

OPENSEARCH_DIR="$WORKSPACE/opensearch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

import React, { createContext, useContext, useEffect } from 'react';
import { NotificationsSetup } from 'opensearch-dashboards/public';
import { HttpSetup, NotificationsSetup } from 'opensearch-dashboards/public';
import { History, Settings, Storage } from '../../services';
import { ObjectStorageClient } from '../../../common/types';
import { MetricsTracker } from '../../types';
Expand All @@ -43,6 +43,7 @@ interface ContextServices {
objectStorageClient: ObjectStorageClient;
trackUiMetric: MetricsTracker;
opensearchHostService: OpenSearchHostService;
http: HttpSetup;
}

export interface ContextValue {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import {
HttpFetchError,
HttpFetchOptionsWithPath,
HttpResponse,
HttpSetup,
} from '../../../../../../core/public';
import { OpenSearchRequestArgs, sendRequestToOpenSearch } from './send_request_to_opensearch';
import * as opensearch from '../../../lib/opensearch/opensearch';

const createMockResponse = (
statusCode: number,
statusText: string,
headers: Array<[string, string]>
): Response => {
return {
// headers: {} as Headers,
headers: new Headers(headers),
ok: true,
redirected: false,
status: statusCode,
statusText,
type: 'basic',
url: '',
clone: jest.fn(),
body: (jest.fn() as unknown) as ReadableStream,
bodyUsed: true,
arrayBuffer: jest.fn(),
blob: jest.fn(),
text: jest.fn(),
formData: jest.fn(),
json: jest.fn(),
};
};

const createMockHttpResponse = (
statusCode: number,
statusText: string,
headers: Array<[string, string]>,
body: any
): HttpResponse<any> => {
return {
fetchOptions: (jest.fn() as unknown) as Readonly<HttpFetchOptionsWithPath>,
request: (jest.fn() as unknown) as Readonly<Request>,
response: createMockResponse(statusCode, statusText, headers),
body,
};
};
const dummyArgs: OpenSearchRequestArgs = {
http: ({
post: jest.fn(),
} as unknown) as HttpSetup,
requests: [
{
method: 'GET',
url: '/dummy/api',
data: ['{}'],
},
],
};

describe('test sendRequestToOpenSearch', () => {
it('test request success, json', () => {
const mockHttpResponse = createMockHttpResponse(
200,
'ok',
[['Content-Type', 'application/json, utf-8']],
{
ok: true,
}
);

jest.spyOn(opensearch, 'send').mockResolvedValue(mockHttpResponse);
sendRequestToOpenSearch(dummyArgs).then((result) => {
expect((result as any)[0].response.value).toBe('{\n "ok": true\n}');
});
});

it('test request success, text', () => {
const mockHttpResponse = createMockHttpResponse(
200,
'ok',
[['Content-Type', 'text/plain']],
'response text'
);

jest.spyOn(opensearch, 'send').mockResolvedValue(mockHttpResponse);
sendRequestToOpenSearch(dummyArgs).then((result) => {
expect((result as any)[0].response.value).toBe('response text');
});
});

it('test request success, with warning', () => {
const mockHttpResponse = createMockHttpResponse(
200,
'ok',
[
['Content-Type', 'text/plain'],
['warning', 'dummy warning'],
],
'response text'
);

jest.spyOn(opensearch, 'send').mockResolvedValue(mockHttpResponse);
sendRequestToOpenSearch(dummyArgs).then((result) => {
expect((result as any)[0].response.value).toBe(
'#! Deprecation: dummy warning\nresponse text'
);
});
});

it('test request 404', () => {
const mockHttpResponse = createMockHttpResponse(
404,
'not found',
[['Content-Type', 'text/plain']],
'response text'
);

jest.spyOn(opensearch, 'send').mockResolvedValue(mockHttpResponse);
sendRequestToOpenSearch(dummyArgs).then((result) => {
expect((result as any)[0].response.value).toBe('response text');
});
});

it('test request 500, json', () => {
const mockHttpError: HttpFetchError = new HttpFetchError(
'error message',
'name',
(jest.fn as unknown) as Request,
createMockResponse(500, 'Server Error', [['Content-Type', 'application/json, utf-8']]),
{ errorMsg: 'message' }
);

jest.spyOn(opensearch, 'send').mockRejectedValue(mockHttpError);
sendRequestToOpenSearch(dummyArgs).catch((error) => {
expect(error.response.value).toBe('{\n "errorMsg": "message"\n}');
});
});

it('test request 500, text', () => {
const mockHttpError: HttpFetchError = new HttpFetchError(
'error message',
'name',
(jest.fn as unknown) as Request,
createMockResponse(500, 'Server Error', [['Content-Type', 'text/plain']]),
'error message'
);

jest.spyOn(opensearch, 'send').mockRejectedValue(mockHttpError);
sendRequestToOpenSearch(dummyArgs).catch((error) => {
expect(error.response.value).toBe('error message');
});
});

it('test no connection', () => {
const mockHttpError: HttpFetchError = new HttpFetchError(
'error message',
'name',
(jest.fn as unknown) as Request,
undefined,
'error message'
);

jest.spyOn(opensearch, 'send').mockRejectedValue(mockHttpError);
sendRequestToOpenSearch(dummyArgs).catch((error) => {
expect(error.response.value).toBe(
"\n\nFailed to connect to Console's backend.\nPlease check the OpenSearch Dashboards server is up and running"
);
});
});
});
Loading

0 comments on commit 63789ed

Please sign in to comment.