Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

RVM-906: Rvm Core Analytics Pipeline #925

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/browser/rvm/rvm_message_bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { WMCopyData } from '../transport';
import { EventEmitter } from 'events';
import * as log from '../log';
import route from '../../common/route';
import { argo } from '../core_state';
import { argo, getConfigUrlByUuid } from '../core_state';

import { app } from 'electron';
import { Identity } from '../api_protocol/transport_strategy/api_transport_base';
const _ = require('underscore');

const processVersions = <any> process.versions;
Expand Down Expand Up @@ -173,13 +174,27 @@ export interface Cleanup extends RvmMsgBase {
// topic: system -----
type systemTopic = 'system';
type getRvmInfoAction = 'get-rvm-info';
type sendCoreAnalyticsEvent = 'send-core-analytics-event';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:neckbeard: This is the same name as the function, not sure if that was intentional


export interface System extends RvmMsgBase {
topic: systemTopic;
action: getRvmInfoAction;
sourceUrl: string;
}

interface CoreAnalytics extends RvmMsgBase {
topic: systemTopic;
action: sendCoreAnalyticsEvent;
sourceUrl: string;
diagnosticsEvent: AnalyticsEvent;
}

interface AnalyticsEvent {
topic: string;
event: string;
createdAt: string;
payload?: any;
}

// topic: application-events -----
type EventType = 'started'| 'closed' | 'ready' | 'run-requested' | 'crashed' | 'error' | 'not-responding';
Expand Down Expand Up @@ -415,6 +430,35 @@ export class RVMMessageBus extends EventEmitter {
};
this.publish(rvmPayload, callback);
}

public sendCoreAnalyticsEvent(event: string, payload: any, identity?: Identity): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually use this yet, are there plans to use it soon?

let sourceUrl = '';
let uuid: string;
if (typeof identity === 'object' && identity.uuid) {
sourceUrl = getConfigUrlByUuid(identity.uuid);
uuid = identity.uuid;
}

return new Promise((resolve, reject) => {
try {
const rvmMsg: CoreAnalytics = {
topic: 'system',
action: 'send-core-analytics-event',
sourceUrl,
...uuid ? { uuid } : {},
diagnosticsEvent: {
event,
topic: 'analytics.core.event',
createdAt: new Date().toISOString(),
payload
}
};
this.publish(rvmMsg, resolve);
} catch (err) {
reject(err);
}
});
}
}
const rvmMessageBus = new RVMMessageBus();
export {rvmMessageBus};