chore(sqllab): Add logging for actions (#28876)

This commit is contained in:
JUST.in DO IT
2024-06-14 09:35:17 -07:00
committed by GitHub
parent 66bd0ce3d0
commit 05829cbda9
9 changed files with 217 additions and 12 deletions

View File

@@ -70,6 +70,21 @@ export const LOG_ACTIONS_DRILL_BY_BREADCRUMB_CLICKED =
'drill_by_breadcrumb_clicked';
export const LOG_ACTIONS_SQLLAB_MONITOR_LOCAL_STORAGE_USAGE =
'sqllab_monitor_local_storage_usage';
export const LOG_ACTIONS_SQLLAB_CREATE_TABLE_AS = 'sqllab_create_table_as';
export const LOG_ACTIONS_SQLLAB_CREATE_VIEW_AS = 'sqllab_create_view_as';
export const LOG_ACTIONS_SQLLAB_RUN_QUERY = 'sqllab_run_query';
export const LOG_ACTIONS_SQLLAB_STOP_QUERY = 'sqllab_stop_query';
export const LOG_ACTIONS_SQLLAB_ESTIMATE_QUERY_COST =
'sqllab_estimate_query_cost';
export const LOG_ACTIONS_SQLLAB_SAVE_QUERY = 'sqllab_save_query';
export const LOG_ACTIONS_SQLLAB_SAVE_DATASET = 'sqllab_save_dataset';
export const LOG_ACTIONS_SQLLAB_COPY_LINK = 'sqllab_copy_link';
export const LOG_ACTIONS_SQLLAB_FORMAT_SQL = 'sqllab_format_sql';
export const LOG_ACTIONS_SQLLAB_DOWNLOAD_CSV = 'sqllab_download_csv';
export const LOG_ACTIONS_SQLLAB_COPY_RESULT_TO_CLIPBOARD =
'sqllab_copy_result_to_clipboard';
export const LOG_ACTIONS_SQLLAB_CREATE_CHART = 'sqllab_create_chart';
export const LOG_ACTIONS_SQLLAB_LOAD_TAB_STATE = 'sqllab_load_tab_state';
// Log event types --------------------------------------------------------------
export const LOG_EVENT_TYPE_TIMING = new Set([
@@ -77,6 +92,7 @@ export const LOG_EVENT_TYPE_TIMING = new Set([
LOG_ACTIONS_RENDER_CHART,
LOG_ACTIONS_HIDE_BROWSER_TAB,
LOG_ACTIONS_SQLLAB_FETCH_FAILED_QUERY,
LOG_ACTIONS_SQLLAB_LOAD_TAB_STATE,
]);
export const LOG_EVENT_TYPE_USER = new Set([
LOG_ACTIONS_MOUNT_DASHBOARD,

View File

@@ -0,0 +1,55 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { renderHook } from '@testing-library/react-hooks';
import { createWrapper } from 'spec/helpers/testing-library';
import useLogAction from './useLogAction';
import { LOG_ACTIONS_SQLLAB_COPY_LINK } from './LogUtils';
import { LOG_EVENT } from './actions';
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
test('dispatches logEvent action with static EventData', () => {
const staticEventData = { staticEventKey: 'value1' };
const store = mockStore();
const { result } = renderHook(() => useLogAction(staticEventData), {
wrapper: createWrapper({
useRedux: true,
store,
}),
});
result.current(LOG_ACTIONS_SQLLAB_COPY_LINK, { count: 1 });
store.getActions();
expect(store.getActions()).toEqual([
{
type: LOG_EVENT,
payload: {
eventName: LOG_ACTIONS_SQLLAB_COPY_LINK,
eventData: {
payload: {
...staticEventData,
count: 1,
},
},
},
},
]);
});

View File

@@ -0,0 +1,40 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { logEvent } from 'src/logger/actions';
export default function useLogAction(staticEventData: Record<string, any>) {
const dispatch = useDispatch();
const logAction = useCallback<typeof logEvent>(
(type, payload) =>
dispatch(
logEvent(type, {
payload: {
...staticEventData,
...payload,
},
}),
),
[staticEventData, dispatch],
);
return logAction;
}