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
Conversation
There was a problem hiding this 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.
gnocchi/rest/__init__.py
Outdated
@@ -665,6 +665,8 @@ def post(self): | |||
except indexer.NoSuchResource as e: | |||
abort(404, e) | |||
|
|||
return metrics |
There was a problem hiding this comment.
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.
Are you referring to the |
On Wed, May 31, 2017 at 02:01:00AM -0700, Andrés Álvarez wrote:
Are you referring to the [`test_post_append_metrics`](https://github.com/gnocchixyz/gnocchi/blob/master/gnocchi/tests/test_rest.py#L985) test?
Not only, you can looks at travis-ci job results to see all the failing
tests.
…--
Mehdi Abaakouk
mail: sileht@sileht.net
irc: sileht
|
There was a problem hiding this 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 :)
gnocchi/rest/__init__.py
Outdated
@@ -665,6 +665,9 @@ def post(self): | |||
except indexer.NoSuchResource as e: | |||
abort(404, e) | |||
|
|||
return pecan.request.indexer.get_resource( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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, which would return the new metrics as well.
Sorry for that, I have thought this API endpoint was about resource, but it's not.
…--
Mehdi Abaakouk
mail: sileht@sileht.net
irc: sileht
|
Any consensus on what the response content should be? Or if this change should be abandoned. |
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.
|
@jd Understood. I have made the changes. Will squash if everything is ok. |
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 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool thx!
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. :) |
@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. |
@BigChief45 Maybe next time, since you'll need to edit that branch to fix the Travis failures. ;) |
@jd No problem. Fixing this soon. By the way, I am taking a look at the documentation regarding this: I cannot find the response content/scenario anywhere in the docs. Is this content generated into the docs from an actual request? |
@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 |
Hm why are resource IDs being passed as uppercase in the requests in the Gabbi tests? Seems a bit strange. |
7e7edfa
to
62f74cc
Compare
@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. |
@@ -665,6 +667,8 @@ def post(self): | |||
except indexer.NoSuchResource as e: | |||
abort(404, e) | |||
|
|||
return r.metrics |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
So it seems that the order of the returned metrics differs between Postgresql and MySQL? |
5e11ca3
to
1c19ce7
Compare
Seems like there is some issue with Docker in the CI. |
That should be fixed now. |
I have squashed all the commits and all seems to pass at the gate. I think this is ready to be merged? 😃 |
Thanks @BigChief45 ! |
Fixes #12