Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metric rollups subcollection #33

Merged
merged 2 commits into from
Aug 24, 2017
Merged

metric rollups subcollection #33

merged 2 commits into from
Aug 24, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Aug 23, 2017

Adds Metric Rollups as a subcollection to services and vms

Usage

Required parameters

The following parameters are required to query metric rollups as a subcollection

  • capture_interval (either 'hourly' or 'daily')
  • start_date

Optional parameters:

  • end_date
    • if no end_date is specified, it will use the current date
  • limit
    • If no limit is specified, the default value in the api settings will be used.

Paging

  • Paging will be automatically applied to these metric rollup requests
  • the limit may be overriden, but is set by default in the api settings (use parameter limit to override)

Examples

Minimum attributes:

GET /api/services/:id/metric_rollups?capture_interval=hourly&start_date=2017-08-01

End date:

GET /api/services/:id/metric_rollups?capture_interval=daily&start_date=2017-08-01&end_date=2017-08-22

Limit:

GET /api/services/:id/metric_rollups?capture_interval=daily&start_date=2017-08-01&end_date=2017-08-22&limit=2000

Dates are in the format:

YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ

@miq-bot add_label wip, enhancement

@jntullo
Copy link
Author

jntullo commented Aug 24, 2017

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] metric rollups subcollection metric rollups subcollection Aug 24, 2017
@miq-bot miq-bot removed the wip label Aug 24, 2017
@abellotti
Copy link
Member

Hi @jntullo thanks for this Enhancement. Just minor stuff,

  • could you add tests to make sure we get 403's if querying the vms and services metrics subcollection without appropriate roles.
  • if you could update the description of the PR with usage examples.

Thank you.

additional specs
def self.query_metric_rollups(params)
validate_params(params)

params[:offset] ||= 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Not certain, but I don't see this or the following param being used anywhere

Copy link
Author

Choose a reason for hiding this comment

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

@imtayadeway it's being used by paging

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! That's quite surprising to me - that this service would mutate some input params for the caller - perhaps this could be handled closer to where paging happens, or at least outside of this service?

end

def self.validate_params(params)
REQUIRED_PARAMS.each do |key|
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this service is larger than one method, WDYT about making it a stateful object? If you did that, you could for instance extract each validation into its own private method, with intention-revealing names, etc..

@@ -0,0 +1,19 @@
describe Api::MetricRollupsService do
before do
allow(Settings.api).to receive(:metrics_default_limit).and_return(1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this stub important to the actual values returned, or more of a sane default? If the latter, I wonder if it might be better placed as an actual configuration in the test environment, in config/settings/test.yml?

allow(Settings.api).to receive(:metrics_default_limit).and_return(1000)
end

it 'validates that all of the parameters are present' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Since all these tests are about validation, I'm wondering it that is suggesting the service's single responsibility should be validation, and that the rest could be pulled out either into the caller, or another service?

Copy link
Author

Choose a reason for hiding this comment

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

@imtayadeway its single responsibility is not about validation. I just felt that it was better to test that the validation is done here rather than add individual tests for the various subcollections. The various subcollections do test the other functionality though. I can alter the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just felt that it was better to test that the validation is done here rather than add individual tests for the various subcollections.

Definitely! I guess I was just thinking that the tests are telling me that validation is important enough to be its own service. If there's a responsibility besides validation that was important enough to extract, I think that behaviour deserves to also be tested at this level. It's OK to have some redundancy between tests of different sizes, since I'd expect a request spec to cover integration, and unit tests to cover all possible paths through the service

@miq-bot
Copy link
Member

miq-bot commented Aug 24, 2017

Checked commits jntullo/manageiq-api@8f1eff4~...3433d26 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
9 files checked, 0 offenses detected
Everything looks fine. ⭐

@abellotti
Copy link
Member

Thanks @jntullo for the updates. 👍

@abellotti abellotti merged commit 24ea740 into ManageIQ:master Aug 24, 2017
@abellotti abellotti added this to the Sprint 68 Ending Sep 4, 2017 milestone Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants