Skip to content

Commit

Permalink
Refactor build request to pass unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Nguyen <[email protected]>
  • Loading branch information
huyaboo committed Apr 9, 2024
1 parent 19c17f9 commit eecfd89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { OPENSEARCH_SEARCH_STRATEGY } from '../../../../data/server';
import Datasource from '../../lib/classes/datasource';
import buildRequest from './lib/build_request';
import toSeriesList from './lib/agg_response_to_series_list';
import { fetchDataSourceIdByName } from '../../lib/fetch_data_source_id';

export default new Datasource('es', {
args: [
Expand Down Expand Up @@ -156,7 +157,15 @@ export default new Datasource('es', {

const opensearchShardTimeout = tlConfig.opensearchShardTimeout;

const body = await buildRequest(config, tlConfig, scriptedFields, opensearchShardTimeout);
const dataSourceId = await fetchDataSourceIdByName(config, tlConfig.savedObjectsClient);

const body = buildRequest(
config,
tlConfig,
scriptedFields,
opensearchShardTimeout,
dataSourceId
);

const deps = (await tlConfig.getStartServices())[1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import moment from 'moment';
import { buildAggBody } from './agg_body';
import createDateAgg from './create_date_agg';
import { UI_SETTINGS } from '../../../../../data/server';
import { fetchDataSourceIdByName } from '../../../lib/fetch_data_source_id';

export default async function buildRequest(config, tlConfig, scriptedFields, timeout) {
export default function buildRequest(config, tlConfig, scriptedFields, timeout, dataSourceId) {
const bool = { must: [] };

const timeFilter = {
Expand All @@ -49,8 +48,6 @@ export default async function buildRequest(config, tlConfig, scriptedFields, tim
};
bool.must.push(timeFilter);

const dataSourceId = await fetchDataSourceIdByName(config, tlConfig.savedObjectsClient);

// Use the opensearchDashboards and kibana filter bar filters
if (config.opensearchDashboards && config.kibana) {
bool.filter = _.get(tlConfig, 'request.body.extended.es.filter');
Expand Down

0 comments on commit eecfd89

Please sign in to comment.