-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support limited non-alphanumeric metadata keys (#3354)
* Support limited non-alphanumeric metadata keys PBENCH-1111 Internally defined and managed Pbench Server metadata keys are lowercase alphanumeric strings; however the dataset.metalog namespace is extracted directly from the tarball metadata.log file and some benchmarks (especially fio and uperf generate tool and iteration keys that aren't accessible because they fail the normal key path validation checks. This PR loosens validation checks in some paths so `GET` APIs that retrieve metadata will be able to find these keys, for example uperf iterations like `dataset.metalog.iterations/1-tcp_stream-64B-1i`. This PR also tightens the key namespace check within an incoming JSON body parameter, e.g. for `PUT /datasets/{id}/metadata` to ensure that all nested keys conform to the rules. (NOTE: I first noticed this problem when I added general metadata filtering, and made special allowances in the `filter` keyword processing, but at the time didn't want to expand the scope to deal with more general handling. I was reminded when I added the key aggregator, and finally I'm fixing it.)
- Loading branch information
Showing
10 changed files
with
307 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from pbench.server.api.resources.query_apis.datasets.datasets_detail import ( | ||
DatasetsDetail, | ||
) | ||
from pbench.server.database.models.datasets import Dataset, Metadata | ||
from pbench.test.unit.server.conftest import generate_token | ||
from pbench.test.unit.server.query_apis.commons import Commons | ||
|
||
|
@@ -197,7 +198,29 @@ def test_metadata( | |
focus on the database dataset metadata... but necessarily has to borrow | ||
much of the setup. | ||
""" | ||
query_params = {"metadata": ["global.seen", "server.deletion"]} | ||
|
||
# In order to test that this API supports getting non-alphanumeric | ||
# metalog metadata keys, we decorate the dataset with one. To keep it | ||
# simple, just remove the existing Metadata row and create a new one. | ||
drb = Dataset.query(name="drb") | ||
Metadata.delete(Metadata.get(drb, Metadata.METALOG)) | ||
Metadata.create( | ||
dataset=drb, | ||
key=Metadata.METALOG, | ||
value={ | ||
"iterations/fooBar=10-what_else@weird": { | ||
"iteration_name": "fooBar=10-what_else@weird" | ||
}, | ||
"run": {"controller": "node1.example.com"}, | ||
}, | ||
) | ||
query_params = { | ||
"metadata": [ | ||
"global.seen", | ||
"server.deletion", | ||
"dataset.metalog.iterations/[email protected]_name", | ||
] | ||
} | ||
|
||
response_payload = { | ||
"took": 112, | ||
|
@@ -319,6 +342,7 @@ def test_metadata( | |
"serverMetadata": { | ||
"global.seen": None, | ||
"server.deletion": "2022-12-26", | ||
"dataset.metalog.iterations/[email protected]_name": "fooBar=10-what_else@weird", | ||
}, | ||
} | ||
assert expected == res_json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,7 @@ def test_dataset_paged_list(self, query_as, login, query, results, server_config | |
query: A JSON representation of the query parameters (these will be | ||
automatically supplemented with a metadata request term) | ||
results: A list of the dataset names we expect to be returned | ||
server_config: The PbenchServerConfig object | ||
""" | ||
query.update({"metadata": ["dataset.uploaded"], "limit": 5}) | ||
result = query_as(query, login, HTTPStatus.OK) | ||
|
@@ -319,10 +320,6 @@ def test_unauth_dataset_list(self, query_as): | |
Args: | ||
query_as: A fixture to provide a helper that executes the API call | ||
login: The username as which to perform a query | ||
query: A JSON representation of the query parameters (these will be | ||
automatically supplemented with a metadata request term) | ||
results: A list of the dataset names we expect to be returned | ||
""" | ||
query_as({"access": "private"}, None, HTTPStatus.UNAUTHORIZED) | ||
|
||
|
@@ -345,7 +342,7 @@ def test_get_bad_keys(self, query_as): | |
) | ||
} | ||
|
||
def test_get_get_errors(self, server_config, query_as): | ||
def test_get_key_errors(self, query_as): | ||
"""Test case reporting key errors | ||
Args: | ||
|
@@ -382,6 +379,60 @@ def test_get_get_errors(self, server_config, query_as): | |
"total": 3, | ||
} | ||
|
||
def test_use_funk_metalog_keys(self, query_as): | ||
"""Test funky metadata.log keys | ||
Normally we constrain metadata keys to lowercase alphanumeric strings. | ||
Traditional Pbench Agent `metadata.log` files contain keys constructed | ||
from benchmark iteration values that can contain mixed case and symbol | ||
characters. We allow these keys to be filtered and retrieved, but not | ||
created, so test that we can filter on a funky key value and return | ||
the key. | ||
Args: | ||
query_as: Query helper fixture | ||
""" | ||
fio_1 = Dataset.query(name="fio_1") | ||
Metadata.create( | ||
dataset=fio_1, | ||
key=Metadata.METALOG, | ||
value={ | ||
"pbench": { | ||
"date": "2020-02-15T00:00:00", | ||
"config": "test1", | ||
"script": "unit-test", | ||
"name": "fio_1", | ||
}, | ||
"iterations/fooBar=10-what_else@weird": { | ||
"iteration_name": "fooBar=10-what_else@weird" | ||
}, | ||
"run": {"controller": "node1.example.com"}, | ||
}, | ||
) | ||
response = query_as( | ||
{ | ||
"metadata": "dataset.metalog.iterations/fooBar=10-what_else@weird", | ||
"filter": "dataset.metalog.iterations/[email protected]_name:~10", | ||
}, | ||
"drb", | ||
HTTPStatus.OK, | ||
) | ||
assert response.json == { | ||
"next_url": "", | ||
"results": [ | ||
{ | ||
"metadata": { | ||
"dataset.metalog.iterations/fooBar=10-what_else@weird": { | ||
"iteration_name": "fooBar=10-what_else@weird" | ||
} | ||
}, | ||
"name": "fio_1", | ||
"resource_id": "random_md5_string3", | ||
} | ||
], | ||
"total": 1, | ||
} | ||
|
||
def test_get_unknown_keys(self, query_as): | ||
"""Test case requesting non-existent query parameter keys. | ||
|
Oops, something went wrong.