-
Notifications
You must be signed in to change notification settings - Fork 1
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 馃徆 Implement Shuttle Route KML Save to S3 #984
base: master
Are you sure you want to change the base?
Conversation
Coverage of commit
|
Coverage of commit
|
Coverage of commit
|
Coverage of commit
|
http_client: HTTPoison, | ||
shape_storage_enabled?: false, | ||
shape_storage_prefix_env: "arrow-dev-local", | ||
shape_storage_bucket: "mbta-gtfs-s3-sandbox", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be mbta-arrow
, but I do not have write access at least with my credentials.
@@ -34,7 +34,11 @@ config :arrow, | |||
}, | |||
time_zone: "America/New_York", | |||
ex_aws_requester: {Fake.ExAws, :admin_group_request}, | |||
http_client: HTTPoison | |||
http_client: HTTPoison, | |||
shape_storage_enabled?: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabled by default, and just stores disabled
as the value for all of the relevant s3 columns.
http_client: HTTPoison | ||
http_client: HTTPoison, | ||
shape_storage_enabled?: false, | ||
shape_storage_prefix_env: "arrow-dev-local", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The storage path is like this: $PREFIX/$PREFIX_ENV/the_file.kml
. In prod, the prefix_env
is set via the existing AWS env var.
@@ -2,6 +2,10 @@ | |||
<aside role="alert" class="alert alert-info"><%= message %></aside> | |||
<% end %> | |||
|
|||
<%= with message when is_binary(message) <- Phoenix.Flash.get(@flash, :error) do %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to display a simple error flash - it looks like the existing error flash was designed to show a whole collection of errors (form validation).
|> Plug.Conn.resp(:found, "") | ||
|> Plug.Conn.put_resp_header( | ||
"location", | ||
"https://#{shape.bucket}.s3.amazonaws.com/#{shape.path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I store the bucket and path - it may be a pre-optimization but should help if we ever have to rename these things vs. string replacing a URL column.
@@ -51,6 +51,8 @@ defmodule Arrow.MixProject do | |||
{:ex_aws_rds, "~> 2.0"}, | |||
{:ex_aws_secretsmanager, "~> 2.0"}, | |||
{:ex_aws, "~> 2.1"}, | |||
{:ex_aws_s3, "~> 2.1"}, | |||
{:sweet_xml, "~> 0.7.4"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet_xml
is soft-required by ex_aws_s3
.
@@ -20,11 +20,24 @@ defmodule Arrow.ShuttleTest do | |||
assert Shuttle.get_shape!(shape.id) == shape | |||
end | |||
|
|||
test "create_shape/1 with valid data creates a shape" do | |||
valid_attrs = %{name: "some name"} | |||
test "create_shape/1 with valid data creates a shape and uploads to s3" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated our "good-path" test to also actually upload to S3.
My one concern with this is storage usage over time without a cleanup routine. I think the cleanest implementation would be to update the policy to whack anything with arrow/test-runner/*
older than n days, vs cleaning it up in the test, because runs that fail may leave detritus on the bucket.
@meagharty There are a few outstanding issues here that aren't really related to the core feature but may block it's acceptance into the repo until they are complete:
Otherwise, I think the feature as-is can be reviewed while we deal with these issues 馃槃 If you disagree I can take it back as a draft while I resolve these things. |
"path" => "some/path/to/sample.kml", | ||
"prefix" => prefix, | ||
"bucket" => Application.get_env(:arrow, :shape_storage_bucket), | ||
"filename" => %Plug.Upload{filename: "sample.kml", path: "test_files/sample.kml"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not blocking: we could resolve this in a future PR since the full featureset is expected to extract individual shapes from a KML file (not part of this PR)
But: I was talking with @bfauble and we might want this filename to be saved as #{name}.kml
. To make the names easier to reconcile between gtfs_creator and arrow.
I am pro-keeping the KML format around since it's industry common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meagharty This is a great idea and would also mean that we could drop the columns eventually - since the file path / name / etc. would be inherent.
I guess an alternative would be a "smart" connection between the two systems where it would pull some metadata JSON payload, which might be more extensible long term BUT I think starting with the names makes a lot of sense.
It would be an easy change here, too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also feel like this could be a follow up ticket, just to avoid this getting stuck in review as long as you're cool with that (re: non-blocking).
Coverage of commit
|
|
||
config :arrow, | ||
shape_storage_enabled?: true, | ||
shape_storage_prefix_env: System.get_env("AWS_SECRET_PREFIX") || "arrow-prod-unknown" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having this default, should it just be nil
and included as part of the check with enabled?
case upload_shape(attrs["filename"]) do | ||
{:ok, new_attrs} -> | ||
# Delete old file: | ||
{:ok, _} = delete_shape_file(shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there not a way to just overwrite when uploading?
Summary of changes
Asana Ticket: 馃徆 Implement Shuttle Route KML Save to S3
Reviewer Checklist