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

Return new metrics when creating metrics for a resource #55

Merged
merged 1 commit into from Jun 12, 2017

Conversation

aalvrz
Copy link
Contributor

@aalvrz aalvrz commented May 31, 2017

Fixes #12

Copy link
Member

@sileht sileht left a comment

Choose a reason for hiding this comment

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

Also some tests have to be updated.

@@ -665,6 +665,8 @@ def post(self):
except indexer.NoSuchResource as e:
abort(404, e)

return metrics
Copy link
Member

Choose a reason for hiding this comment

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

We should not return the user input, but the values that come from the database. Also we update a resource, so we should return a resource description, not the metrics (the resource description should have the complete metrics info).

Maybe just adding 'return' at the beginning of line 655 is enough.

@aalvrz
Copy link
Contributor Author

aalvrz commented May 31, 2017

Are you referring to the test_post_append_metrics test?

@sileht
Copy link
Member

sileht commented May 31, 2017 via email

Copy link
Member

@jd jd left a comment

Choose a reason for hiding this comment

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

Would be cool to have a different PR for the last commit about doc :)

@@ -665,6 +665,9 @@ def post(self):
except indexer.NoSuchResource as e:
abort(404, e)

return pecan.request.indexer.get_resource(
Copy link
Member

Choose a reason for hiding this comment

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

If the user does not need this output it's a whole request for nothing.
It might be better to leave the user request it if it needs it after, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that the user should somehow specify if the output is needed? Could you show me an example of this?

Copy link
Member

Choose a reason for hiding this comment

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

Not really. What I mean is that if the user wants the new updated resource he just have to do GET /v1/resource/generic/<id>.

And actually returning the entire resource on the /v1/resource/generic/<id>/metric seems wrong to me. This is not the resource endpoint, it's the metric of the resource endpoint. So if anything would be returned it's the new list of metric only – which would be a different SQL request, not sure there's such a call in the indexer API.

Also I did understand at first read you were trying to fix #12. I'd like to have @chungg opionion since he is the one that opened the bug, if this is really a requirement since it will cost an indexer request on each call and I'm not sure it's really worth it.

Copy link
Contributor Author

@aalvrz aalvrz Jun 2, 2017

Choose a reason for hiding this comment

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

I agree.

On my first commit before rebasing I was only returning the newly created metrics. But @sileht mentioned something about returning the whole resource's description instead, which would return the new metrics as well.

Waiting on more information to know how to proceed with this.

@@ -989,7 +989,7 @@ def test_post_append_metrics(self):
metrics = {'foo': {'archive_policy_name': "high"}}
self.app.post_json("/v1/resource/" + self.resource_type
+ "/" + self.attributes['id'] + "/metric",
params=metrics, status=204)
params=metrics, status=200)
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be in the previous patch IIUC.

@sileht
Copy link
Member

sileht commented Jun 2, 2017 via email

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 5, 2017

Any consensus on what the response content should be? Or if this change should be abandoned.

@jd
Copy link
Member

jd commented Jun 5, 2017

Re-reading this, I think your first patch was correct – @sileht misread the problem as he said after.

You should return the newly metrics that are created, so "return metrics" was the right choice.

But, as @sileht said you can't blindly return "metrics" because it's user-supplied definitions, and not metrics objects from the database.

update_resource() returns the resource with all its metric loaded. So I'd suggest actually returning r.metrics at the end of the function. That'll report all the metrics attached to this resource, which considering the endpoint URL, sounds like a good thing.

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 6, 2017

@jd Understood. I have made the changes. Will squash if everything is ok.

@sileht
Copy link
Member

sileht commented Jun 6, 2017

The solution looks good, maybe we should check the returned json with gabbi in additional to the 204 -> 200 change to make this PR perfect.

sileht
sileht previously approved these changes Jun 6, 2017
@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 6, 2017

@sileht I have updated the Gabbi tests to check for the JSON response. Please let me know if these are correct and if they are enough.

sileht
sileht previously approved these changes Jun 6, 2017
Copy link
Member

@sileht sileht left a comment

Choose a reason for hiding this comment

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

Cool thx!

@jd
Copy link
Member

jd commented Jun 6, 2017

That's cool, though we need to squash all of that in a single commit. Can you do that @BigChief45? Otherwise I'll try that big UI button in GitHub. :)

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 6, 2017

@jd No problem. But I was thinking maybe you could try that big button this time? I've actually never seen it in action myself hehe.

jd
jd previously approved these changes Jun 6, 2017
@jd
Copy link
Member

jd commented Jun 6, 2017

@BigChief45 Maybe next time, since you'll need to edit that branch to fix the Travis failures. ;)

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 6, 2017

@jd No problem. Fixing this soon.

By the way, I am taking a look at the documentation regarding this:

image

I cannot find the response content/scenario anywhere in the docs. Is this content generated into the docs from an actual request?

@jd jd added this to the 4.0 milestone Jun 6, 2017
@jd
Copy link
Member

jd commented Jun 6, 2017

@BigChief45 Yes, the whole API doc is generated from real API calls. Check out https://github.com/gnocchixyz/gnocchi/blob/master/doc/source/rest.yaml and https://github.com/gnocchixyz/gnocchi/blob/master/doc/source/rest.j2

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 7, 2017

: Unable to match $[-1].resource_id as 85C44741-CC60-4033-804E-2D3098C7D2E9, got 85c44741-cc60-4033-804e-2d3098c7d2e9

Hm why are resource IDs being passed as uppercase in the requests in the Gabbi tests? Seems a bit strange.

@aalvrz aalvrz force-pushed the fix-#12 branch 2 times, most recently from 7e7edfa to 62f74cc Compare June 7, 2017 03:22
@jd
Copy link
Member

jd commented Jun 7, 2017

@BigChief45 Likely because whoever wrote that put them that way. It does not matter and the case should be preserved, so just upper case your changes and you should be all set.

chungg
chungg previously requested changes Jun 7, 2017
@@ -665,6 +667,8 @@ def post(self):
except indexer.NoSuchResource as e:
abort(404, e)

return r.metrics
Copy link
Member

Choose a reason for hiding this comment

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

i think this will return all metrics in resource not just the new metrics you added. it's failing in gate in gate because the new metric is not necessarily the first item returned.

if you're testing this locally, you can add verbose: true to gabbi tests, so check what order metrics are returned in (i'm guessing alphabetical). something like:

 - name: create new metrics
   verbose: True
   POST: /v1/resource/generic/f93450f2-d8a5-4d67-9985-02511241e7d1/metric
   request_headers:
       x-user-id: 0fbb231484614b1a80131fc22f6afc9c
       x-project-id: f3d41b770cc14f0bb94a1d5be9c0e3ea
       content-type: application/json
    data:
      foobar:
        archive_policy_name: low
   status: 200
   response_json_paths:
       $[0].name: foobar
       $[0].resource_id: f93450f2-d8a5-4d67-9985-02511241e7d1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This issue is driving me nuts. Locally, all the gabbi tests pass, assuming that the metric being created in the test will be the first one to be returned in the list.

When testing using the Gnocchi API, metrics are not returned in alphabetical order, but in the order of creation (last created, first in the list). But I don't get why it is not the case in the gate.

Copy link
Member

Choose a reason for hiding this comment

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

There's no order set by default. So, by chance it might always been the same order, but it also can depends on whetever it runs on MySQL or PostgreSQL. You can't assume in the test that the order is going to be always the same. Especially because maybe the next release of $RDBMS will break that assumption.

Now, what you can do is sort in the response_json_paths. This is documented here:

http://gabbi.readthedocs.io/en/latest/jsonpath.html

Basically you can do this:

response_json_paths:
  $[/name][1].name: foobar

If your metric list is "foobar, cpu_util" for example (you'll need to check what the full list is, then "foobar" will be alphabetically after "cpu_util" when sorting by name (the [/name] in the JSON path expression.

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 8, 2017

So it seems that the order of the returned metrics differs between Postgresql and MySQL?

@aalvrz aalvrz force-pushed the fix-#12 branch 2 times, most recently from 5e11ca3 to 1c19ce7 Compare June 9, 2017 01:32
@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 9, 2017

Seems like there is some issue with Docker in the CI.

@jd
Copy link
Member

jd commented Jun 9, 2017

That should be fixed now.

@aalvrz
Copy link
Contributor Author

aalvrz commented Jun 12, 2017

I have squashed all the commits and all seems to pass at the gate. I think this is ready to be merged? 😃

@jd jd dismissed chungg’s stale review June 12, 2017 06:17

Patch updated

@jd jd merged commit a852437 into gnocchixyz:master Jun 12, 2017
@jd
Copy link
Member

jd commented Jun 12, 2017

Thanks @BigChief45 !

@aalvrz aalvrz deleted the fix-#12 branch June 13, 2017 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants