Skip to content

Commit

Permalink
chore: Erlang 27/Elixir 1.17 (#842)
Browse files Browse the repository at this point in the history
* Upgraded erlang and elixir.

* Improved test and removed test without possible outcome.

* Remove protobuf support.

* Fix warnings.

* Fix recaptcha reference.

* Update credo.

* Sobelow skip.

* Update dialyxir.

* Use latest alpine.

* Add back a test.

* Remove unnecessary assertion.
  • Loading branch information
cmaddox5 authored Dec 19, 2024
1 parent 824e0f9 commit adc0810
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 1,573 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
elixir 1.16.3-otp-25
erlang 25.3.2.12
elixir 1.17.3-otp-27
erlang 27.2
python 3.9.16
poetry 1.7.0
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG ELIXIR_VERSION=1.16.3
ARG ERLANG_VERSION=25.3.2.12
ARG ALPINE_VERSION=3.17.7
ARG ELIXIR_VERSION=1.17.3
ARG ERLANG_VERSION=27.2
ARG ALPINE_VERSION=3.21.0

FROM hexpm/elixir:${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION} as builder

Expand Down Expand Up @@ -28,7 +28,7 @@ RUN mix release
# The one the elixir image was built with
FROM alpine:${ALPINE_VERSION}

RUN apk add --no-cache libssl1.1 dumb-init libstdc++ libgcc ncurses-libs && \
RUN apk add --no-cache libssl3 dumb-init libstdc++ libgcc ncurses-libs && \
mkdir /work /api && \
adduser -D api && chown api /work

Expand Down
3 changes: 2 additions & 1 deletion apps/api_web/.sobelow-skips
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

89AB244CFEA58A837123CC326E49CD13
C925E5F931492531D9372392664AE12C
C925E5F931492531D9372392664AE12C
CB8E15060F63E711108608C13BA30278
11 changes: 10 additions & 1 deletion apps/api_web/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ config :api_web, :versions,

config :logger, :console,
format: "$date $time $metadata[$level] $message\n",
metadata: [:request_id]
metadata: [
:request_id,
:api_key,
:ip,
:records,
:api_version,
:concurrent,
:metadata_keep,
:metadata_value
]

# JSON-API configuration
config :phoenix, json_library: Jason
Expand Down
4 changes: 1 addition & 3 deletions apps/api_web/config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ config :logger,
level: :info,
backends: [:console, Sentry.LoggerBackend]

config :logger, :console,
format: "$dateT$time [$level] node=$node $metadata$message\n",
metadata: [:request_id, :api_key, :ip, :records, :api_version, :concurrent]
config :logger, :console, format: "$dateT$time [$level] node=$node $metadata$message\n"

config :ehmon, :report_mf, {:ehmon, :info_report}

Expand Down
10 changes: 6 additions & 4 deletions apps/api_web/lib/api_web/api_controller_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ defmodule ApiWeb.ApiControllerHelpers do
end

def index(module, conn, params) do
conn
|> get_format()
|> index_for_format()
|> apply(:call, [conn, module, params])
mod =
conn
|> get_format()
|> index_for_format()

mod.call(conn, module, params)
end

def call(conn, module, params) do
Expand Down
18 changes: 8 additions & 10 deletions apps/api_web/lib/api_web/controllers/prediction_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,17 @@ defmodule ApiWeb.PredictionController do
{:error, :only_route_type}

p when map_size(p) > 0 ->
filtered_params
|> Params.split_on_comma("trip")
trip_ids = Params.split_on_comma(filtered_params, "trip")

{trip_ids, route_pattern_ids}
|> case do
[] ->
case route_pattern_ids do
[] ->
all_stops_and_routes(stop_ids, route_ids, matchers)
{[], []} ->
all_stops_and_routes(stop_ids, route_ids, matchers)

route_pattern_ids ->
all_stops_and_route_patterns(stop_ids, route_pattern_ids, matchers)
end
{[], route_pattern_ids} ->
all_stops_and_route_patterns(stop_ids, route_pattern_ids, matchers)

trip_ids ->
{trip_ids, _} ->
all_stops_and_trips(stop_ids, trip_ids, matchers)
end
|> Prediction.filter_by_route_type(route_types)
Expand Down
23 changes: 12 additions & 11 deletions apps/api_web/lib/api_web/event_stream/diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ defmodule ApiWeb.EventStream.Diff do
if update_size <= map_size(list_2_map) do
add = Enum.filter(map_list_2, &item_in_map(added_map, &1))
update = Map.values(updated_map)

remove =
map_list_1
|> Enum.flat_map(fn item ->
if item_in_map(removed_map, item) do
[Map.take(item, ~w(id type))]
else
[]
end
end)
|> Enum.reverse()
remove = find_removed_items(map_list_1, removed_map)

%{
add: add,
Expand All @@ -50,6 +40,17 @@ defmodule ApiWeb.EventStream.Diff do
%{reset: [map_list_2]}
end

defp find_removed_items(map, removed_map) do
map
|> Enum.flat_map(fn item ->
if(item_in_map(removed_map, item),
do: [Map.take(item, ~w(id type))],
else: []
)
end)
|> Enum.reverse()
end

defp by_key(%{"type" => type, "id" => id} = item), do: {{type, id}, item}

defp item_in_map(map, %{"type" => type, "id" => id}) do
Expand Down
6 changes: 3 additions & 3 deletions apps/api_web/lib/api_web/plugs/modified_since_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule ApiWeb.Plugs.ModifiedSinceHandler do
last_modified_header = State.Metadata.last_modified_header(mod),
conn = Plug.Conn.put_resp_header(conn, "last-modified", last_modified_header),
{conn, [if_modified_since_header]} <- {conn, get_req_header(conn, "if-modified-since")},
{conn, false} <- {conn, is_modified?(last_modified_header, if_modified_since_header)} do
{conn, false} <- {conn, modified?(last_modified_header, if_modified_since_header)} do
conn
|> send_resp(:not_modified, "")
|> halt()
Expand All @@ -64,12 +64,12 @@ defmodule ApiWeb.Plugs.ModifiedSinceHandler do
end
end

def is_modified?(same, same) do
def modified?(same, same) do
# shortcut if the headers have the same value
false
end

def is_modified?(first, second) do
def modified?(first, second) do
with {:ok, first_val} <- modified_value(first),
{:ok, second_val} <- modified_value(second) do
first_val > second_val
Expand Down
2 changes: 1 addition & 1 deletion apps/api_web/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule ApiWeb.Mixfile do
{:jason, "~> 1.4"},
{:stream_data, "~> 0.5", only: :test},
{:sobelow, "~> 0.11", only: :dev, runtime: false},
{:recaptcha, git: "https://github.com/samueljseay/recaptcha.git", tag: "71cd746"},
{:recaptcha, git: "https://github.com/samueljseay/recaptcha.git", ref: "71cd746be987f6834c1a933f5d2f934350e55060"},
{:sentry, "~> 8.0"},
{:qr_code, "~> 3.0"},
{:nimble_totp, "~> 1.0"}
Expand Down
2 changes: 0 additions & 2 deletions apps/api_web/test/api_web/canary_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ defmodule ApiWeb.CanaryTest do

assert {:error, "expect function/0 for notify_fn, got nil"} =
Canary.start_link(notify_fn: nil)

assert_receive {:EXIT, _, "expect function/0 for notify_fn, got nil"}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -261,42 +261,48 @@ defmodule ApiWeb.RoutePatternControllerTest do
route_id: "route1",
direction_id: 0,
canonical: true,
typicality: 5
typicality: 5,
sort_order: 1
},
%RoutePattern{
id: "rp2",
route_id: "route1",
direction_id: 1,
canonical: true,
typicality: 5
typicality: 5,
sort_order: 2
},
%RoutePattern{
id: "rp3",
route_id: "route2",
direction_id: 0,
canonical: false,
typicality: 5
typicality: 5,
sort_order: 3
},
%RoutePattern{
id: "rp4",
route_id: "route2",
direction_id: 1,
canonical: false,
typicality: 5
typicality: 5,
sort_order: 4
},
%RoutePattern{
id: "rp5",
route_id: "route3",
direction_id: 0,
canonical: false,
typicality: 5
typicality: 5,
sort_order: 5
},
%RoutePattern{
id: "rp6",
route_id: "route3",
direction_id: 1,
canonical: false,
typicality: 5
typicality: 5,
sort_order: 6
}
]
end
Expand Down Expand Up @@ -336,6 +342,10 @@ defmodule ApiWeb.RoutePatternControllerTest do
)

assert [
%{
"id" => "rp3",
"attributes" => %{"direction_id" => 0, "canonical" => false}
},
%{
"id" => "rp4",
"attributes" => %{"direction_id" => 1, "canonical" => false}
Expand All @@ -344,10 +354,6 @@ defmodule ApiWeb.RoutePatternControllerTest do
"id" => "rp5",
"attributes" => %{"direction_id" => 0, "canonical" => false}
},
%{
"id" => "rp3",
"attributes" => %{"direction_id" => 0, "canonical" => false}
},
%{
"id" => "rp6",
"attributes" => %{"direction_id" => 1, "canonical" => false}
Expand All @@ -368,28 +374,28 @@ defmodule ApiWeb.RoutePatternControllerTest do

assert [
%{
"id" => "rp4",
"attributes" => %{"direction_id" => 1, "canonical" => false}
"id" => "rp1",
"attributes" => %{"direction_id" => 0, "canonical" => true}
},
%{
"id" => "rp5",
"id" => "rp2",
"attributes" => %{"direction_id" => 1, "canonical" => true}
},
%{
"id" => "rp3",
"attributes" => %{"direction_id" => 0, "canonical" => false}
},
%{
"id" => "rp1",
"attributes" => %{"direction_id" => 0, "canonical" => true}
"id" => "rp4",
"attributes" => %{"direction_id" => 1, "canonical" => false}
},
%{
"id" => "rp3",
"id" => "rp5",
"attributes" => %{"direction_id" => 0, "canonical" => false}
},
%{
"id" => "rp6",
"attributes" => %{"direction_id" => 1, "canonical" => false}
},
%{
"id" => "rp2",
"attributes" => %{"direction_id" => 1, "canonical" => true}
}
] = json_response(conn, 200)["data"]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ defmodule ApiWeb.Plugs.ModifiedSinceHandlerTest do
end
end

describe "is_modified?/2" do
describe "modified?/2" do
property "is true when first header is greater than second header" do
check all(
{first, first_header} <- rfc1123(),
{second, second_header} <- rfc1123(),
max_runs: 1000
) do
expected = first > second
actual = ModifiedSinceHandler.is_modified?(first_header, second_header)
actual = ModifiedSinceHandler.modified?(first_header, second_header)
assert expected == actual
end
end
Expand Down
2 changes: 1 addition & 1 deletion apps/health/lib/health/checkers/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Health.Checkers.State do
statuses =
for app <- @apps do
subscribe({:new_state, app})
{app_name(app), app.size}
{app_name(app), app.size()}
end

{:ok, statuses}
Expand Down
Loading

0 comments on commit adc0810

Please sign in to comment.