-
Notifications
You must be signed in to change notification settings - Fork 966
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 UI Metric for Discover 2.0 #8345
Conversation
❌ Empty Changelog SectionThe Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8345 +/- ##
==========================================
- Coverage 60.95% 60.92% -0.04%
==========================================
Files 3743 3756 +13
Lines 88857 89185 +328
Branches 13859 13941 +82
==========================================
+ Hits 54164 54337 +173
- Misses 31383 31467 +84
- Partials 3310 3381 +71
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
a68dcb5
to
dc9e9ef
Compare
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.
couple nits and potential suggestion
@@ -33,6 +33,11 @@ import { | |||
} from '../../../opensearch_dashboards_services'; | |||
import { SEARCH_ON_PAGE_LOAD_SETTING } from '../../../../common'; | |||
import { syncQueryStateWithUrl } from '../../../../../data/public'; | |||
import { | |||
DATASOURCE_METRIC_SUFFIX, |
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.
super nit pick so feel free to ignore. i find it easier to have a const object that groups the constants so that i can import more with less.
for example.
METRIC_SUFFIX = {
LANGUAGE: 'language_queries_count',
DATA_SOURCE: 'data_source_queries_count'
}
src/plugins/discover/public/application/view_components/utils/use_search.ts
Outdated
Show resolved
Hide resolved
src/plugins/discover/public/application/view_components/utils/use_search.ts
Outdated
Show resolved
Hide resolved
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.
appreciation comment for adding an index file
97e3456
to
792dff7
Compare
81c30aa
to
299c541
Compare
src/plugins/discover/public/application/view_components/utils/use_search.ts
Outdated
Show resolved
Hide resolved
@@ -236,6 +241,19 @@ export const useSearch = (services: DiscoverViewServices) => { | |||
elapsedMs, | |||
}, | |||
}); | |||
|
|||
// Add tracking for datasource type and query if the query is not same as last query | |||
const query = searchSource.getField('query'); |
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.
can't remember if discover creates a new search source and it doesn't have a parent but we could also check if searchSource.parent.getField('query') . but then again i haven't checked so it parent might not ever be set for discover
244244d
to
2e3e574
Compare
@@ -35,10 +42,34 @@ export const AppContainer = React.memo( | |||
|
|||
const topLinkRef = useRef<HTMLDivElement>(null); | |||
const datePickerRef = useRef<HTMLDivElement>(null); | |||
|
|||
const initialQueryEnhancement = useRef(null); // Initialize to null |
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.
nit:
i think precedent has been to have a reference like
const isMounted = useRef(false);
and add a similar use hook to check if isMounted
is true then we check if initialQueryEnhancement !== isEnhancementsEnabled
. if false then we set initialQueryEnhancement.current
to isEnhancementsEnabled
. for consistency with other parts of the application
that said could we make the isEnhancementsEnabled a reference? and just do
isEnhancementsEnabled.current !== uiSettings?.get(QUERY_ENHANCEMENT_ENABLED_SETTING);
to reduce additional constants
src/plugins/discover/public/application/view_components/utils/use_search.ts
Outdated
Show resolved
Hide resolved
// Track the dataset type and language used | ||
|
||
const query = searchSource.getField('query'); | ||
if (query && query.dataset?.type && query.language) { |
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.
just to verify, dataset with enhancements disabled will be undefined and therefore won't submit a ui metric. is that the current requirements or does it want to submit a ui metric for every language for every query
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.
Its the former. Tracking dataset type and language are important only in the new discover
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.
The requirements are specific to the new Discover experience , therefore in those cases where we don't have the datasets and language with enhancements off are not something we need to be worried about.
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const DATASOURCE_METRIC_SUFFIX = 'data_source_queries_count'; |
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.
i really think this should be dataset_queries_count
or dataset_type_queries_count
or data_queries_count
to avoid confusion with the concept of a dataSource
since a dataset can have a dataSource
ex:
the Index Pattern dataset type would make this count
INDEX_PATTERN_data_source_queries_count
I think but as you can see here it has a data source:
so the ui metric being data source would cause confusion
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.
we should also add a backlog item to migrate this portion over to the data plugin. eventually if the new discover ui becomes the standard and only or if other plugins on board to query enhancements then we can still get this insight on different types of dataset types and languages vs how it is used in discover
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.
Updated the Metric to dataset_queries_count
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const NEW_DISCOVER_LOAD_EVENT = 'new_discover_load_count'; |
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.
super duper nit: don't change this PR specifically for this but the import line for src/plugins/data_explorer/public/components/app_container.tsx could be a smaller and not require future updates if we utilize an object. and easier to access for developers. and probably should keep the casing and the same.
suggestion like:
const APP_NAME = `discover`;
const LOAD_EVENT = `load_count`;
const OPT_IN_EVENT = `opt_in_count`;
const OPT_OUT_EVENT = `opt_out_count`;
export const METRIC = {
DEFAULT: {
LOAD_EVENT: `${APP_NAME}_${LOAD_EVENT}`,
OPT_IN_EVENT: `${APP_NAME}_${OPT_IN_EVENT}`,
OPT_OUT_EVENT: `${APP_NAME}_${OPT_OUT_EVENT}`
},
LEGACY: {
LOAD_EVENT: `${APP_NAME}_legacy_${LOAD_EVENT}`,
OPT_IN_EVENT: `${APP_NAME}_legacy_${OPT_IN_EVENT}`,
OPT_OUT_EVENT: `${APP_NAME}_legacy_${OPT_OUT_EVENT}`
}
}
then we can just import METRIC
and access the constant with the dot notation.
some things to mention is that proposing using legacy
instead of classifying vs using the new
because with new or utilizing the 2.0
is that we version this ui metric to be 2.0 and then if we make the new discover the default then it becomes confusing for those who don't have context that the the default is the new
ui metric and the previous version was the one without any classifying word on the ui metric. however, im not super tied to calling legacy. but i think we should go with legacy or new and avoid the 2.0
or 2
.
also opted to ensure all the metrics are the same structure like
appname_classifier_event_metrictype
classifier being like new
or legacy
or nothing. this way if other plugins utilize the same standard then we have a nice way to aggregate on the results in a similar structure for visualizations and decision making. vs writing a query that filters out only the new and making the regex be something so it filters for new_discover
or discover_new
.
the final is using of interpolation this way if another developer wants to track another metric they can add by seeing the standard of using interpolation and do it as well. the reason why because i've seen people hardcode type constants over and over again and then there was a typo at which point we used that in key for local storage. but since the users used it already we are kind of stuck. so if we reduce the amount of opportunities for someone to make a typo then we could avoid an issue like queries failing to show up if the query was appName: discover
but the developer added a new metric discoever_refresh_count
where they mixed the e
and the v
in discover.
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.
Lemme know your thoughts on the useEffect based tracking. The rest look good!
@@ -49,7 +49,7 @@ describe('IndexPatternSelect', () => { | |||
|
|||
bulkGetMock.mockResolvedValue({ savedObjects: [{ attributes: { title: 'test1' } }] }); | |||
compInstance.debouncedFetch(''); | |||
await new Promise((resolve) => setTimeout(resolve, 300)); | |||
await new Promise((resolve) => setTimeout(resolve, 600)); |
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.
Why this change?
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 test case was a bit flakey in nature. hence to resolve it I had increased the timeout.
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 not the right way to deal with timers. Please revert this and i will deal with it in a separate PR.
DISCOVER_LOAD_EVENT, | ||
NEW_DISCOVER_LOAD_EVENT, | ||
NEW_DISCOVER_OPT_IN, | ||
NEW_DISCOVER_OPT_OUT, |
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.
Why do we need all 4? New discover cant be triggered without a page refresh. So the useEffect based tracking should be unnecessary.
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.
Oh. Then it might not make sense to add them in here. Removing the OPT_IN and OPT_OUT tracking from here.
// Track the dataset type and language used | ||
|
||
const query = searchSource.getField('query'); | ||
if (query && query.dataset?.type && query.language) { |
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.
Its the former. Tracking dataset type and language are important only in the new discover
Signed-off-by: Suchit Sahoo <[email protected]>
2e3e574
to
c6e407a
Compare
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.
+1 to @kavilla's nonblocking comment on the string constants, might need that documented somewhere as part of OSD best practices. Otherwise, LGTM.
Signed-off-by: Suchit Sahoo <[email protected]> (cherry picked from commit daa59de) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Description
The PR aims at capturing following UI Metrics.
Issues Resolved
Screenshot
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration