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

Add metrics framework for frontend and backend #1306

Merged
merged 18 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
9 changes: 5 additions & 4 deletions dashboards-observability/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
*/

import { I18nProvider } from '@osd/i18n/react';
import { QueryManager } from 'common/query_manager';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was 'common/query_manager' instead of './common/query_manager' working for you? I've seen build errors not sure if it's only on my side or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is from tsserver's _typescript.organizeImports command reordering lines, it shouldn't make any difference functionally

import React from 'react';
import { Provider } from 'react-redux';
import { HashRouter, Route, Switch } from 'react-router-dom';
import { QueryManager } from 'common/query_manager';
import { CoreStart } from '../../../../src/core/public';
import { observabilityID, observabilityTitle } from '../../common/constants/shared';
import store from '../framework/redux/store';
import { AppPluginStartDependencies } from '../types';
import { Home as ApplicationAnalyticsHome } from './application_analytics/home';
import { MetricsListener } from './common/metrics_listener';
import { Home as CustomPanelsHome } from './custom_panels/home';
import { EventAnalytics } from './event_analytics';
import { Home as MetricsHome } from './metrics/index';
import { Main as NotebooksHome } from './notebooks/components/main';
import { Home as TraceAnalyticsHome } from './trace_analytics/home';
import { Home as MetricsHome } from './metrics/index';

interface ObservabilityAppDeps {
CoreStartProp: CoreStart;
Expand Down Expand Up @@ -58,7 +59,7 @@ export const App = ({
<Provider store={store}>
<HashRouter>
<I18nProvider>
<>
<MetricsListener http={http}>
<Switch>
<Route
path="/metrics_analytics/"
Expand Down Expand Up @@ -160,7 +161,7 @@ export const App = ({
}}
/>
</Switch>
</>
</MetricsListener>
</I18nProvider>
</HashRouter>
</Provider>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { HttpStart } from '../../../../../src/core/public';
import { OBSERVABILITY_BASE } from '../../../common/constants/shared';

interface MetricsListenerProps {
http: HttpStart;
}

export const MetricsListener: React.FC<MetricsListenerProps> = (props) => {
const incrementCountMetric = (element?: string | null) => {
if (!element) return;
props.http.post(`${OBSERVABILITY_BASE}/stats`, {
body: JSON.stringify({ element }),
});
};

const onClick: React.MouseEventHandler<HTMLDivElement> = (e) => {
incrementCountMetric(
(e.target as HTMLElement | null)
?.closest('[data-click-metric-element]')
?.getAttribute('data-click-metric-element')
Comment on lines +25 to +26
Copy link
Collaborator

@derek-ho derek-ho Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this coming from - is the idea that we label buttons with what they are doing? I see it's being added to some test snapshots, but only for trace analytics refresh? Will it be added for different other operations in the future? Nevermind, seems like you are adding this in the request itself, but why do you need to do this then? Why can't you just have it handled when we send the request?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to be sending these stats anywhere else other than the local index? Any place where we can get the aggregated stats?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derek-ho See description. This PR only adds the framework and some basic examples.

Why can't you just have it handled when we send the request?

Instrumenting metrics in each element's onClick is tedious comparing to adding an attribute.

Are we going to be sending these stats anywhere else other than the local index? Any place where we can get the aggregated stats?

Please see description for the "To get metrics" part.

);
};

return <div onClick={onClick}>{props.children}</div>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -882,12 +882,14 @@ exports[`Search bar components renders search bar 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[MockFunction]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -898,6 +900,7 @@ exports[`Search bar components renders search bar 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[MockFunction]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function SearchBar(props: SearchBarOwnProps) {
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="superDatePickerApplyTimeButton"
data-click-metric-element="trace_analytics.refresh_button"
iconType="refresh"
onClick={props.refresh}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,14 @@ exports[`Dashboard component renders dashboard 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -718,6 +720,7 @@ exports[`Dashboard component renders dashboard 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down Expand Up @@ -2749,12 +2752,14 @@ exports[`Dashboard component renders empty dashboard 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -2765,6 +2770,7 @@ exports[`Dashboard component renders empty dashboard 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,14 @@ exports[`Services component renders empty services page 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -708,6 +710,7 @@ exports[`Services component renders empty services page 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down Expand Up @@ -2438,12 +2441,14 @@ exports[`Services component renders services page 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -2454,6 +2459,7 @@ exports[`Services component renders services page 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,14 @@ exports[`Traces component renders empty traces page 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -706,6 +708,7 @@ exports[`Traces component renders empty traces page 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down Expand Up @@ -1902,12 +1905,14 @@ exports[`Traces component renders traces page 1`] = `
className="euiFlexItem euiFlexItem--flexGrowZero"
>
<EuiButton
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
iconType="refresh"
onClick={[Function]}
>
<EuiButtonDisplay
baseClassName="euiButton"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
element="button"
Expand All @@ -1918,6 +1923,7 @@ exports[`Traces component renders traces page 1`] = `
>
<button
className="euiButton euiButton--primary"
data-click-metric-element="trace_analytics.refresh_button"
data-test-subj="superDatePickerApplyTimeButton"
disabled={false}
onClick={[Function]}
Expand Down
49 changes: 49 additions & 0 deletions dashboards-observability/server/common/metrics/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ComponentType, CounterType } from './types';

export const WINDOW = 3600;
export const INTERVAL = 60;
export const CAPACITY = (WINDOW / INTERVAL) * 2;
export const MILLIS_MULTIPLIER = 1000;

export const COMPONENTS = [
'application_analytics',
'operational_panels',
'event_analytics',
'notebooks',
'trace_analytics',
'metrics_analytics',
] as const;
export const REQUESTS = ['create', 'get', 'update', 'delete'] as const;

export const GLOBAL_BASIC_COUNTER: CounterType = (() => {
const counter = {} as CounterType;
COMPONENTS.forEach((component) => {
counter[component] = {} as CounterType[ComponentType];
REQUESTS.forEach((request) => {
counter[component][request] = {
total: 0,
};
});
});
return counter;
})();

export const DEFAULT_ROLLING_COUNTER: CounterType = (() => {
const counter = {} as CounterType;
COMPONENTS.forEach((component) => {
counter[component] = {} as CounterType[ComponentType];
REQUESTS.forEach((request) => {
counter[component][request] = {
count: 0,
system_error: 0,
user_error: 0,
};
});
});
return counter;
})();
Loading