mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-30 02:28:53 +00:00
Merge pull request #991 from balena-io/990-mixpanel-switch
Add a controlling variable for mixpanel reporting
This commit is contained in:
commit
2ae71ab007
@ -166,6 +166,10 @@ export const schemaTypes = {
|
||||
type: PermissiveBoolean,
|
||||
default: false,
|
||||
},
|
||||
mixpanelReport: {
|
||||
type: PermissiveBoolean,
|
||||
default: true,
|
||||
},
|
||||
|
||||
// Function schema types
|
||||
// The type should be the value that the promise resolves
|
||||
|
@ -190,6 +190,11 @@ export const schema = {
|
||||
mutable: true,
|
||||
removeIfNull: false,
|
||||
},
|
||||
mixpanelReport: {
|
||||
source: 'db',
|
||||
mutable: true,
|
||||
removeIfNull: false,
|
||||
},
|
||||
};
|
||||
|
||||
export type Schema = typeof schema;
|
||||
|
@ -129,6 +129,11 @@ export class DeviceConfig {
|
||||
defaultValue: 'false',
|
||||
rebootRequired: true,
|
||||
},
|
||||
mixpanelReport: {
|
||||
envVarName: 'SUPERVISOR_MIXPANEL_REPORT',
|
||||
varType: 'bool',
|
||||
defaultValue: 'true',
|
||||
},
|
||||
};
|
||||
|
||||
public static validKeys = [
|
||||
|
@ -1,10 +1,10 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import mask = require('json-mask');
|
||||
import * as _ from 'lodash';
|
||||
import * as memoizee from 'memoizee';
|
||||
|
||||
import Mixpanel = require('mixpanel');
|
||||
|
||||
import Config from './config';
|
||||
import supervisorVersion = require('./lib/supervisor-version');
|
||||
|
||||
export type EventTrackProperties = Dictionary<any>;
|
||||
@ -14,6 +14,7 @@ interface InitArgs {
|
||||
unmanaged: boolean;
|
||||
mixpanelHost: { host: string; path: string } | null;
|
||||
mixpanelToken: string;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
// The minimum amount of time to wait between sending
|
||||
@ -34,31 +35,45 @@ const mixpanelMask = [
|
||||
export class EventTracker {
|
||||
private defaultProperties: EventTrackProperties | null;
|
||||
private client: any;
|
||||
private isEnabled: boolean = true;
|
||||
|
||||
public constructor() {
|
||||
this.client = null;
|
||||
this.defaultProperties = null;
|
||||
}
|
||||
|
||||
public init({
|
||||
public async init({
|
||||
unmanaged,
|
||||
mixpanelHost,
|
||||
mixpanelToken,
|
||||
uuid,
|
||||
}: InitArgs): Bluebird<void> {
|
||||
return Bluebird.try(() => {
|
||||
this.defaultProperties = {
|
||||
distinct_id: uuid,
|
||||
uuid,
|
||||
supervisorVersion,
|
||||
};
|
||||
if (unmanaged || mixpanelHost == null) {
|
||||
return;
|
||||
config,
|
||||
}: InitArgs): Promise<void> {
|
||||
this.defaultProperties = {
|
||||
distinct_id: uuid,
|
||||
uuid,
|
||||
supervisorVersion,
|
||||
};
|
||||
if (unmanaged || mixpanelHost == null) {
|
||||
return;
|
||||
}
|
||||
this.client = Mixpanel.init(mixpanelToken, {
|
||||
host: mixpanelHost.host,
|
||||
path: mixpanelHost.path,
|
||||
});
|
||||
|
||||
this.isEnabled = await config.get('mixpanelReport');
|
||||
console.log(
|
||||
`Mixpanel reporting is ${this.isEnabled ? 'enabled' : 'disabled'}`,
|
||||
);
|
||||
config.on('change', conf => {
|
||||
const mixpanelReport = conf.mixpanelReport;
|
||||
if (mixpanelReport != null && mixpanelReport !== this.isEnabled) {
|
||||
this.isEnabled = mixpanelReport;
|
||||
console.log(
|
||||
`${mixpanelReport ? 'A' : 'Dea'}ctivating mixpanel reporting`,
|
||||
);
|
||||
}
|
||||
this.client = Mixpanel.init(mixpanelToken, {
|
||||
host: mixpanelHost.host,
|
||||
path: mixpanelHost.path,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -79,7 +94,7 @@ export class EventTracker {
|
||||
// Don't send potentially sensitive information, by using a whitelist
|
||||
properties = mask(properties, mixpanelMask);
|
||||
this.logEvent('Event:', event, JSON.stringify(properties));
|
||||
if (this.client == null) {
|
||||
if (this.client == null || !this.isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
_ = require 'lodash'
|
||||
|
||||
EventEmitter = require 'events'
|
||||
|
||||
{ EventTracker } = require './event-tracker'
|
||||
@ -64,7 +66,7 @@ module.exports = class Supervisor extends EventEmitter
|
||||
# so we leave a trail of breadcrumbs in the logs in case runtime
|
||||
# fails to get to the first dashboard logs
|
||||
console.log('Starting event tracker')
|
||||
@eventTracker.init(conf)
|
||||
@eventTracker.init(_.assign({}, conf, { @config }))
|
||||
.then =>
|
||||
console.log('Starting up api binder')
|
||||
@apiBinder.initClient()
|
||||
|
@ -45,6 +45,7 @@ testTarget1 = {
|
||||
'SUPERVISOR_LOCAL_MODE': 'false'
|
||||
'SUPERVISOR_LOG_CONTROL': 'true'
|
||||
'SUPERVISOR_OVERRIDE_LOCK': 'false'
|
||||
'SUPERVISOR_MIXPANEL_REPORT': 'true'
|
||||
'SUPERVISOR_POLL_INTERVAL': '60000'
|
||||
'SUPERVISOR_VPN_CONTROL': 'true'
|
||||
'SUPERVISOR_PERSISTENT_LOGGING': 'false'
|
||||
@ -130,6 +131,7 @@ testTargetWithDefaults2 = {
|
||||
'SUPERVISOR_OVERRIDE_LOCK': 'false'
|
||||
'SUPERVISOR_POLL_INTERVAL': '60000'
|
||||
'SUPERVISOR_VPN_CONTROL': 'true'
|
||||
'SUPERVISOR_MIXPANEL_REPORT': 'true'
|
||||
'SUPERVISOR_PERSISTENT_LOGGING': 'false'
|
||||
}
|
||||
apps: {
|
||||
|
@ -42,6 +42,9 @@ describe 'EventTracker', ->
|
||||
mixpanelToken: 'someToken'
|
||||
uuid: 'barbaz'
|
||||
mixpanelHost: { host: '', path: '' }
|
||||
config:
|
||||
get: -> Promise.resolve(true)
|
||||
on: ->
|
||||
})
|
||||
expect(promise).to.be.fulfilled
|
||||
.then =>
|
||||
|
@ -177,6 +177,7 @@ describe 'DeviceConfig', ->
|
||||
SUPERVISOR_DELTA_APPLY_TIMEOUT: '0',
|
||||
SUPERVISOR_DELTA_RETRY_COUNT: '30',
|
||||
SUPERVISOR_DELTA_RETRY_INTERVAL: '10000',
|
||||
SUPERVISOR_MIXPANEL_REPORT: 'true'
|
||||
SUPERVISOR_DELTA_VERSION: '2',
|
||||
SUPERVISOR_INSTANT_UPDATE_TRIGGER: 'true',
|
||||
SUPERVISOR_OVERRIDE_LOCK: 'false',
|
||||
|
Loading…
Reference in New Issue
Block a user