Skip to content

Conversation

@rashmidixit
Copy link

@rashmidixit rashmidixit commented Jan 2, 2017

The Metrics view for each type of entity basically fires APIs and calculates required values on the client end. For e.g. to display memory usage etc at the zone level, it will fetch all zones. For each zone it will fetch pods->cluster->host->VMs
For a very large Cloudstack installation this will have a major impact on the performance.
Ideally, there should be an API which calculates all metrics in the backend and the UI should simply show the values. However, for the time, introduce a global setting called enable.metrics which will be set to false. This will cause the metrics button not to be shown on any of the pages.
If the Admin changes this to true, then the button will be visible and Metrics functionality will work as usual.

In this pull request, have also added JUnit test case for listCapabilities API.

Additionally added a test case in marvin called test_global_settings as part of the smoke tests which test the output of the listCapabilities API and checks if this setting is present or not.

Refer to CLOUDSTACK-9699 for more details.

Rashmi Dixit added 7 commits December 29, 2016 15:31
Reviewed-By: Radhika Grover & Koushik Das

Added a new global setting called enable.metrics.ui (default false) which
allows the metrics button to be enabled/disabled in the UI. Note that
when false, the metrics button is not visible at all. This feature
has been introduced because metrics feature is not optimized and
will cause performance issues in large deployments.

Conflicts:
	api/src/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java
	api/src/org/apache/cloudstack/api/response/CapabilitiesResponse.java
	server/src/com/cloud/server/ManagementServerImpl.java
	ui/scripts/cloudStack.js
	ui/scripts/instances.js
	ui/scripts/sharedFunctions.js
	ui/scripts/storage.js
	ui/scripts/system.js
…ies API

and whether it includes enableMetrics parameter.

Reviewed-By Koushik Das, Sanjeev N

Added junit test case and marvin test case for testing updated listCapabilities
API. The junit test case changes involved updating ResponseGenerator and
ApiResponseHelper to correctly build the response.

Conflicts:
	api/src/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java
	server/src/com/cloud/api/ApiResponseHelper.java
Reviewed-By: Radhika Grover & Koushik Das

Added a new global setting called enable.metrics.ui (default false) which
allows the metrics button to be enabled/disabled in the UI. Note that
when false, the metrics button is not visible at all. This feature
has been introduced because metrics feature is not optimized and
will cause performance issues in large deployments.

Conflicts:
	api/src/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java
	api/src/org/apache/cloudstack/api/response/CapabilitiesResponse.java
	server/src/com/cloud/server/ManagementServerImpl.java
	ui/scripts/cloudStack.js
	ui/scripts/instances.js
	ui/scripts/sharedFunctions.js
	ui/scripts/storage.js
	ui/scripts/system.js
…stack into CLOUDSTACK-9699

Conflicts:
	api/src/org/apache/cloudstack/api/response/CapabilitiesResponse.java
	server/src/com/cloud/api/ApiResponseHelper.java
	test/integration/smoke/test_global_settings.py
	ui/scripts/cloudStack.js
	ui/scripts/sharedFunctions.js
@rashmidixit rashmidixit changed the title Add global setting for enable/disable Metrics feature CLOUDSTACK-9699: Add global setting for enable/disable Metrics feature Jan 3, 2017
Copy link
Contributor

@jburwell jburwell left a comment

Choose a reason for hiding this comment

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

In addition to the code feedback, please squash the commits for this PR.

Mockito.when(mgr.listCapabilities(listCapabilitiesCmd)).thenReturn(result);
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not perform lines 58-67 in in setUp? Not only would this approach focus this method on the test operations, but remove the need for unnecessary class-level attributes.

Also, catching exceptions is not required because JUnit will automatically fail when exceptions are thrown. If there are checked exceptions, add them to the throws of the test method to keep test methods as succinct as possible.

listCapabilitiesCmd._mgr = mgr;
listCapabilitiesCmd._responseGenerator = responseGenerator;

Map<String, Object> result = new HashMap<String, Object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider using Collections.emptyMap() instead of allocating a new Map to improve clarity of intention.

self.assertIsNotNone(
listCapabilities.enablemetricsui,
"Failed to fetch enable.metrics.ui"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests to verify that the value is set as expected.

return ['add', 'viewMetrics', 'uploadVolume', 'uploadVolumefromLocal'];
else
return ['add', 'uploadVolume', 'uploadVolumefromLocal'];
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the duplication in this function by refactoring as follows:

actionPreFilter: function(args){
                         actions = ['add', 'uploadVolume', 'uploadVolumefromLocal'];
                         if (g_enablemetricsui) {
                             actions.splice(1, 0, 'viewMetrics');
                         }
                         return actions;
                     },

if (g_enablemetricsui)
return ['add', 'viewMetrics'];
else
return ['add'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the duplication in this function by refactoring as follows:

actions = ['add'];
if (g_enablemetricsui) {
   actions.append('viewMetrics');
}
return actions;

return ['add', 'viewMetrics'];
else
return ['add'];
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 14096-14101 appear to be a duplication of lines 7857-7860. Can this code duplication be removed?

return ['add', 'viewMetrics'];
else
return ['add'];
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please code duplication comments above.

return ['add', 'viewMetrics'];
else
return ['add'];
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please code duplication comments above.

if (listViewData.actions) {
// If a preFilter is set, then get the values. Else set this to null
var filteredActions = listViewData.actionPreFilter == undefined ?
null : listViewData.actionPreFilter();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not set to an empty list rather than null to avoid a potential null error?

// filter out those actions that shouldn't be shown
if (filteredActions != null
&& (filteredActions.indexOf(actionName) < 0))
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Per coding standards, please surround all if blocks with curly braces.

@rashmidixit
Copy link
Author

Thank you @jburwell. I will incorporate the comments in a couple of days and resubmit.

@yadvr
Copy link
Member

yadvr commented Jan 11, 2017

@rashmidixit I'm working on writing separate metrics view apis (backend/apis), they will improve the performance significantly. An explicit global settings is not necessary, pl. hold on this PR.

@yadvr
Copy link
Member

yadvr commented Feb 13, 2017

I'm working on improving the metrics view feature by implementing the logic as backend APIs, will post a PR this/next week. Thanks.

@rashmidixit
Copy link
Author

@rhtyd Thanks for the update.

@yadvr
Copy link
Member

yadvr commented Feb 16, 2017

This is not needed with PR #1944, though changes around capability refactoring can be separated.

@rashmidixit
Copy link
Author

Closing this based on the new PR #1944.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants