Skip to content

Commit

Permalink
Feature/observability (#1)
Browse files Browse the repository at this point in the history
* Adding plugin backend adaptor (opensearch-project#126)

* adding plugin backed adaptor

* resolved comments and beautification

* Update notebooks to use observability backend (opensearch-project#129)

* Event Analytics  - Add index picker to explorer page (opensearch-project#125)

* Add index picker to explorer page

* Update explorer.tsx

* Feature/operational panels backend (opensearch-project#130)

* added panel router, viz router and panel types

* removed let->const

* minor fix

* replaced console log->error, removed index_not_found error check

* Feature/p1 release (opensearch-project#133)

* removed live button

Signed-off-by: Eric Wei <[email protected]>

* refresh button

Signed-off-by: Eric Wei <[email protected]>

* removed live button from home

Signed-off-by: Eric Wei <[email protected]>

* xaxis range selectable

Signed-off-by: Eric Wei <[email protected]>

* added new charts

Signed-off-by: Eric Wei <[email protected]>

* added sidebar to vis, hided vis setting panel

Signed-off-by: Eric Wei <[email protected]>

* fixed a bar issue

Signed-off-by: Eric Wei <[email protected]>

* modified run/refresh button

Signed-off-by: Eric Wei <[email protected]>

* hided surrounding docs

Signed-off-by: Eric Wei <[email protected]>

* disabled insights

Signed-off-by: Eric Wei <[email protected]>

* disable reset button and remove s/ms options

Signed-off-by: Eric Wei <[email protected]>

* breadcrumb/route changes

Signed-off-by: Eric Wei <[email protected]>

* add date range to query & added runtime fields

Signed-off-by: Eric Wei <[email protected]>

* disabled toggle button for queried fields

Signed-off-by: Eric Wei <[email protected]>

* modified text

Signed-off-by: Eric Wei <[email protected]>

* added couple of configs to autocomplete

* added saved objects and few bug fixes

Signed-off-by: Eric Wei <[email protected]>

* removed unused reference/files, modified few loggings

Signed-off-by: Eric Wei <[email protected]>

* removed missed comments/usused code, fixed one sidebar issue

Signed-off-by: Eric Wei <[email protected]>

* modified files for code review

Signed-off-by: Eric Wei <[email protected]>

* Feature/operational panel UI (opensearch-project#132)

* modified panels home, table and view

* added new panel modules

* moved modules to folders with css

* css edits and removed time regex check

* removed time and fields regex checks

* minor doc changes

* adding visualization charts

* added delete panelList functionality

* edited delete custom panel function, beautified

* changed console log to error

* removed time/fields regex

* removed length check, combined optionalArgs in custom modal, prettier fix

Co-authored-by: Shenoy Pratik <[email protected]>
Co-authored-by: Joshua <[email protected]>
Co-authored-by: Eric Wei <[email protected]>
  • Loading branch information
4 people authored Oct 26, 2021
1 parent 58c3c67 commit bad8169
Show file tree
Hide file tree
Showing 82 changed files with 3,822 additions and 1,893 deletions.
39 changes: 37 additions & 2 deletions common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,51 @@
*/

export const RAW_QUERY = 'rawQuery';
export const INDEX = 'index';
export const FINAL_QUERY = 'finalQuery';
export const SELECTED_DATE_RANGE = 'selectedDateRange';
export const INDEX = 'indexPattern';
export const SELECTED_FIELDS = 'selectedFields';
export const UNSELECTED_FIELDS = 'unselectedFields';
export const AVAILABLE_FIELDS = 'availableFields';
export const QUERIED_FIELDS = 'queriedFields';
export const TAB_ID_TXT_PFX = 'query-panel-';
export const TAB_TITLE = 'New query';
export const TAB_CHART_TITLE = 'Visualizations';
export const TAB_EVENT_TITLE = 'Events';
export const TAB_EVENT_ID_TXT_PFX = 'main-content-events-';
export const TAB_CHART_ID_TXT_PFX = 'main-content-charts-';
export const TAB_CHART_ID_TXT_PFX = 'main-content-vis-';

export const DATE_PICKER_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export const TIME_INTERVAL_OPTIONS = [
{
display: 'Auto',
val: 'h' // same as value of Hour for now
},
{
display: 'Minute',
val: 'm'
},
{
display: 'Hour',
val: 'h'
},
{
display: 'Day',
val: 'd'
},
{
display: 'Week',
val: 'w'
},
{
display: 'Month',
val: 'M'
},
{
display: 'Year',
val: 'y'
},
]

// redux
export const SELECTED_QUERY_TAB = 'selectedQueryTab';
Expand Down
15 changes: 12 additions & 3 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const DSL_BASE = '/api/dsl';
export const DSL_SEARCH = '/search';
export const DSL_CAT = '/cat.indices';
export const DSL_MAPPING = '/indices.getFieldMapping';
export const OBSERVABILITY_BASE = '/api/observability';
export const EVENT_ANALYTICS = '/event_analytics';
export const SAVED_OBJECTS = '/saved_objects';
export const SAVED_QUERY = '/query';
export const SAVED_VISUALIZATION = '/vis';

// Server route
export const PPL_ENDPOINT = '/_plugins/_ppl';
Expand All @@ -29,11 +34,15 @@ export const observabilityPluginOrder = 6000;
// Shared Constants
export const UI_DATE_FORMAT = 'MM/DD/YYYY hh:mm A';
export const PPL_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export const PPL_STATS_REGEX = /\|\s*stats/i;
export const PPL_INDEX_INSERT_POINT_REGEX = /search (source|index)\s*=\s*([^\s]+)(.*)/i;
export const PPL_INDEX_REGEX = /(search source|source|index)\s*=\s*([^|\s]+)/i;

// Observability plugin URI
// Observability plugin URI
const BASE_OBSERVABILITY_URI = '/_plugins/_observability';
export const OPENSEARCH_PANELS_API = {
GET_PANELS: `${BASE_OBSERVABILITY_URI}/panels`,
PANEL: `${BASE_OBSERVABILITY_URI}/panel`,
OBJECT: `${BASE_OBSERVABILITY_URI}/object`,
};

// Saved Objects
export const SAVED_OBJECT = '/object';
51 changes: 51 additions & 0 deletions common/types/custom_panels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

export type CustomPanelListType = {
name: string;
id: string;
dateCreated: string;
dateModified: string;
};

export type VisualizationType = {
id: string;
title: string;
x: number;
y: number;
w: number;
h: number;
query: string;
type: string;
timeField: string;
};

export type PanelType = {
name: string;
visualizations: VisualizationType[];
timeRange: { to: string; from: string };
queryFilter: { query: string; language: string };
};

export type SavedVisualizationType = {
id: string;
name: string;
query: string;
type: string;
timeField: string;
};

export type pplResponse = {
data: any;
metadata: any;
size: number;
status: number;
};
8 changes: 7 additions & 1 deletion common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import {
RAW_QUERY,
SELECTED_FIELDS,
UNSELECTED_FIELDS
UNSELECTED_FIELDS,
AVAILABLE_FIELDS,
QUERIED_FIELDS
} from '../constants/explorer';
import SavedObjects from '../../public/services/saved_objects/event_analytics/saved_objects';

export interface IQueryTab {
id: string;
Expand Down Expand Up @@ -45,9 +48,12 @@ export interface IExplorerTabFields {
export interface IExplorerFields {
[SELECTED_FIELDS]: Array<IField>;
[UNSELECTED_FIELDS]: Array<IField>;
[AVAILABLE_FIELDS]: Array<IField>;
[QUERIED_FIELDS]: Array<IField>;
}

export interface ILogExplorerProps {
pplService: any;
dslService: any;
savedObjects: SavedObjects;
}
2 changes: 1 addition & 1 deletion common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* GitHub history for details.
*/

export { getIndexPatternFromRawQuery } from './query_utils';
export { getIndexPatternFromRawQuery, insertDateRangeToQuery } from './query_utils';
35 changes: 34 additions & 1 deletion common/utils/query_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,45 @@
* GitHub history for details.
*/

import { PPL_INDEX_REGEX } from "../constants/shared";
import { isEmpty } from 'lodash';
import datemath from '@elastic/datemath';
import { DATE_PICKER_FORMAT } from '../../common/constants/explorer';
import {
PPL_INDEX_REGEX,
PPL_INDEX_INSERT_POINT_REGEX
} from '../../common/constants/shared';

export const getIndexPatternFromRawQuery = (query: string) : string => {
const matches = query.match(PPL_INDEX_REGEX);
if (matches) {
return matches[2];
}
return '';
};

export const insertDateRangeToQuery = ({
rawQuery,
startTime,
endTime,
timeField = 'utc_time',
}: {
rawQuery: string;
startTime: string;
endTime: string;
timeField?: string;
}) => {

let finalQuery = '';

if (isEmpty(rawQuery)) return finalQuery;

// convert to moment
const start = datemath.parse(startTime)?.format(DATE_PICKER_FORMAT);
const end = datemath.parse(endTime)?.format(DATE_PICKER_FORMAT);
const tokens = rawQuery.match(PPL_INDEX_INSERT_POINT_REGEX);

if (isEmpty(tokens)) return finalQuery;
finalQuery = `search ${tokens![1]}=${tokens![2]} | where ${timeField} >= timestamp('${start}') and ${timeField} <= timestamp('${end}')${tokens![3]}`;

return finalQuery;
};
37 changes: 16 additions & 21 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { AppPluginStartDependencies } from '../types';
import { Home as ApplicationAnalyticsHome } from './application_analytics/home';
import { renderPageWithSidebar } from './common/side_nav';
import { Home as CustomPanelsHome } from './custom_panels/home';
import { Home as EventExplorerHome } from './explorer/home';
import { LogExplorer } from './explorer/log_explorer';
import { EventAnalytics } from './explorer/event_analytics';
import { Main as NotebooksHome } from './notebooks/components/main';
import { Home as TraceAnalyticsHome } from './trace_analytics/home';

Expand All @@ -30,13 +29,15 @@ interface ObservabilityAppDeps {
DepsStart: AppPluginStartDependencies;
pplService: any;
dslService: any;
savedObjects: any;
}

export const App = ({
CoreStart,
DepsStart,
pplService,
dslService
dslService,
savedObjects
}: ObservabilityAppDeps) => {

const { chrome, http, notifications } = CoreStart;
Expand Down Expand Up @@ -97,17 +98,19 @@ export const App = ({
)}
/>
<Route
exact
path={['/explorer', '/explorer/home']}
path="/event_analytics"
render={(props) => {
chrome.setBreadcrumbs([
parentBreadcrumb,
{
text: 'Event analytics',
href: '/explorer/events',
},
]);
return renderPageWithSidebar(<EventExplorerHome />);
return (
<EventAnalytics
chrome={ chrome }
parentBreadcrumb={ parentBreadcrumb }
pplService={ pplService }
dslService={ dslService }
savedObjects={ savedObjects }
http={ http }
{ ...props }
/>
);
}}
/>
<Route
Expand All @@ -125,14 +128,6 @@ export const App = ({
);
}}
/>
<Route
exact
path='/explorer/events'
render={(props) => <LogExplorer
pplService={ pplService }
dslService={ dslService }
/> }
/>
</Switch>
</>
</I18nProvider>
Expand Down
25 changes: 21 additions & 4 deletions public/components/common/search/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,42 @@
*/

import './search.scss';
import React, { useEffect } from 'react';
import React, {
createElement,
Fragment,
useEffect,
useRef
} from 'react';
import { render } from 'react-dom';
import { autocomplete } from '@algolia/autocomplete-js';
import { IQueryBarProps } from './search';
import { RAW_QUERY } from '../../../../common/constants/explorer';
import { createPPLSuggestionsPlugin } from './autocomplete_plugin';

export function Autocomplete(props: IQueryBarProps) {
const containerRef = useRef(null);
const { query, handleQueryChange, handleQuerySearch, dslService } = props;

const PPLSuggestionPlugin = createPPLSuggestionsPlugin({
query,
handleQueryChange: props.handleQueryChange,
handleQuerySearch: props.handleQuerySearch,
dslService: props.dslService,
});

useEffect(() => {

if (!containerRef.current) {
return undefined;
}

const search = autocomplete({
container: '#autocomplete',
initialState: { query: props.query[RAW_QUERY] },
container: containerRef.current,
renderer: { createElement, Fragment },
render({ children }, root) {
render(children, root);
},
initialState: { query: query[RAW_QUERY] },
openOnFocus: true,
placeholder: 'Enter PPL query to retrieve log, traces, and metrics',
plugins: [PPLSuggestionPlugin],
Expand All @@ -40,5 +57,5 @@ export function Autocomplete(props: IQueryBarProps) {
};
}, []);

return <div id="autocomplete" />;
return <div ref={containerRef} />;
}
6 changes: 3 additions & 3 deletions public/components/common/search/autocomplete_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface PPLSuggestion {
}

interface CreatePPLSuggestionsPluginProps {
query: any;
handleQueryChange: (query: string, index: string) => void;
handleQuerySearch: () => void;
dslService: DSLService;
Expand Down Expand Up @@ -173,7 +174,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
item: '=',
});
currField = splittedModel[splittedModel.length - 2];
currFieldType = fieldsFromBackend.find((field) => field.label === currField).type;
currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type;
return fullSuggestions.filter(({ label }) => label.startsWith(prefix) && prefix !== label);
} else if (nextWhere === splittedModel.length - 2) {
return fillSuggestions(
Expand Down Expand Up @@ -267,9 +268,8 @@ export function createPPLSuggestionsPlugin(
): AutocompletePlugin<PPLSuggestion, undefined> {
return {
onStateChange: ({ state }) => {
if (state.query.length > queryLength) {
if (options.query.rawQuery !== state.query) {
options.handleQueryChange(state.query, currIndex);
queryLength++;
}
},
onSubmit: () => {
Expand Down
Loading

0 comments on commit bad8169

Please sign in to comment.