-
Notifications
You must be signed in to change notification settings - Fork 97
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
Changes from 17 commits
f0f61f0
2325337
1a63c53
c0601ed
b0d3e3a
adb68bd
0ed4924
018a700
41cce60
4be4a8c
3901b8f
c611e7c
be1f264
891115d
15f5a5e
83e2419
b9bce79
c86df76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Instrumenting metrics in each element's onClick is tedious comparing to adding an attribute.
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 |
---|---|---|
@@ -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; | ||
})(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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