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

add AWSS3 as a package extension #147

Merged
merged 7 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name = "Onda"
uuid = "e853f5be-6863-11e9-128d-476edb89bfb5"
authors = ["Beacon Biosignals, Inc."]
version = "0.15.2"

version = "0.15.3"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand All @@ -17,22 +16,32 @@ TimeSpans = "bb34ddd2-327f-4c4a-bfb0-c98fc494ece1"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"

[extensions]
OndaAWSS3Ext = "AWSS3"

[compat]
Arrow = "1.6.2, 2"
AWSS3 = "0.9, 0.10, 0.11"
CodecZstd = "0.6, 0.7"
Compat = "3.32, 4"
DataFrames = "1.2"
FLAC_jll = "1.3.3"
Legolas = "0.5"
Minio = "0.2"
Tables = "1.4"
TimeSpans = "0.3.4"
TranscodingStreams = "0.9"
julia = "1.6"

[extras]
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
FLAC_jll = "1d38b3a6-207b-531b-80e8-c83f48dafa73"
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["FLAC_jll", "DataFrames", "Test"]
test = ["AWSS3", "FLAC_jll", "DataFrames", "Minio", "Test"]
24 changes: 24 additions & 0 deletions ext/OndaAWSS3Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module OndaAWSS3Ext

using AWSS3: S3Path
using Onda: Onda

"""
Onda.read_byte_range(path::S3Path, byte_offset, byte_count)

Implement method needed for Onda to read a byte range from an S3 path. Uses
`AWSS3.s3_get` under the hood.

"""
function Onda.read_byte_range(path::S3Path, byte_offset, byte_count)

Check warning on line 13 in ext/OndaAWSS3Ext.jl

View check run for this annotation

Codecov / codecov/patch

ext/OndaAWSS3Ext.jl#L13

Added line #L13 was not covered by tests
# s3_get byte_range is 1-indexed, so we need to add one
byte_range = range(byte_offset + 1; length=byte_count)
return read(path; byte_range)

Check warning on line 16 in ext/OndaAWSS3Ext.jl

View check run for this annotation

Codecov / codecov/patch

ext/OndaAWSS3Ext.jl#L15-L16

Added lines #L15 - L16 were not covered by tests
end

# avoid method ambiguity
function Onda.read_byte_range(path::S3Path, ::Missing, ::Missing)
return read(path)
end

end # module
47 changes: 47 additions & 0 deletions test/awss3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function minio_server(body, dirs=[mktempdir()]; address="localhost:9005")
server = Minio.Server(dirs; address)

try
run(server; wait=false)
sleep(0.5) # give the server just a bit of time, though it is amazingly fast to start

config = MinioConfig(
"http://$address"; username="minioadmin", password="minioadmin"
)
body(config)
finally
# Make sure we kill the server even if a test failed.
kill(server)
end
end

@testset "AWSS3 usage" begin
minio_server() do config
s3_create_bucket(config, "test-bucket")

file_format = "lpcm.zst"
kleinschmidt marked this conversation as resolved.
Show resolved Hide resolved
file_path = S3Path("s3://test-bucket/prefix/samples.$(file_format)"; config)
recording_uuid = uuid4()
start = Second(0)

info = SamplesInfoV2(sensor_type="eeg",
channels=["a", "b"],
sample_unit="unit",
sample_resolution_in_unit=1.0,
sample_offset_in_unit=0.0,
sample_type=Int16,
sample_rate=100.0)
samples = Samples(rand(sample_type(info), 2, 300), info, true)

signal = Onda.store(file_path, file_format, samples, recording_uuid, start)
@test signal.file_path isa S3Path

loaded_samples = Onda.load(signal; encoded=true)
@test samples == loaded_samples

# Load subspan to exercise method
span = TimeSpan(0, Second(1))
loaded_span = Onda.load(signal, span; encoded=true)
@test loaded_samples[:, span] == loaded_span
Copy link
Member

Choose a reason for hiding this comment

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

for some reason it doesn't seem like this has hit that added method, at least according to the "missed coverage" annotations above. I wonder if somehow the package extension isn't getting loaded properly in tests?

we also have some tests in OndaBatches.jl which try to really make sure we're actually passing the byte range to AWSS3: https://github.com/beacon-biosignals/OndaBatches.jl/blob/a43b6f0a6837c2a478a1845c69728c1851e234c0/test/utils.jl#L22-L27

Copy link
Member Author

Choose a reason for hiding this comment

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

locally I confirmed it was loading, but I agree something seems off here. Weirdly codecov says the other method WAS hit in the extension code...

end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Compat: @compat
using Test, UUIDs, Dates, Onda, Legolas, Arrow, Tables, TimeSpans, DataFrames, Random
using Tables: rowmerge
using AWSS3, Minio # for testing AWSS3 package extension

function has_rows(a, b)
for name in propertynames(b)
Expand All @@ -17,5 +18,6 @@ include("signals.jl")
include("serialization.jl")
include("samples.jl")
include("deprecations.jl")
include("awss3.jl")
include(joinpath(dirname(@__DIR__), "examples", "flac.jl"))
include(joinpath(dirname(@__DIR__), "examples", "tour.jl"))
Loading