Skip to content

Commit a625118

Browse files
committed
COMPASS-414: Adding back missing metrics (#1295)
* COMPASS-414: Adding back missing metrics * Adding crud related metrics tracking
1 parent f919097 commit a625118

File tree

4 files changed

+267
-10
lines changed

4 files changed

+267
-10
lines changed

src/internal-plugins/home/lib/store/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ const HomeStore = Reflux.createStore({
3030
errorMessage: '',
3131
namespace: '',
3232
uiStatus: UI_STATES.INITIAL,
33-
isConnected: false
33+
isConnected: false,
34+
isAtlas: false,
35+
authentication: 'NONE',
36+
ssl: 'NONE',
37+
sshTunnel: 'NONE'
3438
};
3539
},
3640

@@ -51,6 +55,10 @@ const HomeStore = Reflux.createStore({
5155

5256
this.setState({
5357
isConnected: true,
58+
isAtlas: /mongodb\.net/i.test(connection.hostname),
59+
authentication: connection.authentication,
60+
ssl: connection.ssl,
61+
sshTunnel: connection.ssh_tunnel,
5462
uiStatus: UI_STATES.LOADING
5563
});
5664
},

src/internal-plugins/metrics/lib/features.js

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ const features = [
2020
const featureResources = _.object(_.map(features, function(feature) {
2121
const Klass = FeatureResource.extend({
2222
id: feature,
23-
eventTrackers: ['ga', 'intercom', 'stitch']
23+
eventTrackers: ['stitch']
2424
});
2525
return [feature, new Klass()];
2626
}));
2727

2828
// Geo Data uses `detected` as action
2929
const GeoDataResource = FeatureResource.extend({
3030
id: 'Geo Data',
31-
eventTrackers: ['ga', 'intercom', 'stitch'],
31+
eventTrackers: ['stitch'],
3232
detected: function(metadata, callback) {
3333
this._send_event(metadata, callback);
3434
}
@@ -37,7 +37,7 @@ const GeoDataResource = FeatureResource.extend({
3737
// Collection uses `fetched` as action
3838
const CollectionResource = FeatureResource.extend({
3939
id: 'Collection',
40-
eventTrackers: ['ga', 'intercom', 'stitch'],
40+
eventTrackers: ['stitch'],
4141
fetched: function(metadata, callback) {
4242
this._send_event(metadata, callback);
4343
}
@@ -55,21 +55,117 @@ const DeploymentResource = FeatureResource.extend({
5555
// Schema resource uses `sampled` as action
5656
const SchemaResource = BaseResource.extend({
5757
id: 'Schema',
58-
eventTrackers: ['ga', 'intercom', 'stitch'],
58+
eventTrackers: ['stitch'],
5959
sampled: function(metadata, callback) {
6060
this._send_event(metadata, callback);
6161
}
6262
});
6363

64-
// Index resource uses `detected` as action
64+
// Index resource uses `fetched` as action
6565
const IndexesResource = BaseResource.extend({
6666
id: 'Indexes',
67-
eventTrackers: ['ga', 'intercom', 'stitch'],
67+
eventTrackers: ['stitch'],
68+
fetched: function(metadata, callback) {
69+
this._send_event(metadata, callback);
70+
}
71+
});
72+
73+
// Collection Stats uses 'fetched' as action
74+
const CollectionStatsResource = BaseResource.extend({
75+
id: 'Collection Stats',
76+
eventTrackers: ['stitch'],
77+
fetched: function(metadata, callback) {
78+
this._send_event(metadata, callback);
79+
}
80+
});
81+
82+
// Topology resources uses 'detected' as action
83+
const TopologyResource = BaseResource.extend({
84+
id: 'Topology',
85+
eventTrackers: ['stitch'],
6886
detected: function(metadata, callback) {
6987
this._send_event(metadata, callback);
7088
}
7189
});
7290

91+
// Query resources uses 'applied' as action
92+
const QueryResource = BaseResource.extend({
93+
id: 'Query',
94+
eventTrackers: ['stitch'],
95+
applied: function(metadata, callback) {
96+
this._send_event(metadata, callback);
97+
}
98+
});
99+
100+
// Application resources uses 'connected' as action
101+
const ApplicationResource = BaseResource.extend({
102+
id: 'Application',
103+
eventTrackers: ['stitch'],
104+
connected: function(metadata, callback) {
105+
this._send_event(metadata, callback);
106+
}
107+
});
108+
109+
// ValidationRules resources uses 'fetched' as action
110+
const ValidationRulesResource = BaseResource.extend({
111+
id: 'Validation Rules',
112+
eventTrackers: ['stitch'],
113+
fetched: function(metadata, callback) {
114+
this._send_event(metadata, callback);
115+
}
116+
});
117+
118+
// Explain resources uses 'fetched' as action
119+
const ExplainResource = BaseResource.extend({
120+
id: 'Explain',
121+
eventTrackers: ['stitch'],
122+
fetched: function(metadata, callback) {
123+
this._send_event(metadata, callback);
124+
}
125+
});
126+
127+
// Document resources uses 'inserted', 'updated', and 'deleted' as actions
128+
const DocumentResource = BaseResource.extend({
129+
id: 'Document',
130+
eventTrackers: ['stitch'],
131+
inserted: function(metadata, callback) {
132+
this._send_event(metadata, callback);
133+
},
134+
updated: function(metadata, callback) {
135+
this._send_event(metadata, callback);
136+
},
137+
deleted: function(metadata, callback) {
138+
this._send_event(metadata, callback);
139+
}
140+
});
141+
142+
// Documents resources uses 'loaded' as action
143+
const DocumentsResource = BaseResource.extend({
144+
id: 'Documents',
145+
eventTrackers: ['stitch'],
146+
loaded: function(metadata, callback) {
147+
this._send_event(metadata, callback);
148+
}
149+
});
150+
151+
// DocumentsListView resources uses 'paginated' as action
152+
const DocumentsListViewResource = BaseResource.extend({
153+
id: 'Documents List View',
154+
eventTrackers: ['stitch'],
155+
paginated: function(metadata, callback) {
156+
this._send_event(metadata, callback);
157+
}
158+
});
159+
160+
// DocumentsTableView resources uses 'paginated' as action
161+
const DocumentsTableViewResource = BaseResource.extend({
162+
id: 'Documents Table View',
163+
eventTrackers: ['stitch'],
164+
paginated: function(metadata, callback) {
165+
this._send_event(metadata, callback);
166+
}
167+
});
168+
73169
const AutoUpdateResource = BaseResource.extend({
74170
id: 'Auto Update',
75171
eventTrackers: ['ga', 'intercom', 'stitch'],
@@ -99,6 +195,16 @@ featureResources.Collection = new CollectionResource();
99195
featureResources.Deployment = new DeploymentResource();
100196
featureResources.Schema = new SchemaResource();
101197
featureResources.Indexes = new IndexesResource();
198+
featureResources['Collection Stats'] = new CollectionStatsResource();
199+
featureResources.Topology = new TopologyResource();
200+
featureResources.Query = new QueryResource();
201+
featureResources.Application = new ApplicationResource();
202+
featureResources['Validation Rules'] = new ValidationRulesResource();
203+
featureResources.Explain = new ExplainResource();
204+
featureResources.Document = new DocumentResource();
205+
featureResources.Documents = new DocumentsResource();
206+
featureResources.DocumentsListView = new DocumentsListViewResource();
207+
featureResources.DocumentsTableView = new DocumentsTableViewResource();
102208

103209
debug('feature resources', featureResources);
104210

src/internal-plugins/metrics/lib/rules.js

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ module.exports = [
3434
'server architecture': state.instance.host.arch,
3535
'server cpu cores': state.instance.host.cpu_cores,
3636
'server cpu frequency (mhz)': state.instance.host.cpu_frequency / 1000 / 1000,
37-
'server memory size (gb)': state.instance.host.memory_bits / 1024 / 1024 / 1024
37+
'server memory (gb)': state.instance.host.memory_bits / 1024 / 1024 / 1024,
38+
'server os': state.instance.host.os,
39+
'server arch': state.instance.host.arch,
40+
'server os family': state.instance.host.os_family,
41+
'server machine model': state.instance.host.machine_model,
42+
'server kernel version': state.instance.host.kernel_version,
43+
'server kernel version string': state.instance.host.kernel_version_string
3844
})
3945
},
4046
{
@@ -49,6 +55,136 @@ module.exports = [
4955
'schema depth': schemaStats.depth(state.schema),
5056
'schema branching factors': schemaStats.branch(state.schema)
5157
})
58+
},
59+
{
60+
store: 'DeploymentAwareness.Store',
61+
resource: 'Topology',
62+
action: 'detected',
63+
condition: () => true,
64+
metadata: (state) => ({
65+
'topology type': state.topologyType,
66+
'server count': state.servers.length,
67+
'server types': state.servers.map(server => server.type)
68+
})
69+
},
70+
{
71+
store: 'CollectionStats.Store',
72+
resource: 'Collection Stats',
73+
action: 'fetched',
74+
condition: () => true,
75+
metadata: (state) => ({
76+
'document count': state.documentCount,
77+
'total document size kb': state.totalDocumentSize,
78+
'avg document size kb': state.avgDocumentSize,
79+
'index count': state.indexCount,
80+
'total index size kb': state.totalIndexSize,
81+
'avg index size kb': state.avgIndexSize
82+
})
83+
},
84+
{
85+
store: 'Indexes.LoadIndexesStore',
86+
resource: 'Indexes',
87+
action: 'fetched',
88+
condition: () => true,
89+
multi: true,
90+
metadata: (state) => ({
91+
'index type': state.type,
92+
'usage count': state.usageCount,
93+
'cardinality': state.cardinality,
94+
'properties': state.properties
95+
})
96+
},
97+
{
98+
store: 'Query.QueryStore',
99+
resource: 'Query',
100+
action: 'applied',
101+
condition: (state) => state.queryState === 'apply',
102+
metadata: (state) => ({
103+
'filter': state.filter,
104+
'project': state.project,
105+
'sort': state.sort,
106+
'skip': state.skip,
107+
'limit': state.limit
108+
})
109+
},
110+
{
111+
store: 'Home.HomeStore',
112+
resource: 'Application',
113+
action: 'connected',
114+
condition: (state) => state.isConnected === true,
115+
metadata: (state) => ({
116+
'is atlas': state.isAtlas,
117+
'authentication method': state.authentication,
118+
'ssl method': state.ssl,
119+
'ssh tunnel method': state.sshTunnel
120+
})
121+
},
122+
{
123+
store: 'Validation.Store',
124+
resource: 'Validation Rules',
125+
action: 'fetched',
126+
condition: () => true,
127+
metadata: (state) => ({
128+
'rule count': state.validationRules.length,
129+
'validation level': state.validationLevel,
130+
'validation action': state.validationAction
131+
})
132+
},
133+
{
134+
store: 'Explain.Store',
135+
resource: 'Explain',
136+
action: 'fetched',
137+
condition: () => true,
138+
metadata: (state) => ({
139+
'view mode': state.viewType,
140+
'execution time ms': state.executionTimeMillis,
141+
'in memory sort': state.inMemorySort,
142+
'is collection scan': state.isCollectionScan,
143+
'is covered': state.isCovered,
144+
'is multi key': state.isMultiKey,
145+
'is sharded': state.isSharded,
146+
'index type': state.indexType,
147+
'index': state.index,
148+
'number of docs returned': state.nReturned,
149+
'number of shards': state.numShards,
150+
'total docs examined': state.totalDocsExamined,
151+
'total keys examined': state.totalKeysExamined,
152+
'index used': state.usedIndex
153+
})
154+
},
155+
{
156+
store: 'CRUD.InsertDocumentStore',
157+
resource: 'Document',
158+
action: 'inserted',
159+
condition: () => true,
160+
metadata: () => ({})
161+
},
162+
{
163+
store: 'CRUD.RemoveDocumentStore',
164+
resource: 'Document',
165+
action: 'deleted',
166+
condition: () => true,
167+
metadata: () => ({})
168+
},
169+
{
170+
store: 'CRUD.ResetDocumentListStore',
171+
resource: 'Documents',
172+
action: 'loaded',
173+
condition: () => true,
174+
metadata: () => ({})
175+
},
176+
{
177+
store: 'CRUD.LoadMoreDocumentsStore',
178+
resource: 'Documents List View',
179+
action: 'paginated',
180+
condition: () => true,
181+
metadata: () => ({})
182+
},
183+
{
184+
store: 'CRUD.PageChangedStore',
185+
resource: 'Documents Table View',
186+
action: 'paginated',
187+
condition: () => true,
188+
metadata: () => ({})
52189
}
53-
54190
];

src/internal-plugins/metrics/lib/store.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ const MetricsStore = Reflux.createStore({
2727
store.listen((state) => {
2828
// only track an event if the rule condition evaluates to true
2929
if (rule.condition(state)) {
30-
metrics.track(rule.resource, rule.action, rule.metadata(state));
30+
// Some stores trigger with arrays of data.
31+
if (rule.multi) {
32+
state.forEach((s) => {
33+
metrics.track(rule.resource, rule.action, rule.metadata(s));
34+
});
35+
} else {
36+
metrics.track(rule.resource, rule.action, rule.metadata(state));
37+
}
3138
}
3239
});
3340
});

0 commit comments

Comments
 (0)