-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fixes-flaky-spaces-data-before-all
- Loading branch information
Showing
61 changed files
with
1,560 additions
and
706 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
.../data_view_management/public/components/index_pattern_table/data_view_table_controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; | ||
import { BehaviorSubject, Observable } from 'rxjs'; | ||
import { isEqual } from 'lodash'; | ||
import { getIndexPatterns } from '../utils'; | ||
import { IndexPatternTableItem } from '../types'; | ||
import { stateSelectorFactory } from '../state_helpers'; | ||
|
||
export interface DataViewTableControllerState { | ||
isLoadingDataViews: boolean; | ||
isLoadingHasData: boolean; | ||
hasDataView: boolean; | ||
hasEsData: boolean; | ||
dataViews: IndexPatternTableItem[]; | ||
} | ||
|
||
export interface DataViewTableControllerConstructorArgs { | ||
services: { | ||
dataViews: DataViewsPublicPluginStart; | ||
}; | ||
config: { | ||
defaultDataView: string; | ||
}; | ||
} | ||
|
||
export const dataViewTableControllerStateDefaults = { | ||
isLoadingDataViews: false, | ||
isLoadingHasData: true, | ||
hasDataView: false, | ||
hasEsData: false, | ||
dataViews: [], | ||
}; | ||
|
||
const selectIndexPattern = (state: DataViewTableControllerState) => state.dataViews; | ||
const selectHasDataView = (state: DataViewTableControllerState) => state.hasDataView; | ||
const selectHasEsData = (state: DataViewTableControllerState) => state.hasEsData; | ||
const selectIsLoadingIndexPatterns = (state: DataViewTableControllerState) => | ||
state.isLoadingDataViews; | ||
const selectIsLoadingDataState = (state: DataViewTableControllerState) => state.isLoadingHasData; | ||
|
||
export class DataViewTableController { | ||
constructor({ | ||
services: { dataViews }, | ||
config: { defaultDataView }, | ||
}: DataViewTableControllerConstructorArgs) { | ||
this.dataViews = dataViews; | ||
this.defaultDataView = defaultDataView; | ||
|
||
const stateSelector = stateSelectorFactory(this.state$); | ||
|
||
this.isLoadingIndexPatterns$ = stateSelector(selectIsLoadingIndexPatterns); | ||
this.indexPatterns$ = stateSelector(selectIndexPattern, isEqual); | ||
this.isLoadingDataState$ = stateSelector(selectIsLoadingDataState); | ||
this.hasDataView$ = stateSelector(selectHasDataView); | ||
this.hasESData$ = stateSelector(selectHasEsData); | ||
|
||
this.loadDataViews(); | ||
} | ||
|
||
private state: DataViewTableControllerState = { | ||
...dataViewTableControllerStateDefaults, | ||
}; | ||
|
||
private state$ = new BehaviorSubject<DataViewTableControllerState>(this.state); | ||
|
||
private dataViews: DataViewsPublicPluginStart; | ||
private defaultDataView: string; | ||
|
||
isLoadingIndexPatterns$: Observable<boolean>; | ||
indexPatterns$: Observable<IndexPatternTableItem[]>; | ||
isLoadingDataState$: Observable<boolean>; | ||
hasDataView$: Observable<boolean>; | ||
hasESData$: Observable<boolean>; | ||
|
||
private updateState = (newState: Partial<DataViewTableControllerState>) => { | ||
this.state = { ...this.state, ...newState }; | ||
this.state$.next(this.state); | ||
}; | ||
|
||
private loadHasData = async () => { | ||
const hasDataViewPromise = this.dataViews.hasData.hasDataView().then((hasDataView) => { | ||
this.updateState({ hasDataView }); | ||
}); | ||
|
||
const hasESDataPromise = this.dataViews.hasData.hasESData().then((hasEsData) => { | ||
this.updateState({ hasEsData }); | ||
}); | ||
|
||
return Promise.all([hasDataViewPromise, hasESDataPromise]).then(() => { | ||
this.updateState({ isLoadingHasData: false }); | ||
}); | ||
}; | ||
|
||
private getDataViews = async () => { | ||
this.updateState({ isLoadingDataViews: true }); | ||
const dataViews = await getIndexPatterns(this.defaultDataView, this.dataViews); | ||
this.updateState({ dataViews, isLoadingDataViews: false }); | ||
}; | ||
|
||
loadDataViews = async () => { | ||
const loadHasDataPromise = this.loadHasData(); | ||
const getDataViewsPromise = this.getDataViews(); | ||
return Promise.all([loadHasDataPromise, getDataViewsPromise]); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/plugins/data_view_management/public/components/state_helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { map, distinctUntilChanged, Observable } from 'rxjs'; | ||
|
||
export const stateSelectorFactory = | ||
<S>(state$: Observable<S>) => | ||
<R>(selector: (state: S) => R, equalityFn?: (arg0: R, arg1: R) => boolean) => | ||
state$.pipe(map(selector), distinctUntilChanged(equalityFn)); |
54 changes: 54 additions & 0 deletions
54
x-pack/plugins/apm/ftr_e2e/cypress/e2e/power_user/service_overview/generate_data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { apm, timerange } from '@kbn/apm-synthtrace'; | ||
|
||
export function generateData({ from, to }: { from: number; to: number }) { | ||
const range = timerange(from, to); | ||
const synthGo1 = apm | ||
.service({ | ||
name: 'synth-go-1', | ||
environment: 'production', | ||
agentName: 'go', | ||
}) | ||
.instance('my-instance'); | ||
|
||
const synthIOS = apm | ||
.service({ | ||
name: 'synth-ios', | ||
environment: 'production', | ||
agentName: 'iOS/swift', | ||
}) | ||
.instance('my-instance'); | ||
|
||
const synthAndroid = apm | ||
.service({ | ||
name: 'synth-android', | ||
environment: 'production', | ||
agentName: 'android/java', | ||
}) | ||
.instance('my-instance'); | ||
|
||
return range.interval('1m').generator((timestamp) => { | ||
return [ | ||
synthGo1 | ||
.transaction({ transactionName: 'GET /apple 🍎' }) | ||
.timestamp(timestamp) | ||
.duration(1000) | ||
.success(), | ||
synthIOS | ||
.transaction({ transactionName: 'GET /banana 🍌' }) | ||
.timestamp(timestamp) | ||
.duration(1000) | ||
.success(), | ||
synthAndroid | ||
.transaction({ transactionName: 'GET /apple 🍎' }) | ||
.timestamp(timestamp) | ||
.duration(1000) | ||
.success(), | ||
]; | ||
}); | ||
} |
Oops, something went wrong.