Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/refactor/create-form-hooks-p2' i…
Browse files Browse the repository at this point in the history
…nto refactor/create-form-hooks-part3
  • Loading branch information
Esteban Beltran committed Jun 7, 2022
2 parents 4b5dab6 + 2453d45 commit 20df8b9
Show file tree
Hide file tree
Showing 46 changed files with 1,763 additions and 96 deletions.
5 changes: 3 additions & 2 deletions .buildkite/pipelines/code_coverage/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ steps:
queue: kibana-default
env:
FTR_CONFIGS_DEPS: ''
LIMIT_CONFIG_TYPE: 'unit,functional,integration'
# LIMIT_CONFIG_TYPE: 'unit,functional,integration'
LIMIT_CONFIG_TYPE: 'unit,integration'
JEST_UNIT_SCRIPT: '.buildkite/scripts/steps/code_coverage/jest.sh'
JEST_INTEGRATION_SCRIPT: '.buildkite/scripts/steps/code_coverage/jest_integration.sh'
FTR_CONFIGS_SCRIPT: '.buildkite/scripts/steps/code_coverage/ftr_configs.sh'
Expand All @@ -25,6 +26,6 @@ steps:
depends_on:
- jest
- jest-integration
- ftr-configs
# - ftr-configs
timeout_in_minutes: 30
key: ingest
20 changes: 10 additions & 10 deletions .buildkite/scripts/steps/code_coverage/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo "--- Upload new git sha"

echo "--- Download coverage artifacts"
buildkite-agent artifact download target/kibana-coverage/jest/* .
buildkite-agent artifact download target/kibana-coverage/functional/* .
#buildkite-agent artifact download target/kibana-coverage/functional/* .
buildkite-agent artifact download target/ran_files/* .
ls -l target/ran_files/* || echo "### No ran-files found"

Expand All @@ -42,20 +42,20 @@ echo "--- Jest: Reset file paths prefix, merge coverage files, and generate the
replacePaths "$KIBANA_DIR/target/kibana-coverage/jest" "CC_REPLACEMENT_ANCHOR" "$KIBANA_DIR"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js

echo "--- Functional: Reset file paths prefix, merge coverage files, and generate the final combined report"
#echo "--- Functional: Reset file paths prefix, merge coverage files, and generate the final combined report"
# Functional: Reset file paths prefix to Kibana Dir of final worker
set +e
sed -ie "s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json
echo "--- Begin Split and Merge for Functional"
splitCoverage target/kibana-coverage/functional
splitMerge
set -e
#set +e
#sed -ie "s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json
#echo "--- Begin Split and Merge for Functional"
#splitCoverage target/kibana-coverage/functional
#splitMerge
#set -e

echo "--- Archive and upload combined reports"
collectAndUpload target/kibana-coverage/jest/kibana-jest-coverage.tar.gz \
target/kibana-coverage/jest-combined
collectAndUpload target/kibana-coverage/functional/kibana-functional-coverage.tar.gz \
target/kibana-coverage/functional-combined
#collectAndUpload target/kibana-coverage/functional/kibana-functional-coverage.tar.gz \
# target/kibana-coverage/functional-combined

echo "--- Upload coverage static site"
.buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh
Expand Down
22 changes: 14 additions & 8 deletions .buildkite/scripts/steps/code_coverage/reporting/ingestData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ echo "### Generate Team Assignments"
CI_STATS_DISABLED=true node scripts/generate_team_assignments.js \
--verbose --src '.github/CODEOWNERS' --dest $TEAM_ASSIGN_PATH

for x in functional jest; do
echo "### Ingesting coverage for ${x}"
COVERAGE_SUMMARY_FILE="target/kibana-coverage/${x}-combined/coverage-summary.json"

CI_STATS_DISABLED=true node scripts/ingest_coverage.js --path ${COVERAGE_SUMMARY_FILE} \
--vcsInfoPath ./VCS_INFO.txt --teamAssignmentsPath $TEAM_ASSIGN_PATH &
done
wait
#for x in functional jest; do
# echo "### Ingesting coverage for ${x}"
# COVERAGE_SUMMARY_FILE="target/kibana-coverage/${x}-combined/coverage-summary.json"
#
# CI_STATS_DISABLED=true node scripts/ingest_coverage.js --path ${COVERAGE_SUMMARY_FILE} \
# --vcsInfoPath ./VCS_INFO.txt --teamAssignmentsPath $TEAM_ASSIGN_PATH &
#done
#wait

echo "### Ingesting coverage for JEST"
COVERAGE_SUMMARY_FILE="target/kibana-coverage/jest-combined/coverage-summary.json"

CI_STATS_DISABLED=true node scripts/ingest_coverage.js --path ${COVERAGE_SUMMARY_FILE} \
--vcsInfoPath ./VCS_INFO.txt --teamAssignmentsPath $TEAM_ASSIGN_PATH

echo "--- Ingesting Code Coverage - Complete"
echo ""
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -euo pipefail

cat << EOF > src/dev/code_coverage/www/index_partial_2.html
<a class="nav-link" href="https://kibana-coverage.elastic.dev/${TIME_STAMP}/jest-combined/index.html">Latest Jest</a>
<a class="nav-link" href="https://kibana-coverage.elastic.dev/${TIME_STAMP}/functional-combined/index.html">Latest FTR</a>
</nav>
</div>
</header>
Expand All @@ -26,4 +25,4 @@ cat << EOF > src/dev/code_coverage/www/index_partial_2.html
EOF

cat src/dev/code_coverage/www/index_partial.html > src/dev/code_coverage/www/index.html
cat src/dev/code_coverage/www/index_partial_2.html >> src/dev/code_coverage/www/index.html
cat src/dev/code_coverage/www/index_partial_2.html >> src/dev/code_coverage/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ for x in 'src/dev/code_coverage/www/index.html' 'src/dev/code_coverage/www/404.h
gsutil -m -q cp -r -a public-read -z js,css,html ${x} ${uploadPrefix}
done

gsutil -m -q cp -r -a public-read -z js,css,html ${x} ${uploadPrefixWithTimeStamp}
#gsutil -m -q cp -r -a public-read -z js,css,html ${x} ${uploadPrefixWithTimeStamp}
#
#for x in 'target/kibana-coverage/functional-combined' 'target/kibana-coverage/jest-combined'; do
# gsutil -m -q cp -r -a public-read -z js,css,html ${x} ${uploadPrefixWithTimeStamp}
#done

for x in 'target/kibana-coverage/functional-combined' 'target/kibana-coverage/jest-combined'; do
gsutil -m -q cp -r -a public-read -z js,css,html ${x} ${uploadPrefixWithTimeStamp}
done
gsutil -m -q cp -r -a public-read -z js,css,html 'target/kibana-coverage/jest-combined' ${uploadPrefixWithTimeStamp}
4 changes: 2 additions & 2 deletions src/plugins/expressions/public/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ describe('ExpressionLoader', () => {
it('throttles partial results', async () => {
testScheduler.run(({ cold, expectObservable }) => {
const expressionLoader = new ExpressionLoader(element, 'var foo', {
variables: { foo: cold('a 5ms b 5ms c 10ms d', { a: 1, b: 2, c: 3, d: 4 }) },
variables: { foo: cold('a 5ms b 5ms c 10ms (d|)', { a: 1, b: 2, c: 3, d: 4 }) },
partial: true,
throttle: 20,
});

expectObservable(expressionLoader.data$).toBe('a 19ms c 19ms d', {
expectObservable(expressionLoader.data$).toBe('a 19ms c 2ms d', {
a: expect.objectContaining({ result: 1 }),
c: expect.objectContaining({ result: 3 }),
d: expect.objectContaining({ result: 4 }),
Expand Down
63 changes: 58 additions & 5 deletions src/plugins/expressions/public/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { BehaviorSubject, Observable, Subject, Subscription, asyncScheduler, identity } from 'rxjs';
import { filter, map, delay, shareReplay, throttleTime } from 'rxjs/operators';
import { BehaviorSubject, Observable, Subject, Subscription, identity, timer } from 'rxjs';
import { delay, filter, finalize, map, shareReplay, takeWhile } from 'rxjs/operators';
import { defaults } from 'lodash';
import { SerializableRecord, UnwrapObservable } from '@kbn/utility-types';
import { Adapters } from '@kbn/inspector-plugin/public';
Expand All @@ -20,6 +20,61 @@ import { getExpressionsService } from './services';

type Data = unknown;

/**
* RxJS' `throttle` operator does not emit the last value immediately when the source observable is completed.
* Instead, it waits for the next throttle period to emit that.
* It might cause delays until we get the final value, even though it is already there.
* @see https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/throttle.ts#L121
*/
function throttle<T>(timeout: number) {
return (source: Observable<T>): Observable<T> =>
new Observable((subscriber) => {
let latest: T | undefined;
let hasValue = false;

const emit = () => {
if (hasValue) {
subscriber.next(latest);
hasValue = false;
latest = undefined;
}
};

let throttled: Subscription | undefined;
const timer$ = timer(0, timeout).pipe(
takeWhile(() => hasValue),
finalize(() => {
subscriber.remove(throttled!);
throttled = undefined;
})
);

subscriber.add(
source.subscribe({
next: (value) => {
latest = value;
hasValue = true;

if (!throttled) {
throttled = timer$.subscribe(emit);
subscriber.add(throttled);
}
},
error: (error) => subscriber.error(error),
complete: () => {
emit();
subscriber.complete();
},
})
);

subscriber.add(() => {
hasValue = false;
latest = undefined;
});
});
}

export class ExpressionLoader {
data$: ReturnType<ExecutionContract['getData']>;
update$: ExpressionRenderHandler['update$'];
Expand Down Expand Up @@ -151,9 +206,7 @@ export class ExpressionLoader {
.pipe(
delay(0), // delaying until the next tick since we execute the expression in the constructor
filter(({ partial }) => params.partial || !partial),
params.partial && params.throttle
? throttleTime(params.throttle, asyncScheduler, { leading: true, trailing: true })
: identity
params.partial && params.throttle ? throttle(params.throttle) : identity
)
.subscribe((value) => this.dataSubject.next(value));
};
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/apm/common/agent_configuration/all_option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { i18n } from '@kbn/i18n';

export const ALL_OPTION_VALUE = 'ALL_OPTION_VALUE';

// human-readable label for service and environment. The "All" option should be translated.
Expand All @@ -24,3 +23,8 @@ export function getOptionLabel(value: string | undefined) {
export function omitAllOption(value?: string) {
return value === ALL_OPTION_VALUE ? undefined : value;
}

export const ALL_OPTION = {
value: ALL_OPTION_VALUE,
label: getOptionLabel(ALL_OPTION_VALUE),
};
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,29 @@ describe('Agent configuration', () => {
cy.wait('@serviceEnvironmentApi');
cy.contains('production');
});
it('displays All label when selecting all option', () => {
cy.intercept(
'GET',
'/api/apm/settings/agent-configuration/environments'
).as('serviceEnvironmentApi');
cy.contains('Create configuration').click();
cy.get('[data-test-subj="serviceNameComboBox"]')
.click()
.type('All')
.type('{enter}');
cy.contains('All').realClick();
cy.wait('@serviceEnvironmentApi');

cy.get('[data-test-subj="serviceEnviromentComboBox"]')
.click({ force: true })
.type('All');

cy.get('mark').contains('All').click();
cy.contains('Next step').click();
cy.contains('Service name All');
cy.contains('Environment All');
cy.contains('Edit').click();
cy.wait('@serviceEnvironmentApi');
cy.contains('All');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { EuiDescribedFormGroup, EuiFormRow } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { SuggestionsSelect } from '../../../../../shared/suggestions_select';
import { ENVIRONMENT_ALL } from '../../../../../../../common/environment_filter_values';
import {
getOptionLabel,
ALL_OPTION,
} from '../../../../../../../common/agent_configuration/all_option';

interface Props {
title: string;
Expand Down Expand Up @@ -40,8 +43,8 @@ export function FormRowSuggestionsSelect({
>
<EuiFormRow label={fieldLabel}>
<SuggestionsSelect
customOptions={allowAll ? [ENVIRONMENT_ALL] : undefined}
defaultValue={value}
customOptions={allowAll ? [ALL_OPTION] : undefined}
defaultValue={value ? getOptionLabel(value) : undefined}
fieldName={fieldName}
onChange={onChange}
isClearable={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { waitForComponentToUpdate } from '../../common/test_utils';
import { useCreateAttachments } from '../../containers/use_create_attachments';
import { useGetReporters } from '../../containers/use_get_reporters';
import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics';
import { useGetActionLicense } from '../../containers/use_get_action_license';
import { useGetConnectors } from '../../containers/configure/use_connectors';
import { useGetTags } from '../../containers/use_get_tags';
import { useUpdateCase } from '../../containers/use_update_case';
Expand Down Expand Up @@ -61,7 +60,6 @@ const useGetCasesMock = useFetchCases as jest.Mock;
const useGetCasesStatusMock = useGetCasesStatus as jest.Mock;
const useGetCasesMetricsMock = useGetCasesMetrics as jest.Mock;
const useUpdateCasesMock = useUpdateCases as jest.Mock;
const useGetActionLicenseMock = useGetActionLicense as jest.Mock;
const useGetTagsMock = useGetTags as jest.Mock;
const useGetReportersMock = useGetReporters as jest.Mock;
const useKibanaMock = useKibana as jest.MockedFunction<typeof useKibana>;
Expand Down Expand Up @@ -132,12 +130,6 @@ describe('AllCasesListGeneric', () => {
updateBulkStatus,
};

const defaultActionLicense = {
data: null,
isLoading: false,
isError: false,
};

const defaultColumnArgs = {
caseDetailsNavigation: {
href: jest.fn(),
Expand Down Expand Up @@ -166,7 +158,6 @@ describe('AllCasesListGeneric', () => {
useDeleteCasesMock.mockReturnValue(defaultDeleteCases);
useGetCasesStatusMock.mockReturnValue(defaultCasesStatus);
useGetCasesMetricsMock.mockReturnValue(defaultCasesMetrics);
useGetActionLicenseMock.mockReturnValue(defaultActionLicense);
useGetTagsMock.mockReturnValue({ data: ['coke', 'pepsi'], refetch: jest.fn() });
useGetReportersMock.mockReturnValue({
reporters: ['casetester'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { useFetchCases } from '../../containers/use_get_cases';

jest.mock('../../containers/use_get_reporters');
jest.mock('../../containers/use_get_tags');
jest.mock('../../containers/use_get_action_license');
jest.mock('../../containers/use_get_action_license', () => {
return {
useGetActionLicense: jest.fn(),
};
});
jest.mock('../../containers/configure/use_connectors');
jest.mock('../../containers/api');
jest.mock('../../containers/use_get_cases');
Expand Down
Loading

0 comments on commit 20df8b9

Please sign in to comment.