Skip to content

Commit

Permalink
Update Codec Enum to support ZSTD and ZSTDNODICT (opensearch-project#327
Browse files Browse the repository at this point in the history
)

Signed-off-by: Ian Hoang <hoangia@amazon.com>
Co-authored-by: Ian Hoang <hoangia@amazon.com>
  • Loading branch information
IanHoang and Ian Hoang authored Jun 12, 2023
1 parent 7192af8 commit 93d8a8a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
14 changes: 10 additions & 4 deletions osbenchmark/workload/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,20 @@ def from_hyphenated_string(cls, v):
class IndexCodec(Enum):
Default = "default"
BestCompression = "best_compression"
ZSTD = "zstd"
ZSTDNODICT = "zstdnodict"

@classmethod
def is_codec_valid(cls, codec):
for valid_codec in cls:
if codec == valid_codec.value:
return True
available_codecs = cls.get_available_codecs()
if codec.lower() in available_codecs:
return True

raise ValueError(f"Invalid index.codec value '{codec}'")
raise ValueError(f"Invalid index.codec value '{codec}'. Choose from available codecs: {available_codecs}")

@classmethod
def get_available_codecs(cls):
return list(map(lambda codec: codec.value, cls))


class TaskNameFilter:
Expand Down
59 changes: 58 additions & 1 deletion tests/workload/params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,62 @@ def test_create_index_with_best_compression_codec(self):
self.assertEqual({}, p["request-params"])
self.assertEqual("best_compression", body["settings"]["index.codec"])

def test_create_index_with_zstd_codec(self):
source = params.CreateIndexParamSource(workload.Workload(name="unit-test"), params={
"index": "test",
"body": {
"settings": {
"index.number_of_replicas": 0,
"index.codec": "zstd"
},
"mappings": {
"doc": {
"properties": {
"name": {
"type": "keyword",
}
}
}
}
}
})

p = source.params()
self.assertEqual(1, len(p["indices"]))
index, body = p["indices"][0]
self.assertEqual("test", index)
self.assertTrue(len(body) > 0)
self.assertEqual({}, p["request-params"])
self.assertEqual("zstd", body["settings"]["index.codec"])

def test_create_index_with_zstdnodict_codec(self):
source = params.CreateIndexParamSource(workload.Workload(name="unit-test"), params={
"index": "test",
"body": {
"settings": {
"index.number_of_replicas": 0,
"index.codec": "zstdnodict"
},
"mappings": {
"doc": {
"properties": {
"name": {
"type": "keyword",
}
}
}
}
}
})

p = source.params()
self.assertEqual(1, len(p["indices"]))
index, body = p["indices"][0]
self.assertEqual("test", index)
self.assertTrue(len(body) > 0)
self.assertEqual({}, p["request-params"])
self.assertEqual("zstdnodict", body["settings"]["index.codec"])

def test_create_index_with_invalid_codec(self):
with self.assertRaises(exceptions.InvalidSyntax) as context:
params.CreateIndexParamSource(workload.Workload(name="unit-test"), params={
Expand All @@ -1654,7 +1710,8 @@ def test_create_index_with_invalid_codec(self):
})

self.assertEqual(str(context.exception),
"Please set the value properly for the create-index operation. Invalid index.codec value 'invalid_codec'")
"Please set the value properly for the create-index operation. Invalid index.codec value " +
"'invalid_codec'. Choose from available codecs: ['default', 'best_compression', 'zstd', 'zstdnodict']")

class CreateDataStreamParamSourceTests(TestCase):
def test_create_data_stream(self):
Expand Down

0 comments on commit 93d8a8a

Please sign in to comment.