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

Separate default filters and extra filters #474

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ export function Application(props: AppDetailProps) {
endTime,
query,
filters,
appConfigs,
setAppConfigs,
setStartTimeWithStorage,
setEndTimeWithStorage,
setFilters,
setToasts,
} = props;
const [application, setApplication] = useState<ApplicationType>({
Expand Down Expand Up @@ -158,7 +159,7 @@ export function Application(props: AppDetailProps) {
};

useEffect(() => {
fetchAppById(http, appId, setApplication, setFilters, setToasts);
fetchAppById(http, appId, setApplication, setAppConfigs, setToasts);
}, [appId]);

useEffect(() => {
Expand All @@ -178,9 +179,9 @@ export function Application(props: AppDetailProps) {
}, [appId, application.name]);

useEffect(() => {
const DSL = filtersToDsl(filters, query, startTime, endTime, 'app');
const DSL = filtersToDsl(filters, query, startTime, endTime, 'app', appConfigs);
setSpanDSL(DSL);
}, [filters, query, startTime, endTime]);
}, [filters, appConfigs, query, startTime, endTime]);

const openServiceFlyout = (serviceName: string) => {
setSpanFlyoutId('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function ServiceDetailFlyout(props: ServiceFlyoutProps) {
startTime,
endTime,
filters,
appConfigs,
query,
closeServiceFlyout,
openSpanFlyout,
Expand Down Expand Up @@ -114,10 +115,10 @@ export function ServiceDetailFlyout(props: ServiceFlyoutProps) {
}, [serviceName, fields, serviceMap, DSL]);

useEffect(() => {
const serviceDSL = filtersToDsl(filters, query, startTime, endTime, 'app');
const serviceDSL = filtersToDsl(filters, query, startTime, endTime, 'app', appConfigs);
handleServiceViewRequest(serviceName, http, serviceDSL, fields, setFields);
handleServiceMapRequest(http, serviceDSL, serviceMap, setServiceMap, serviceName);
const spanDSL = filtersToDsl(filters, query, startTime, endTime, 'app');
const spanDSL = filtersToDsl(filters, query, startTime, endTime, 'app', appConfigs);
spanDSL.query.bool.must.push({
term: {
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AppAnalyticsComponentDeps extends TraceAnalyticsComponentDeps {
setDescriptionWithStorage: (newDescription: string) => void;
setQueryWithStorage: (newQuery: string) => void;
setFiltersWithStorage: (newFilters: FilterType[]) => void;
setAppConfigs: (newAppConfigs: FilterType[]) => void;
setStartTimeWithStorage: (newStartTime: string, itemName?: string) => void;
setEndTimeWithStorage: (newEndTime: string, itemName?: string) => void;
}
Expand All @@ -65,6 +66,7 @@ export const Home = (props: HomeProps) => {
const [applicationList, setApplicationList] = useState<ApplicationListType[]>([]);
const [toasts, setToasts] = useState<Toast[]>([]);
const [indicesExist, setIndicesExist] = useState(true);
const [appConfigs, setAppConfigs] = useState<FilterType[]>([]);
const storedFilters = sessionStorage.getItem('AppAnalyticsFilters');
const [filters, setFilters] = useState<FilterType[]>(
storedFilters ? JSON.parse(storedFilters) : []
Expand Down Expand Up @@ -125,6 +127,8 @@ export const Home = (props: HomeProps) => {
query,
setQuery,
setQueryWithStorage,
appConfigs,
setAppConfigs,
filters,
setFilters,
setFiltersWithStorage,
Expand Down Expand Up @@ -221,13 +225,12 @@ export const Home = (props: HomeProps) => {

// Rename an existing application
const renameApp = (newAppName: string, appId: string) => {
if (
!isNameValid(
newAppName,
applicationList.map((obj) => obj.name)
)
) {
setToast('Invalid Application name', 'danger');
const toast = isNameValid(
newAppName,
applicationList.map((obj) => obj.name)
);
if (toast.length > 0) {
setToast(toast.join(', '), 'danger');
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const Explorer = ({
const [isOverridingTimestamp, setIsOverridingTimestamp] = useState(false);
const [tempQuery, setTempQuery] = useState(query[RAW_QUERY]);

const fromAppAnalytics = tabId === 'application-analytics-tab';
const appLogEvents = tabId === 'application-analytics-tab';

const queryRef = useRef();
const selectedPanelNameRef = useRef('');
Expand Down Expand Up @@ -359,7 +359,7 @@ export const Explorer = ({
toggleFields(field, SELECTED_FIELDS, AVAILABLE_FIELDS);

const handleTimePickerChange = async (timeRange: string[]) => {
if (fromAppAnalytics) {
if (appLogEvents) {
setStartTime(timeRange[0]);
setEndTime(timeRange[1]);
} else {
Expand Down Expand Up @@ -842,7 +842,7 @@ export const Explorer = ({
})
);
});
if (fromAppAnalytics) {
if (appLogEvents) {
addVisualizationToPanel(res.objectId, selectedPanelNameRef.current);
} else {
history.replace(`/event_analytics/explorer/${res.objectId}`);
Expand Down Expand Up @@ -892,7 +892,7 @@ export const Explorer = ({
<div className="dscAppContainer">
<Search
key="search-component"
query={fromAppAnalytics ? appBaseQuery : query[RAW_QUERY]}
query={appLogEvents ? appBaseQuery : query[RAW_QUERY]}
tempQuery={tempQuery}
handleQueryChange={handleQueryChange}
handleQuerySearch={handleQuerySearch}
Expand All @@ -911,7 +911,7 @@ export const Explorer = ({
handleTimeRangePickerRefresh={handleTimeRangePickerRefresh}
selectedSubTabId={selectedContentTabId}
searchBarConfigs={searchBarConfigs}
getSuggestions={fromAppAnalytics ? getSuggestionsAfterSource : getFullSuggestions}
getSuggestions={appLogEvents ? getSuggestionsAfterSource : getFullSuggestions}
onItemSelect={onItemSelect}
tabId={tabId}
baseQuery={appBaseQuery}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ exports[`Search bar components renders date picker 1`] = `

exports[`Search bar components renders search bar 1`] = `
<SearchBar
appConfigs={Array []}
endTime="now"
filters={Array []}
page="dashboard"
Expand Down Expand Up @@ -980,6 +981,7 @@ exports[`Search bar components renders search bar 1`] = `
/>
</EuiSpacer>
<Filters
appConfigs={Array []}
filters={Array []}
page="dashboard"
setFilters={[MockFunction]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Search bar components', () => {
setEndTime={setEndTime}
filters={[]}
setFilters={setFilters}
appConfigs={[]}
/>
);
expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Filter component renders filters 1`] = `
<Filters
appConfigs={Array []}
filters={Array []}
page="dashboard"
setFilters={[MockFunction]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe('Filter component', () => {

it('renders filters', () => {
const setFilters = jest.fn();
const wrapper = mount(<Filters page="dashboard" filters={[]} setFilters={setFilters} />);
const wrapper = mount(
<Filters page="dashboard" filters={[]} setFilters={setFilters} appConfigs={[]} />
);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiPopoverTitle,
EuiTextColor,
} from '@elastic/eui';
import React, { Dispatch, SetStateAction, useMemo, useState } from 'react';
import React, { useMemo, useState } from 'react';
import { FilterEditPopover } from './filter_edit_popover';
import { getFilterFields, getValidFilterFields } from './filter_helpers';

Expand All @@ -32,6 +32,7 @@ export interface FilterType {

export interface FiltersProps {
filters: FilterType[];
appConfigs: FilterType[];
setFilters: (filters: FilterType[]) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export const filtersToDsl = (
startTime: string,
endTime: string,
page?: string,
appConfigs: FilterType[] = []
) => {
const DSL: any = {
query: {
Expand Down Expand Up @@ -395,13 +396,24 @@ export const filtersToDsl = (
default:
break;
}
if (page === 'app') {
DSL.query.bool.minimum_should_match = 1;
DSL.query.bool.should.push(filterQuery);
} else {
DSL.query.bool[filter.inverted ? 'must_not' : 'must'].push(filterQuery);
}
DSL.query.bool[filter.inverted ? 'must_not' : 'must'].push(filterQuery);
});

if (page === 'app') {
DSL.query.bool.minimum_should_match = 1;
appConfigs.forEach((config) => {
let appQuery = {};
const appField = config.field;
const appValue = config.value;
appQuery = {
term: {
[appField]: appValue,
},
};
DSL.query.bool.minimum_should_match = 1;
DSL.query.bool.should.push(appQuery);
});
}

return DSL;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
EuiSpacer,
EuiSuperDatePicker,
} from '@elastic/eui';
import { uiSettingsService } from '../../../../../common/utils';
import _ from 'lodash';
import React, { useState } from 'react';
import { uiSettingsService } from '../../../../../common/utils';
import { Filters, FiltersProps } from './filters/filters';

export const renderDatePicker = (
Expand Down Expand Up @@ -93,7 +93,12 @@ export function SearchBar(props: SearchBarOwnProps) {
{!props.datepickerOnly && (
<>
<EuiSpacer size="s" />
<Filters page={props.page} filters={props.filters} setFilters={props.setFilters} />
<Filters
page={props.page}
filters={props.filters}
setFilters={props.setFilters}
appConfigs={props.appConfigs}
/>
</>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Dashboard component renders dashboard 1`] = `
<Dashboard
appConfigs={Array []}
chrome={
Object {
"getIsNavDrawerLocked$": [MockFunction],
Expand Down Expand Up @@ -80,6 +81,7 @@ exports[`Dashboard component renders dashboard 1`] = `
</h2>
</EuiTitle>
<SearchBar
appConfigs={Array []}
endTime="now"
filters={Array []}
page="dashboard"
Expand Down Expand Up @@ -700,6 +702,7 @@ exports[`Dashboard component renders dashboard 1`] = `
/>
</EuiSpacer>
<Filters
appConfigs={Array []}
filters={Array []}
page="dashboard"
setFilters={
Expand Down Expand Up @@ -1989,6 +1992,7 @@ exports[`Dashboard component renders dashboard 1`] = `

exports[`Dashboard component renders empty dashboard 1`] = `
<Dashboard
appConfigs={Array []}
chrome={
Object {
"getIsNavDrawerLocked$": [MockFunction],
Expand Down Expand Up @@ -2067,6 +2071,7 @@ exports[`Dashboard component renders empty dashboard 1`] = `
</h2>
</EuiTitle>
<SearchBar
appConfigs={Array []}
endTime="now"
filters={Array []}
page="dashboard"
Expand Down Expand Up @@ -2669,6 +2674,7 @@ exports[`Dashboard component renders empty dashboard 1`] = `
/>
</EuiSpacer>
<Filters
appConfigs={Array []}
filters={Array []}
page="dashboard"
setFilters={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Dashboard component', () => {
query=""
setQuery={setQuery}
filters={[]}
appConfigs={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
Expand Down Expand Up @@ -57,6 +58,7 @@ describe('Dashboard component', () => {
query=""
setQuery={setQuery}
filters={[]}
appConfigs={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,25 @@ export function Dashboard(props: DashboardProps) {

useEffect(() => {
if (!redirect && props.indicesExist) refresh();
}, [props.filters, props.startTime, props.endTime]);
}, [props.filters, props.startTime, props.endTime, props.appConfigs]);

const refresh = async () => {
setLoading(true);
const DSL = filtersToDsl(props.filters, props.query, props.startTime, props.endTime, page);
const DSL = filtersToDsl(
props.filters,
props.query,
props.startTime,
props.endTime,
page,
appOverview ? props.appConfigs : []
);
const timeFilterDSL = filtersToDsl([], '', props.startTime, props.endTime, page);
const latencyTrendStartTime = dateMath
.parse(props.endTime)
?.subtract(24, 'hours')
.toISOString()!;
const latencyTrendDSL = filtersToDsl(
props.filters,
appOverview ? props.appConfigs : props.filters,
props.query,
latencyTrendStartTime,
props.endTime,
Expand Down Expand Up @@ -193,6 +200,7 @@ export function Dashboard(props: DashboardProps) {
<SearchBar
query={appOverview ? '' : props.query}
filters={props.filters}
appConfigs={props.appConfigs}
setFilters={props.setFilters}
setQuery={props.setQuery}
startTime={props.startTime}
Expand Down
Loading