Skip to content

Commit

Permalink
chore(serverstats): refactor serverstats to new interface COMPASS-7400 (
Browse files Browse the repository at this point in the history
#5148)

* chore(serverstats): refactor serverstats to new interface

* chore(serverstats): add d.ts export
  • Loading branch information
gribnoysup authored Nov 22, 2023
1 parent 4cf6958 commit 91f4a85
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 81 deletions.
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/compass-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@mongodb-js/compass-instance": "^4.19.1",
"@mongodb-js/compass-logging": "^1.2.6",
"@mongodb-js/compass-saved-aggregations-queries": "^1.20.1",
"@mongodb-js/compass-serverstats": "^16.19.1",
"@mongodb-js/compass-settings": "^0.21.1",
"@mongodb-js/compass-shell": "^3.19.1",
"@mongodb-js/compass-sidebar": "^5.19.1",
Expand All @@ -69,6 +70,7 @@
"@mongodb-js/compass-instance": "^4.19.1",
"@mongodb-js/compass-logging": "^1.2.6",
"@mongodb-js/compass-saved-aggregations-queries": "^1.20.1",
"@mongodb-js/compass-serverstats": "^16.19.1",
"@mongodb-js/compass-settings": "^0.21.1",
"@mongodb-js/compass-shell": "^3.19.1",
"@mongodb-js/compass-sidebar": "^5.19.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/compass-home/src/components/workspace-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
DatabaseTabsProvider,
} from '@mongodb-js/compass-database';
import CompassSavedAggregationsQueriesPlugin from '@mongodb-js/compass-saved-aggregations-queries';
import { InstanceTab as DatabasesPlugin } from '@mongodb-js/compass-databases-collections';
import { InstanceTab as DatabasesTabPlugin } from '@mongodb-js/compass-databases-collections';
import { InstanceTab as PerformanceTabPlugin } from '@mongodb-js/compass-serverstats';
import type Namespace from '../types/namespace';

const EmptyComponent: React.FunctionComponent = () => null;

const WorkspaceContent: React.FunctionComponent<{ namespace: Namespace }> = ({
namespace,
}) => {
const instanceTabs = useAppRegistryRole('Instance.Tab');
const databaseTabs = useAppRegistryRole('Database.Tab');

const Collection =
Expand All @@ -42,8 +42,8 @@ const WorkspaceContent: React.FunctionComponent<{ namespace: Namespace }> = ({
<InstanceTabsProvider
tabs={[
CompassSavedAggregationsQueriesPlugin,
DatabasesPlugin,
...(instanceTabs ?? []),
DatabasesTabPlugin,
PerformanceTabPlugin,
]}
>
<InstanceWorkspacePlugin></InstanceWorkspacePlugin>
Expand Down
16 changes: 11 additions & 5 deletions packages/compass-serverstats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"apiVersion": "3.0.0",
"description": "Compass Real Time",
"main": "dist/index.js",
"compass:main": "src/index.js",
"compass:main": "src/index.ts",
"exports": {
"browser": "./dist/browser.js",
"require": "./dist/index.js"
},
"compass:exports": {
".": "./src/index.js"
".": "./src/index.ts"
},
"types": "./dist/src/index.d.ts",
"scripts": {
"compile": "npm run webpack -- --mode production",
"postcompile": "tsc --emitDeclarationOnly",
"webpack": "webpack-compass",
"test": "mocha",
"test-electron": "xvfb-maybe electron-mocha --no-sandbox",
Expand All @@ -33,13 +35,19 @@
},
"license": "SSPL",
"peerDependencies": {
"@mongodb-js/compass-app-stores": "^7.6.1",
"@mongodb-js/compass-components": "^1.19.0",
"@mongodb-js/compass-logging": "^1.2.6",
"hadron-app-registry": "^9.0.14",
"mongodb-data-service": "^22.15.1",
"react": "^17.0.2"
},
"dependencies": {
"@mongodb-js/compass-app-stores": "^7.6.1",
"@mongodb-js/compass-components": "^1.19.0",
"@mongodb-js/compass-logging": "^1.2.6"
"@mongodb-js/compass-logging": "^1.2.6",
"hadron-app-registry": "^9.0.14",
"mongodb-data-service": "^22.15.1"
},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "^1.0.11",
Expand All @@ -58,10 +66,8 @@
"enzyme": "^3.11.0",
"eslint": "^7.25.0",
"hadron-app": "^5.15.1",
"hadron-app-registry": "^9.0.14",
"lodash": "^4.17.21",
"mocha": "^10.2.0",
"mongodb-data-service": "^22.15.1",
"mongodb-js-errors": "^0.3.2",
"mongodb-ns": "^2.4.0",
"prop-types": "^15.7.2",
Expand Down
49 changes: 0 additions & 49 deletions packages/compass-serverstats/src/index.js

This file was deleted.

59 changes: 59 additions & 0 deletions packages/compass-serverstats/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PerformanceComponent } from './components';
import { registerHadronPlugin } from 'hadron-app-registry';
import type { DataService } from 'mongodb-data-service';
import { dataServiceLocator } from 'mongodb-data-service/provider';
import { mongoDBInstanceLocator } from '@mongodb-js/compass-app-stores/provider';
import CurrentOpStore from './stores/current-op-store';
import ServerStatsStore from './stores/server-stats-graphs-store';
import TopStore from './stores/top-store';

const PerformancePlugin = registerHadronPlugin(
{
name: 'Performance',
component: PerformanceComponent,
activate(_: unknown, { dataService, instance }) {
CurrentOpStore.onActivated(dataService);
ServerStatsStore.onActivated(dataService);
TopStore.onActivated(dataService, instance);

// TODO(COMPASS-7416): no stores or subscriptions are returned here, we'd
// need to refactor the stores of this package
return {
store: {},
deactivate() {
// noop
},
};
},
},
{
dataService: dataServiceLocator as typeof dataServiceLocator<
keyof DataService
>,
instance: mongoDBInstanceLocator,
}
);

const InstanceTab = {
name: 'Performance',
component: PerformancePlugin,
};

/**
* Activate all the components in the RTSS package.
*/
function activate() {
// noop
}

/**
* Deactivate all the components in the RTSS package.
*/
function deactivate() {
// noop
}

export default PerformancePlugin;
export { activate, deactivate, InstanceTab };
export { default as d3 } from './d3';
export { default as metadata } from '../package.json';
9 changes: 4 additions & 5 deletions packages/compass-serverstats/src/stores/current-op-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const debug = require('debug')('mongodb-compass:server-stats:current-op-store');
* This store listens to the
* 'currentOpComplete' action, fetches the current op data, and
* triggers with the result of the command.
*
* @type {Reflux.Store & {onActivated(ds: import('mongodb-data-service').DataService)}}
*/
const CurrentOpStore = Reflux.createStore({
/**
Expand All @@ -26,11 +28,8 @@ const CurrentOpStore = Reflux.createStore({
this.listenTo(Actions.killOp, this.killOp);
},

onActivated: function (appRegistry) {
appRegistry.on('data-service-connected', (err, ds) => {
if (err) throw err;
this.dataService = ds;
});
onActivated: function (ds) {
this.dataService = ds;
},

restart: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const Actions = require('../actions');

// const debug = require('debug')('mongodb-compass:server-stats:graphs-store');

/**
* @type {Reflux.Store & {onActivated(ds: import('mongodb-data-service').DataService)}}
*/
const ServerStatsStore = Reflux.createStore({
init: function () {
this.restart();
Expand All @@ -11,14 +14,10 @@ const ServerStatsStore = Reflux.createStore({
this.listenTo(Actions.pause, this.pause);
},

onActivated: function (appRegistry) {
appRegistry.on('data-service-connected', (err, ds) => {
if (!err) {
this.dataService = ds;
this.isMongos = ds.isMongos();
this.isWritable = ds.isWritable();
}
});
onActivated: function (ds) {
this.dataService = ds;
this.isMongos = ds.isMongos();
this.isWritable = ds.isWritable();
},

restart: function () {
Expand Down
14 changes: 7 additions & 7 deletions packages/compass-serverstats/src/stores/top-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const debug = require('debug')('mongodb-compass:server-stats:top-store');
* This store listens to the
* 'topComplete' action, fetches the top data, and
* triggers with the result of the command.
*
* @type {Reflux.Store & {onActivated(ds: import('mongodb-data-service').DataService, instance: import('@mongodb-js/compass-app-stores/provider').MongoDBInstance)}}
*/
const TopStore = Reflux.createStore({
/**
Expand All @@ -26,12 +28,10 @@ const TopStore = Reflux.createStore({
this.listenTo(Actions.mouseOut, this.mouseOut);
},

onActivated: function (appRegistry) {
appRegistry.on('data-service-connected', (err, ds) => {
if (err) throw err;
this.dataService = ds;
this.isMongos = ds.isMongos();
});
onActivated: function (ds, instance) {
this.dataService = ds;
this.isMongos = ds.isMongos();
this.mongoDBInstance = instance;
},

restart: function () {
Expand Down Expand Up @@ -120,7 +120,7 @@ const TopStore = Reflux.createStore({
if (response !== undefined && 'totals' in response) {
doc = response.totals;
}
const numCores = global.hadronApp.instance.host.cpu_cores;
const numCores = this.mongoDBInstance.host.cpu_cores;
const cadence = 1000000; // Can safetly assume we're polling 1x/sec TODO
const t2s = {};
for (let collname in doc) {
Expand Down

0 comments on commit 91f4a85

Please sign in to comment.