Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"mongodb": "^2.2.8",
"mongodb-collection-model": "^0.3.1",
"mongodb-connection-model": "^6.3.3",
"mongodb-data-service": "^2.1.7",
"mongodb-data-service": "^2.2.0",
"mongodb-database-model": "^0.1.2",
"mongodb-explain-plan-model": "^0.2.2",
"mongodb-extended-json": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class DBErrorComponent extends React.Component {
this.setState({ data: data });
}

renderErrors() {
renderErrors() { // TODO: display srcName
const rows = this.state.data.map(function(row, i) {
return (
<li className="rt-errors__item" key={`list-item-${i}`}>
<div className="rt-errors__operror"><text>&#9888; Command {row.ops} returned error: </text><text className="rt-errors__bold">{row.errorMsg}</text></div>
<div className="rt-errors__operror"><text>&#9888; Command &#34;{row.ops}&#34; returned error </text><text className="rt-errors__bold">&#34;{row.errorMsg}&#34;</text></div>
</li>
);
});
Expand Down
54 changes: 36 additions & 18 deletions src/internal-packages/server-stats/lib/store/current-op-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CurrentOpStore = Reflux.createStore({
this.inOverlay = false;
this.xLength = 60;
this.starting = true;
this.error = null;
this.errored = [];
},

pause: function() {
Expand All @@ -44,31 +44,50 @@ const CurrentOpStore = Reflux.createStore({
mouseOver: function(index) {
const startPause = Math.max(this.endPause - this.xLength, 0);
const visOps = this.allOps.slice(startPause, this.endPause);
const visErrors = this.errored.slice(startPause, this.endPause);
if (index >= visOps.length) {
index = visOps.length - 1;
}
this.overlayIndex = index;
this.inOverlay = true;
this.trigger(null, visOps[this.overlayIndex]);
this.trigger(visErrors[this.overlayIndex], visOps[this.overlayIndex]);
},

mouseOut: function() {
this.inOverlay = false;
const startPause = Math.max(this.endPause - this.xLength, 0);
const visOps = this.allOps.slice(startPause, this.endPause);
this.trigger(this.error, visOps[visOps.length - 1]);
const visErrors = this.errored.slice(startPause, this.endPause);
this.trigger(visErrors[this.overlayIndex], visOps[visOps.length - 1]);
},

currentOp: function() {
app.dataService.currentOp(false, (error, response) => {
// Trigger error banner changes
if (error === null && this.errored.length > 0 && this.errored[this.errored.length - 1] !== null) { // Trigger error removal
Actions.dbError({'op': 'currentOp', 'error': null });
} else if (error !== null) {
Actions.dbError({'op': 'currentOp', 'error': error });
}
this.errored.push(error);

// Update op list if error
if (error !== null || this.starting) {
this.allOps.push([]);
}

// Update op list if no error
let totals = [];
this.error = error;
if (!error && response !== undefined && ('inprog' in response)) {
if (error === null) {
// If response is empty, send empty list
let doc = [];
if (response !== undefined && ('inprog' in response)) {
doc = response.inprog;
}
if (this.starting) { // Skip first to match charts
this.starting = false;
this.starting = false; // TODO: skip first error as well?
return;
}
const doc = response.inprog;
for (let i = 0; i < doc.length; i++) {
if (toNS(doc[i].ns).specialish) {
continue;
Expand Down Expand Up @@ -100,17 +119,16 @@ const CurrentOpStore = Reflux.createStore({
});
// Add current state to all
this.allOps.push(totals);
if (this.isPaused) {
totals = this.allOps[this.endPause];
} else {
this.endPause = this.allOps.length;
}
// This handled by mouseover function completely
if (this.inOverlay) {
return;
}
} else if (error) {
Actions.dbError({'op': 'currentOp', 'error': error });
}
if (this.isPaused) {
totals = this.allOps[this.endPause];
error = this.errored[this.endPause];
} else {
this.endPause = this.allOps.length;
}
// This handled by mouseover function completely
if (this.inOverlay) {
return;
}
this.trigger(error, totals);
});
Expand Down
55 changes: 38 additions & 17 deletions src/internal-packages/server-stats/lib/store/dberror-store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Reflux = require('reflux');
const Actions = require('../action');
const translate = require('mongodb-js-errors').translate;
// const debug = require('debug')('mongodb-compass:server-stats:dberror-store');

const DBErrorStore = Reflux.createStore({
Expand All @@ -11,27 +12,47 @@ const DBErrorStore = Reflux.createStore({
},

restart: function() {
this.ops = {'top': null, 'currentOp': null, 'serverStatus': null};
this.errors = {};
this.ops = {top: null, currentOp: null, serverStatus: null};
this.srcName = {top: 'Hottest Collections', currentOp: 'Slowest Operations', serverStatus: 'Stats Charts'};
},

dbError: function(data) {
// New or different error
const err = data.error.name + ': ' + data.error.message;
if (this.ops[data.op] !== err) {
this.ops[data.op] = err;
if (err in this.errors) {
this.errors[err] = this.errors[err] + ', ' + data.op;
} else {
this.errors[err] = data.op;
}
const msg = [];
for (let key in this.errors) { // eslint-disable-line prefer-const
if (this.errors.hasOwnProperty( key ) ) {
msg.push({'errorMsg': key, 'ops': this.errors[key], 'type': this.errors});
/**
* Translates the error message to something human readable. From data-service.
*
* @param {Error} error - The error.
*
* @returns {Error} The error with message translated.
*/
_translateMessage(error) {
const mapping = translate(error);
if (mapping) {
error.message = mapping.message;
}
return error;
},

publish: function() {
const msg = [];
for (let key in this.ops) { // eslint-disable-line prefer-const
if (this.ops.hasOwnProperty( key ) ) {
if (this.ops[key] !== null) {
msg.push({errorMsg: this._translateMessage(this.ops[key]).message, ops: key, type: this.ops[key].name, srcName: this.srcName[key]});
}
}
this.trigger(msg);
}
this.trigger(msg);
},

dbError: function(data) {
// Remove previous error
if (this.ops[data.op] !== null && data.error === null) {
this.ops[data.op] = data.error;
this.publish();
}
// New error
if (data.error !== null && this.ops[data.op] !== data.error) {
this.ops[data.op] = data.error;
this.publish();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const ServerStatsStore = Reflux.createStore({

serverStats: function() {
app.dataService.serverstats((error, doc) => {
this.trigger(error, doc, this.isPaused);
if (error) {
Actions.dbError({ 'op': 'serverStatus', 'error': error });
if (error === null && this.error !== null) { // Trigger error removal
Actions.dbError({'op': 'serverStatus', 'error': null });
} else if (error !== null) {
Actions.dbError({'op': 'serverStatus', 'error': error });
}
this.trigger(error, doc, this.isPaused);
});
},

Expand Down
113 changes: 36 additions & 77 deletions src/internal-packages/server-stats/lib/store/top-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const TopStore = Reflux.createStore({

restart: function() {
this.allOps = [];
this.errored = [];
this.isPaused = false;
this.endPause = 0;
this.overlayIndex = 0;
this.inOverlay = false;
this.xLength = 60;
this.starting = true;
this.error = null;
this.t1s = {};
},

Expand All @@ -45,31 +45,49 @@ const TopStore = Reflux.createStore({
mouseOver: function(index) {
const startPause = Math.max(this.endPause - this.xLength, 0);
const visOps = this.allOps.slice(startPause, this.endPause);
const visErrors = this.errored.slice(startPause, this.endPause);
if (index >= visOps.length) {
index = visOps.length - 1;
}
this.overlayIndex = index;
this.inOverlay = true;
this.trigger(null, visOps[this.overlayIndex]);
this.trigger(visErrors[this.overlayIndex], visOps[this.overlayIndex]);
},

mouseOut: function() {
this.inOverlay = false;
const startPause = Math.max(this.endPause - this.xLength, 0);
const visOps = this.allOps.slice(startPause, this.endPause);
this.trigger(this.error, visOps[visOps.length - 1]);
const visErrors = this.errored.slice(startPause, this.endPause);
this.trigger(visErrors[this.overlayIndex], visOps[visOps.length - 1]);
},

// Calculate list as current hottest collection (like Cloud and system top)
top_delta: function() {
app.dataService.top((error, response) => {
const numCores = app.instance.host.cpu_cores;
const cadence = 1000000; // Can safetly assume we're polling 1x/sec TODO
const t2s = {};
// Trigger error banner changes
if (error === null && this.errored.length > 0 && this.errored[this.errored.length - 1] !== null) { // Trigger error removal
Actions.dbError({'op': 'top', 'error': null });
} else if (error !== null) {
Actions.dbError({'op': 'top', 'error': error });
}
this.errored.push(error);
// Update op list if error
if (error !== null || this.starting) {
this.allOps.push([]);
}

// Update op list if no error
let totals = [];
this.error = error;
if (!error && response !== undefined && ('totals' in response)) {
const doc = response.totals;
if (error === null) {
// If response is empty, send empty list
let doc = {};
if (response !== undefined && ('totals' in response)) {
doc = response.totals;
}
const numCores = app.instance.host.cpu_cores;
const cadence = 1000000; // Can safetly assume we're polling 1x/sec TODO
const t2s = {};
for (let collname in doc) { // eslint-disable-line prefer-const
// Ignore special collections
if (!doc.hasOwnProperty(collname) || collname === 'note' || toNS(collname).specialish) {
Expand Down Expand Up @@ -119,75 +137,16 @@ const TopStore = Reflux.createStore({
});
// Add current state to all
this.allOps.push(totals);
if (this.isPaused) {
totals = this.allOps[this.endPause];
} else {
this.endPause = this.allOps.length;
}
// This handled by mouseover function completely
if (this.inOverlay) {
return;
}
} else if (error) {
Actions.dbError({ 'op': 'top', 'error': error });
}
this.trigger(error, totals);
});
},

// Calculate list as all-time hottest collections
top: function() {
app.dataService.top((error, response) => {
let totals = [];
this.error = error;
if (!error && response !== undefined && ('totals' in response)) {
if (this.starting) { // Skip first to match charts
this.starting = false;
return;
}
const doc = response.totals;
let totalTime = 0;
for (let collname in doc) { // eslint-disable-line prefer-const
if (!doc.hasOwnProperty(collname) || collname === 'note' || toNS(collname).specialish) {
continue;
}
const subdoc = doc[collname];
if (!('readLock' in subdoc) || !('writeLock' in subdoc) || !('total' in subdoc)) {
debug('Error: top response from DB missing fields', subdoc);
}
totals.push({
'collectionName': collname,
'loadPercentR': (subdoc.readLock.time / subdoc.total.time) * 100,
'loadPerfectL': (subdoc.writeLock.time / subdoc.total.time) * 100,
'loadPercent': subdoc.total.time
});
totalTime += subdoc.total.time;
}
for (let i = 0; i < totals.length; i++) {
totals[i].loadPercent = _.round((totals[i].loadPercent / totalTime) * 100, 0);
}
for (let i = totals.length - 1; i >= 0; i--) {
if (!totals[i].loadPercent) {
totals.splice(i, 1);
}
}
totals.sort(function(a, b) {
const f = (b.loadPercent < a.loadPercent) ? -1 : 0;
return (a.loadPercent < b.loadPercent) ? 1 : f;
});
// Add current state to all
this.allOps.push(totals);
if (this.isPaused) {
totals = this.allOps[this.endPause];
} else {
this.endPause = this.allOps.length;
}
// This handled by mouseover function completely
if (this.inOverlay) {
return;
}
} else if (error) {
Actions.dbError({ 'op': 'top', 'error': error });
if (this.isPaused) {
totals = this.allOps[this.endPause];
error = this.errored[this.endPause];
} else {
this.endPause = this.allOps.length;
}
// This handled by mouseover function completely
if (this.inOverlay) {
return;
}
this.trigger(error, totals);
});
Expand Down