From d7393f65782b9fe9895062a9b5c59e86167cbe68 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 8 May 2017 15:10:26 -0400 Subject: [PATCH] rest: do not duplicate non-existing resource ids Currently the code tries over and over again to create metrics for a resource that does not exist. Which add 2 bad effects (with N is the number of metrics that gets measures for this non-existing resource): - it calls N times create_metrics() where it's sure it'll raise NoSuchResource, so let's just break at the first error - the unknown resource is added N times to the detail of the error message Change-Id: I5b0de5989c21cd57d84b53cb9e8a13a311ad4862 --- gnocchi/rest/__init__.py | 1 + .../functional/gabbits/batch-measures.yaml | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gnocchi/rest/__init__.py b/gnocchi/rest/__init__.py index ec3207f5..ef884535 100644 --- a/gnocchi/rest/__init__.py +++ b/gnocchi/rest/__init__.py @@ -1404,6 +1404,7 @@ class ResourcesMetricsMeasuresBatchController(rest.RestController): unknown_resources.append({ 'resource_id': six.text_type(resource_id), 'original_resource_id': original_resource_id}) + break except indexer.IndexerException as e: # This catch NoSuchArchivePolicy, which is unlikely # be still possible diff --git a/gnocchi/tests/functional/gabbits/batch-measures.yaml b/gnocchi/tests/functional/gabbits/batch-measures.yaml index ae3b454e..a121f6fb 100644 --- a/gnocchi/tests/functional/gabbits/batch-measures.yaml +++ b/gnocchi/tests/functional/gabbits/batch-measures.yaml @@ -227,6 +227,39 @@ tests: - original_resource_id: "bbbbbbbb-d63b-4cdd-be89-111111111111" resource_id: "bbbbbbbb-d63b-4cdd-be89-111111111111" + - name: push measurements to unknown named metrics and resource with create_metrics with uuid resource id where resources is several times listed + POST: /v1/batch/resources/metrics/measures?create_metrics=true + request_headers: + content-type: application/json + accept: application/json + data: + aaaaaaaa-d63b-4cdd-be89-111111111111: + auto.test: + - timestamp: "2015-03-06T14:33:57" + value: 43.1 + - timestamp: "2015-03-06T14:34:12" + value: 12 + auto.test2: + - timestamp: "2015-03-06T14:33:57" + value: 43.1 + - timestamp: "2015-03-06T14:34:12" + value: 12 + bbbbbbbb-d63b-4cdd-be89-111111111111: + auto.test: + - timestamp: "2015-03-06T14:33:57" + value: 43.1 + - timestamp: "2015-03-06T14:34:12" + value: 12 + + status: 400 + response_json_paths: + $.description.cause: "Unknown resources" + $.description.detail[/original_resource_id]: + - original_resource_id: "aaaaaaaa-d63b-4cdd-be89-111111111111" + resource_id: "aaaaaaaa-d63b-4cdd-be89-111111111111" + - original_resource_id: "bbbbbbbb-d63b-4cdd-be89-111111111111" + resource_id: "bbbbbbbb-d63b-4cdd-be89-111111111111" + - name: push measurements to unknown named metrics and resource with create_metrics with non uuid resource id POST: /v1/batch/resources/metrics/measures?create_metrics=true request_headers: