Skip to content

Commit

Permalink
Merge pull request #7 from invenia/ed/rm-awssdk
Browse files Browse the repository at this point in the history
Remove AWSSDK dependency
  • Loading branch information
iamed2 authored Oct 1, 2018
2 parents 1681469 + e6e9141 commit 29986bc
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 57 deletions.
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
julia 0.6
AWSCore 0.3
AWSSDK 0.3
Memento 0.9
Mocking 0.5.3
TimeZones 0.5
Expand Down
8 changes: 1 addition & 7 deletions src/CloudWatchLogs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ __precompile__()
module CloudWatchLogs

using AWSCore: AWSConfig, AWSException
using AWSSDK.CloudWatchLogs:
describe_log_streams,
create_log_stream,
delete_log_stream,
create_log_group,
delete_log_group,
put_log_events
using AWSCore.Services: logs
using Compat: @__MODULE__, Nothing, AbstractDict
using Compat.Dates
using Compat.UUIDs
Expand Down
23 changes: 14 additions & 9 deletions src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ function create_group(
)
if isempty(tags)
aws_retry() do
create_log_group(config; logGroupName=log_group_name)
logs(config, "CreateLogGroup"; logGroupName=log_group_name)
end
else
tags = Dict{String, String}(tags)
aws_retry() do
create_log_group(config; logGroupName=log_group_name, tags=tags)
logs(config, "CreateLogGroup"; logGroupName=log_group_name, tags=tags)
end
end
return String(log_group_name)
Expand All @@ -86,7 +86,7 @@ function delete_group(
log_group_name::AbstractString,
)
aws_retry() do
delete_log_group(config; logGroupName=log_group_name)
logs(config, "DeleteLogGroup"; logGroupName=log_group_name)
end
return nothing
end
Expand All @@ -107,8 +107,9 @@ function create_stream(
log_stream_name::AbstractString="julia-$(uuid4())",
)
aws_retry() do
create_log_stream(
config;
logs(
config,
"CreateLogStream";
logGroupName=log_group_name,
logStreamName=log_stream_name,
)
Expand All @@ -127,8 +128,9 @@ function delete_stream(
log_stream_name::AbstractString,
)
aws_retry() do
delete_log_stream(
config;
logs(
config,
"DeleteLogStream";
logGroupName=log_group_name,
logStreamName=log_stream_name,
)
Expand All @@ -147,6 +149,8 @@ function new_sequence_token(stream::CloudWatchLogStream)
return new_sequence_token(stream.config, stream.log_group_name, stream.log_stream_name)
end

describe_log_streams(config; kwargs...) = logs(config, "DescribeLogStreams"; kwargs...)

"""
new_sequence_token(stream::CloudWatchLogStream) -> Union{String, Nothing}
new_sequence_token(config::AWSConfig, log_group_name, log_stream_name) -> Union{String, Nothing}
Expand Down Expand Up @@ -207,8 +211,9 @@ function update_sequence_token!(
end

function _put_log_events(stream::CloudWatchLogStream, events::AbstractVector{LogEvent})
put_log_events(
stream.config;
logs(
stream.config,
"PutLogEvents";
logEvents=events,
logGroupName=stream.log_group_name,
logStreamName=stream.log_stream_name,
Expand Down
85 changes: 51 additions & 34 deletions test/online.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ end
group_name = new_group("create_group")
@test create_group(CFG, group_name; tags=Dict("Temporary"=>"true")) == group_name

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -52,8 +53,9 @@ end

delete_group(CFG, group_name)

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -67,8 +69,9 @@ end
group_name = new_group("create_group_no_tags")
@test create_group(CFG, group_name) == group_name

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -80,8 +83,9 @@ end

delete_group(CFG, group_name)

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -94,8 +98,9 @@ end
@testset "Unnamed group" begin
group_name = create_group(CFG; tags=Dict("Temporary"=>"true"))

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -107,8 +112,9 @@ end

delete_group(CFG, group_name)

response = CloudWatchLogsSDK.describe_log_groups(
CFG;
response = logs(
CFG,
"DescribeLogGroups";
logGroupNamePrefix=group_name,
limit=1,
)
Expand All @@ -127,8 +133,9 @@ end
stream_name = new_stream("create_stream")
@test create_stream(CFG, TEST_LOG_GROUP, stream_name) == stream_name

response = CloudWatchLogsSDK.describe_log_streams(
CFG;
response = logs(
CFG,
"DescribeLogStreams";
logGroupName=TEST_LOG_GROUP,
logStreamNamePrefix=stream_name,
orderBy="LogStreamName", # orderBy and limit will ensure we get just the one
Expand All @@ -142,8 +149,9 @@ end

delete_stream(CFG, TEST_LOG_GROUP, stream_name)

response = CloudWatchLogsSDK.describe_log_streams(
CFG;
response = logs(
CFG,
"DescribeLogStreams";
logGroupName=TEST_LOG_GROUP,
logStreamNamePrefix=stream_name,
orderBy="LogStreamName", # orderBy and limit will ensure we get just the one
Expand All @@ -158,8 +166,9 @@ end
@testset "Unnamed stream" begin
stream_name = create_stream(CFG, TEST_LOG_GROUP)

response = CloudWatchLogsSDK.describe_log_streams(
CFG;
response = logs(
CFG,
"DescribeLogStreams";
logGroupName=TEST_LOG_GROUP,
logStreamNamePrefix=stream_name,
orderBy="LogStreamName", # orderBy and limit will ensure we get just the one
Expand All @@ -173,8 +182,9 @@ end

delete_stream(CFG, TEST_LOG_GROUP, stream_name)

response = CloudWatchLogsSDK.describe_log_streams(
CFG;
response = logs(
CFG,
"DescribeLogStreams";
logGroupName=TEST_LOG_GROUP,
logStreamNamePrefix=stream_name,
orderBy="LogStreamName", # orderBy and limit will ensure we get just the one
Expand Down Expand Up @@ -203,8 +213,9 @@ end
@test submit_logs(stream, LogEvent.(["Second log", "Third log"])) == 2

sleep(2) # wait until AWS has injested the logs; this may or may not be enough
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
startFromHead=true,
Expand Down Expand Up @@ -312,8 +323,9 @@ end
end

sleep(1) # wait until AWS has injested the logs; this may or may not be enough
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
startFromHead=true,
Expand Down Expand Up @@ -411,8 +423,9 @@ end
@test !isready(handler.channel)

sleep(1) # wait until AWS has injested the logs; this may or may not be enough
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
startFromHead=true,
Expand Down Expand Up @@ -459,8 +472,9 @@ end

# wait for the logs to be submitted and for AWS to injest them
sleep(10)
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
)
Expand All @@ -471,8 +485,9 @@ end
@test length(response["events"]) <= 4
num_events_injested += length(response["events"])

response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
nextToken=prev_token,
Expand Down Expand Up @@ -507,8 +522,9 @@ end
end

sleep(1) # wait until AWS has injested the logs; this may or may not be enough
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
startFromHead=true,
Expand All @@ -520,8 +536,9 @@ end
@test event["message"] == "1"

sleep(5) # wait until AWS has injested the logs; this may or may not be enough
response = CloudWatchLogsSDK.get_log_events(
CFG;
response = logs(
CFG,
"GetLogEvents";
logGroupName=TEST_LOG_GROUP,
logStreamName=stream_name,
startFromHead=false,
Expand Down
10 changes: 4 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ using CloudWatchLogs
using Compat.Test

import AWSCore
import AWSCore.Services: logs, sts
using AWSCore: AWSConfig, aws_config, AWSCredentials, AWSException
import AWSSDK
import AWSSDK.CloudFormation
import AWSSDK.STS
using Compat: findall
using Compat.Dates
using Compat.Printf
Expand All @@ -18,13 +16,13 @@ using Memento
using Memento.Test
using TimeZones

const CloudWatchLogsSDK = AWSSDK.CloudWatchLogs
const LOGGER = getlogger(CloudWatchLogs)


function assume_role(config::AWSConfig, role_arn::AbstractString; kwargs...)
response = STS.assume_role(
config;
response = sts(
config,
"AssumeRole";
RoleArn=role_arn,
RoleSessionName=session_name(),
kwargs...
Expand Down

0 comments on commit 29986bc

Please sign in to comment.