ktmud commented on a change in pull request #10815:
URL:
https://github.com/apache/incubator-superset/pull/10815#discussion_r485803045
##########
File path: superset-frontend/src/logger/actions/index.ts
##########
@@ -16,10 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+import { Dispatch } from 'react-redux';
+
export const LOG_EVENT = 'LOG_EVENT';
-export function logEvent(eventName, eventData) {
- return dispatch =>
+export function logEvent(eventName: string, eventData: Record<string, any>) {
Review comment:
E.g.
```diff
diff --git a/superset-frontend/src/chart/Chart.jsx
b/superset-frontend/src/chart/Chart.jsx
index 118cfe18f..c1a1f8f25 100644
--- a/superset-frontend/src/chart/Chart.jsx
+++ b/superset-frontend/src/chart/Chart.jsx
@@ -20,9 +20,9 @@ import PropTypes from 'prop-types';
import React from 'react';
import { Alert } from 'react-bootstrap';
import { styled, logging } from '@superset-ui/core';
+import { getTimeSincePageLoad, LOG_EVENTS } from 'src/logger';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
-import { Logger, LOG_ACTIONS_RENDER_CHART } from '../logger/LogUtils';
import Loading from '../components/Loading';
import RefreshChartOverlay from '../components/RefreshChartOverlay';
import ErrorMessageWithStackTrace from
'../components/ErrorMessage/ErrorMessageWithStackTrace';
@@ -138,13 +138,13 @@ class Chart extends React.PureComponent {
info ? info.componentStack : null,
);
- actions.logEvent(LOG_ACTIONS_RENDER_CHART, {
+ actions.logEvent(LOG_EVENTS.load_chart, {
slice_id: chartId,
has_err: true,
error_details: error.toString(),
start_offset: this.renderStartTime,
ts: new Date().getTime(),
- duration: Logger.getTimestamp() - this.renderStartTime,
+ duration: getTimeSincePageLoad() - this.renderStartTime,
});
}
diff --git a/superset-frontend/src/chart/ChartContainer.jsx
b/superset-frontend/src/chart/ChartContainer.jsx
index f509281f3..28f41a645 100644
--- a/superset-frontend/src/chart/ChartContainer.jsx
+++ b/superset-frontend/src/chart/ChartContainer.jsx
@@ -18,9 +18,9 @@
*/
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
+import { logEvent } from 'src/logger';
import * as actions from './chartAction';
-import { logEvent } from '../logger/actions';
import Chart from './Chart';
function mapDispatchToProps(dispatch) {
diff --git a/superset-frontend/src/chart/chartAction.js
b/superset-frontend/src/chart/chartAction.js
index fb19186cb..909dd19d7 100644
--- a/superset-frontend/src/chart/chartAction.js
+++ b/superset-frontend/src/chart/chartAction.js
@@ -20,6 +20,7 @@
/* eslint no-param-reassign: ["error", { "props": false }] */
import moment from 'moment';
import { t, SupersetClient } from '@superset-ui/core';
+import { logEvent } from 'src/logger';
import { isFeatureEnabled, FeatureFlag } from '../featureFlags';
import {
getAnnotationJsonUrl,
@@ -36,7 +37,6 @@ import {
} from '../modules/AnnotationTypes';
import { addDangerToast } from '../messageToasts/actions';
-import { logEvent } from '../logger/actions';
import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger/LogUtils';
import getClientErrorObject from '../utils/getClientErrorObject';
import { allowCrossDomain as domainShardingEnabled } from
'../utils/hostNamesConfig';
@@ -357,7 +357,7 @@ export function exploreJSON(
// For now just use the first result.
const result = response.result[0];
dispatch(
- logEvent(LOG_ACTIONS_LOAD_CHART, {
+ logEvent('load_chart', {
slice_id: key,
is_cached: result.is_cached,
force_refresh: force,
@@ -379,7 +379,7 @@ export function exploreJSON(
.catch(response => {
const appendErrorLog = (errorDetails, isCached) => {
dispatch(
- logEvent(LOG_ACTIONS_LOAD_CHART, {
+ logEvent('load_chart', {
slice_id: key,
has_err: true,
is_cached: isCached,
diff --git a/superset-frontend/src/logger/LogUtils.js
b/superset-frontend/src/logger/LogUtils.js
deleted file mode 100644
index 17e4a0f69..000000000
--- a/superset-frontend/src/logger/LogUtils.js
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.
- */
-// Log event names
------------------------------------------------------------
-export const LOG_ACTIONS_LOAD_CHART = 'load_chart';
-export const LOG_ACTIONS_RENDER_CHART = 'render_chart';
-export const LOG_ACTIONS_HIDE_BROWSER_TAB = 'hide_browser_tab';
-
-export const LOG_ACTIONS_MOUNT_DASHBOARD = 'mount_dashboard';
-export const LOG_ACTIONS_MOUNT_EXPLORER = 'mount_explorer';
-
-export const LOG_ACTIONS_SELECT_DASHBOARD_TAB = 'select_dashboard_tab';
-export const LOG_ACTIONS_FORCE_REFRESH_CHART = 'force_refresh_chart';
-export const LOG_ACTIONS_CHANGE_EXPLORE_CONTROLS =
'change_explore_controls';
-export const LOG_ACTIONS_TOGGLE_EDIT_DASHBOARD = 'toggle_edit_dashboard';
-export const LOG_ACTIONS_FORCE_REFRESH_DASHBOARD =
'force_refresh_dashboard';
-export const LOG_ACTIONS_PERIODIC_RENDER_DASHBOARD =
- 'periodic_render_dashboard';
-export const LOG_ACTIONS_EXPLORE_DASHBOARD_CHART =
'explore_dashboard_chart';
-export const LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART =
- 'export_csv_dashboard_chart';
-export const LOG_ACTIONS_CHANGE_DASHBOARD_FILTER =
'change_dashboard_filter';
-export const LOG_ACTIONS_OMNIBAR_TRIGGERED = 'omnibar_triggered';
-
-// Log event types
--------------------------------------------------------------
-export const LOG_EVENT_TYPE_TIMING = new Set([
- LOG_ACTIONS_LOAD_CHART,
- LOG_ACTIONS_RENDER_CHART,
- LOG_ACTIONS_HIDE_BROWSER_TAB,
-]);
-export const LOG_EVENT_TYPE_USER = new Set([
- LOG_ACTIONS_MOUNT_DASHBOARD,
- LOG_ACTIONS_SELECT_DASHBOARD_TAB,
- LOG_ACTIONS_EXPLORE_DASHBOARD_CHART,
- LOG_ACTIONS_FORCE_REFRESH_CHART,
- LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART,
- LOG_ACTIONS_CHANGE_DASHBOARD_FILTER,
- LOG_ACTIONS_CHANGE_EXPLORE_CONTROLS,
- LOG_ACTIONS_TOGGLE_EDIT_DASHBOARD,
- LOG_ACTIONS_FORCE_REFRESH_DASHBOARD,
- LOG_ACTIONS_PERIODIC_RENDER_DASHBOARD,
- LOG_ACTIONS_OMNIBAR_TRIGGERED,
- LOG_ACTIONS_MOUNT_EXPLORER,
-]);
-
-export const Logger = {
- // note that this returns ms since page load, NOT ms since epoc
- getTimestamp() {
- return Math.round(window.performance.now());
- },
-};
diff --git a/superset-frontend/src/logger/actions/index.js
b/superset-frontend/src/logger/actions/index.js
deleted file mode 100644
index f319068e6..000000000
--- a/superset-frontend/src/logger/actions/index.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.
- */
-export const LOG_EVENT = 'LOG_EVENT';
-
-export function logEvent(eventName, eventData) {
- return dispatch =>
- dispatch({
- type: LOG_EVENT,
- payload: {
- eventName,
- eventData,
- },
- });
-}
diff --git a/superset-frontend/src/logger/constants.ts
b/superset-frontend/src/logger/constants.ts
new file mode 100644
index 000000000..f30814469
--- /dev/null
+++ b/superset-frontend/src/logger/constants.ts
@@ -0,0 +1,42 @@
+export const LOG_EVENTS = {
+ load_chart: 'load_chart',
+ render_chart: 'render_chart',
+ hide_browser_tab: 'hide_browser_tab',
+ mount_dashboard: 'mount_dashboard',
+ mount_explorer: 'mount_explorer',
+ select_dashboard_tab: 'select_dashboard_tab',
+ force_refresh_chart: 'force_refresh_chart',
+ change_explore_controls: 'change_explore_controls',
+ toggle_edit_dashboard: 'toggle_edit_dashboard',
+ force_refresh_dashboard: 'force_refresh_dashboard',
+ periodic_render_dashboard: 'periodic_render_dashboard',
+ explore_dashboard_chart: 'explore_dashboard_chart',
+ export_csv_dashboard_chart: 'export_csv_dashboard_chart',
+ change_dashboard_filter: 'change_dashboard_filter',
+ omnibar_triggered: 'omnibar_triggered',
+};
+
+export type LogEventName = keyof typeof LOG_EVENTS;
+
+export type LogEventPayload<T> = Record<string, any>;
+
+// Log event types
--------------------------------------------------------------
+export const LOG_TIMING_EVENTS = new Set([
+ LOG_EVENTS.load_chart,
+ LOG_EVENTS.render_chart,
+ LOG_EVENTS.hide_browser_tab,
+]);
+export const LOG_USER_ACTION_EVENTS = new Set([
+ LOG_EVENTS.mount_dashboard,
+ LOG_EVENTS.select_dashboard_tab,
+ LOG_EVENTS.explore_dashboard_chart,
+ LOG_EVENTS.force_refresh_chart,
+ LOG_EVENTS.export_csv_dashboard_chart,
+ LOG_EVENTS.change_dashboard_filter,
+ LOG_EVENTS.change_explore_controls,
+ LOG_EVENTS.toggle_edit_dashboard,
+ LOG_EVENTS.force_refresh_dashboard,
+ LOG_EVENTS.periodic_render_dashboard,
+ LOG_EVENTS.omnibar_triggered,
+ LOG_EVENTS.mount_explorer,
+]);
diff --git a/superset-frontend/src/logger/index.ts
b/superset-frontend/src/logger/index.ts
new file mode 100644
index 000000000..c9a5120ed
--- /dev/null
+++ b/superset-frontend/src/logger/index.ts
@@ -0,0 +1,28 @@
+import { Dispatch } from 'react-redux';
+import { LogEventName, LogEventPayload } from './constants';
+
+export * from './constants';
+
+export const LOG_EVENT = 'LOG_EVENT';
+
+/**
+ * Rounded milliseconds since page load started.
+ * Ref: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
+ */
+export function getTimeSincePageLoad() {
+ return Math.round(window.performance.now());
+}
+
+export function logEvent<T extends LogEventName>(
+ eventName: T,
+ eventData: LogEventPayload<T>,
+) {
+ return (dispatch: Dispatch<never>) =>
+ dispatch({
+ type: LOG_EVENT,
+ payload: {
+ eventName,
+ eventData,
+ },
+ });
+}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]