graceguo-supercat commented on a change in pull request #4226: add frontend
logging functions and log loading time for Dashboard and explore view
URL:
https://github.com/apache/incubator-superset/pull/4226#discussion_r162804217
##########
File path: superset/assets/javascripts/logger.js
##########
@@ -0,0 +1,79 @@
+import $ from 'jquery';
+
+export const LOG_ACTIONS_LOAD_DASHBOARD = 'load_dashboard';
+export const LOG_ACTIONS_LOAD_EXPLORE = 'load_explore';
+export const LOAD_EVENT = 'load';
+
+export class ActionLog {
+ constructor({ action, containerId, eventName }) {
+ this.containerId = containerId;
+ this.action = action;
+ this.eventName = eventName;
+ this.startAt = 0;
+ this.duration = 0;
+ this.events = [];
+
+ this.addEvent = this.addEvent.bind(this);
+ }
+
+ setAttribute(name, value) {
+ this[name] = value;
+ }
+
+ addEvent(eventBody) {
+ this.events.push(eventBody);
+ }
+}
+
+const handlers = {};
+
+export default {
+ start(log) {
+ log.setAttribute('startAt', this.getTimestamp());
+ if (!handlers[log.eventName]) {
+ handlers[log.eventName] = [];
+ }
+ handlers[log.eventName].push(log.addEvent);
+ },
+
+ append(eventName, eventBody) {
+ return handlers[eventName].length &&
+ handlers[eventName].forEach((handler) => {
+ handler(eventBody);
+ });
+ },
+
+ end(log) {
+ log.setAttribute('duration', this.getTimestamp() - log.startAt);
+ this.send(log);
+
+ if (handlers[log.eventName].length) {
+ const index = handlers[log.eventName].findIndex(handler => (handler ===
log.addEvent));
+ handlers[log.eventName].splice(index, 1);
+ }
+ },
+
+ send(log) {
+ const { action, containerId, events, startAt, duration } = log;
+ const url = `/superset/${action}/?${action === LOG_ACTIONS_LOAD_DASHBOARD
? 'dashboard_id' : 'slice_id'}=${containerId}`;
Review comment:
i changed the way tracking type of load actions. i added `source` and
`sourceId` attributes in ActionLog instance.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services