Skip to content

Commit

Permalink
Merge pull request #342 from Accenture/341-support-otp23
Browse files Browse the repository at this point in the history
341 support otp23
  • Loading branch information
mmacai committed Dec 2, 2020
2 parents f1b627d + d8e86ad commit 6543746
Show file tree
Hide file tree
Showing 34 changed files with 130 additions and 127 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@ erl_crash.dump
/.elixir_ls/
*~
*.orig

# asdf
.tool-versions
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
erlang 23.1.2
elixir 1.11.2-otp-23
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ stages:

.elixir-env: &elixir-env
language: elixir
elixir: "1.10"
otp_release: "22.0"
elixir: "1.11"
otp_release: "23.0"

jobs:
include:
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
helm repo add accenture https://accenture.github.io/reactive-interaction-gateway
helm install rig accenture/reactive-interaction-gateway
```

More information, follow the [deployment Readme](./deployment/README.md). [#319](https://github.com/Accenture/reactive-interaction-gateway/issues/319)
- make README smaller, easier to read and highlight features. [#284](https://github.com/Accenture/reactive-interaction-gateway/issues/284)

Expand All @@ -55,7 +55,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ### Security -->

<!-- ### Technical Improvements -->
### Technical Improvements

- Updated dependencies to support OTP 23. We've also replaced the versions file with `.tool-versions`, which makes it easier for those using the [asdf package manager](https://asdf-vm.com/) - just run `asdf install` to obtain the correct versions of Erlang and Elixir.
[#341](https://github.com/Accenture/reactive-interaction-gateway/issues/341)

## [2.4.0] - 2020-05-07

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM elixir:1.10-alpine as build
FROM elixir:1.11-alpine as build

# Install Elixir & Erlang environment dependencies
RUN apk add --no-cache make gcc g++
COPY .tool-versions /opt/sites/rig/
RUN mix local.hex --force
RUN mix local.rebar --force

ENV MIX_ENV=prod
WORKDIR /opt/sites/rig

# Copy release config
COPY version /opt/sites/rig/
COPY rel /opt/sites/rig/rel/
COPY vm.args /opt/sites/rig/

Expand All @@ -28,7 +28,7 @@ COPY lib /opt/sites/rig/lib
RUN mix compile
RUN mix distillery.release

FROM erlang:22-alpine
FROM erlang:23-alpine

LABEL org.label-schema.name="Reactive Interaction Gateway"
LABEL org.label-schema.description="Reactive API Gateway and Event Hub"
Expand Down
6 changes: 3 additions & 3 deletions aws.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ WORKDIR /opt/sites/rig/kinesis-client
# Compile AWS Kinesis Java application
RUN mvn package

FROM elixir:1.10-alpine as elixir-build
FROM elixir:1.11-alpine as elixir-build

# Install Elixir & Erlang environment dependencies
RUN apk add --no-cache make gcc g++
COPY .tool-versions /opt/sites/rig/
RUN mix local.hex --force
RUN mix local.rebar --force

ENV MIX_ENV=prod
WORKDIR /opt/sites/rig

# Copy release config
COPY version /opt/sites/rig/
COPY rel /opt/sites/rig/rel/
COPY vm.args /opt/sites/rig/

Expand All @@ -37,7 +37,7 @@ COPY lib /opt/sites/rig/lib
RUN mix compile
RUN mix distillery.release

FROM erlang:22-alpine
FROM erlang:23-alpine

RUN apk add --no-cache bash

Expand Down
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ config :rig, RIG.Tracing,
jaeger_service_name: {:system, :charlist, "JAEGER_SERVICE_NAME", 'rig'},
zipkin_address: {:system, :charlist, "ZIPKIN_ADDR", ''},
zipkin_service_name: {:system, "ZIPKIN_SERVICE_NAME", "rig"}

# --------------------------------------
# Phoenix
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

config :phoenix, :json_library, Jason
2 changes: 1 addition & 1 deletion config/rig_api/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ config :rig, RigApi.Endpoint,
protocol_options: cowboy_options
],
render_errors: [view: RigApi.ErrorView, accepts: ~w(json)],
pubsub: [name: Rig.PubSub],
pubsub_server: Rig.PubSub,
check_origin: false

# Always start the HTTP endpoints on application startup:
Expand Down
2 changes: 1 addition & 1 deletion config/rig_inbound_gateway/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ config :rig, RigInboundGatewayWeb.Endpoint,
transport_options: ranch_transport_options
],
render_errors: [view: RigInboundGatewayWeb.ErrorView, accepts: ~w(html json xml)],
pubsub: [name: Rig.PubSub],
pubsub_server: Rig.PubSub,
check_origin: false

config :mime, :types, %{
Expand Down
6 changes: 3 additions & 3 deletions docs/rig-dev-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Developer's Guide to the Reactive Interaction Gateway
sidebar_label: Developer's Guide
---

You'd like to mess with the code? Great! To get started, install Elixir and the Mix build tool on your machine. You can either follow the [instructions on the Elixir website](https://elixir-lang.org/install.html), or use [kiex](https://github.com/taylor/kiex) to install and manage Elixir runtimes. Kiex is recommended for development, because it allows you to jump to definitions inside the Elixir source code, plus you can checkout upcoming Elixir versions easily.
You'd like to help hacking? Great! To get started, install Elixir and the Mix build tool on your machine. If you use [asdf](https://asdf-vm.com/), all you need to do is `asdf install`. Otherwise, either follow the [instructions on the Elixir website](https://elixir-lang.org/install.html), or use [kiex](https://github.com/taylor/kiex) to install and manage Elixir runtimes.

With Elixir installed, do this:

Expand Down Expand Up @@ -38,11 +38,11 @@ To have the project use a newer Elixir version, make sure to change the followin

- `.travis.yml`: Update the Elixir and OTP versions in the `.elixir-env` section.
- `Dockerfile`, `aws.dockerfile`, `smoke_tests.dockerfile`: Make sure to change the `FROM` image tag for both the build image (elixir:...-alpine) as well as the runtime image (erlang:...-alpine). If the Erlang runtime (ERTS) in the runtime image doesn't match the ERTS version in the build image, chances are the built image won't work due to missing libraries. Because of this, it's best to use the most recent versions for both images when upgrading - they should always be compatible.
- `version`: Again, make sure both the Elixir and the OTP versions match what you have used in the previous steps.
- `.tool-versions`: Again, make sure both the Elixir and the OTP versions match what you have used in the previous steps.

## Releasing a new version

- Increment `rig` version in the [version](../version) file
- Increment `@rig_version` in [mix.exs](../mix.exs)
- Increment `appVersion` in the [Helm v2 Chart.yaml](../deployment/reactive-interaction-gateway/Chart.yaml) and [Helm v3 Chart.yaml](../deployment/reactive-interaction-gateway/Chart.yaml) files
- Update Helm chart README files: install [helm-docs](https://github.com/norwoodj/helm-docs) and run `helm-docs` in the root directory
- Increment image tag in the [Kubernetes rig.yaml](../deployment/kubectl/rig.yaml) file
Expand Down
2 changes: 1 addition & 1 deletion lib/rig/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Rig.Application do
Discovery.start()

children = [
Spec.supervisor(Phoenix.PubSub.PG2, [Rig.PubSub, []]),
{Phoenix.PubSub, name: Rig.PubSub},
# Kafka:
{DynamicSupervisor, strategy: :one_for_one, name: RigKafka.DynamicSupervisor},
# Event stream handling:
Expand Down
16 changes: 7 additions & 9 deletions lib/rig/distributed_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ defmodule RIG.DistributedSet do
{:ok, %{state | ets_table: ets_table}}
end

@doc "Handles get_record requests from other nodes."
# Handles get_record requests from other nodes.
@impl GenServer
def handle_call(
{:get_records, since_record_id},
Expand Down Expand Up @@ -163,7 +163,7 @@ defmodule RIG.DistributedSet do
{:reply, reply, state}
end

@doc "Handles adding a record on this node."
# Handles adding a record on this node.
@impl GenServer
def handle_call(
{:add_from_local, {_, uuid, _, _} = record},
Expand Down Expand Up @@ -211,12 +211,10 @@ defmodule RIG.DistributedSet do
{:noreply, %{state | last_record_id: synced_record_id}}
end

@doc """
Asks a random peer for missing records.
Records are missing on startup, but there could also be a gap caused by a temporary
network split.
"""
# Asks a random peer for missing records.
#
# Records are missing on startup, but there could also be a gap caused by a temporary
# network split.
@impl GenServer
def handle_info(
:sync_with_random_peer,
Expand All @@ -241,7 +239,7 @@ defmodule RIG.DistributedSet do
{:noreply, state}
end

@doc "Remove expired records."
# Remove expired records.
@impl GenServer
def handle_info(:cleanup, %{ets_table: ets_table} = state) do
remove_expired_records(ets_table)
Expand Down
2 changes: 1 addition & 1 deletion lib/rig_api/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule RigApi.Router do
parsers: [:urlencoded, :multipart, :json],
# return "415 Unsupported Media Type" if not handled by any parser
pass: [],
json_decoder: Poison
json_decoder: Jason
)
end

Expand Down
14 changes: 6 additions & 8 deletions lib/rig_cloud_events/cloud_event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ defmodule RigCloudEvents.CloudEvent do
end
end

@doc """
Convenience function used in testing.
If this would be called in production, of course it would be way more efficient to
access the given map directly. However, this modules' raison d'être is the safe
handling of incoming JSON encoded data, so it's safe to assume this function is ever
only called by tests.
"""
# Convenience function used in testing.
#
# If this would be called in production, of course it would be way more efficient to
# access the given map directly. However, this modules' raison d'être is the safe
# handling of incoming JSON encoded data, so it's safe to assume this function is ever
# only called by tests.
@spec parse(map) :: {:ok, t} | {:error, any}
def parse(map) when is_map(map) do
map |> Jason.encode!() |> parse
Expand Down
3 changes: 1 addition & 2 deletions lib/rig_inbound_gateway/api_proxy/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ defmodule RigInboundGateway.ApiProxy.Handler do
alias RigInboundGateway.ApiProxy.Api

@type request_path :: String.t()
@callback handle_http_request(Conn.t(), Api.t(), Api.endpoint(), request_path) ::
:ok | {:error, any}
@callback handle_http_request(Conn.t(), Api.t(), Api.endpoint(), request_path) :: Conn.t()
end
4 changes: 2 additions & 2 deletions lib/rig_inbound_gateway/api_proxy/handler/kafka.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule RigInboundGateway.ApiProxy.Handler.Kafka do
@impl Handler
def handle_http_request(conn, api, endpoint, request_path)

@doc "CORS response for preflight request."
# CORS response for preflight request.
def handle_http_request(
%{method: "OPTIONS"} = conn,
_,
Expand Down Expand Up @@ -139,7 +139,7 @@ defmodule RigInboundGateway.ApiProxy.Handler.Kafka do
query: conn.query_string
})
|> Tracing.append_context(Tracing.context())
|> Poison.encode!()
|> Jason.encode!()

produce(partition, kafka_message, topic, schema)

Expand Down
4 changes: 2 additions & 2 deletions lib/rig_inbound_gateway/api_proxy/handler/kinesis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule RigInboundGateway.ApiProxy.Handler.Kinesis do
@impl Handler
def handle_http_request(conn, api, endpoint, request_path)

@doc "CORS response for preflight request."
# CORS response for preflight request.
def handle_http_request(
%{method: "OPTIONS"} = conn,
_,
Expand Down Expand Up @@ -125,7 +125,7 @@ defmodule RigInboundGateway.ApiProxy.Handler.Kinesis do
query: conn.query_string
})
|> Tracing.append_context(Tracing.context())
|> Poison.encode!()
|> Jason.encode!()

produce(partition, kinesis_message, topic)

Expand Down
2 changes: 1 addition & 1 deletion lib/rig_inbound_gateway/api_proxy/handler/nats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule RigInboundGateway.ApiProxy.Handler.Nats do
@doc @help_text
def handle_http_request(conn, api, endpoint, request_path)

@doc "CORS response for preflight request."
# CORS response for preflight request.
def handle_http_request(%{method: "OPTIONS"} = conn, _, %{"target" => "nats"} = _endpoint, _) do
conn
|> with_cors()
Expand Down
2 changes: 1 addition & 1 deletion lib/rig_inbound_gateway/api_proxy/presence_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule RigInboundGateway.ApiProxy.PresenceHandler do
"""
require Logger
@behaviour Phoenix.Tracker
use Phoenix.Tracker

alias RigInboundGateway.Proxy

Expand Down
2 changes: 1 addition & 1 deletion lib/rig_inbound_gateway/api_proxy/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ defmodule RigInboundGateway.ApiProxy.Serializer do
end

def encode_error_message(message) do
Poison.encode!(%{message: message})
Jason.encode!(%{message: message})
end
end
2 changes: 1 addition & 1 deletion lib/rig_inbound_gateway/api_proxy/sup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule RigInboundGateway.ApiProxy.Sup do

def init(:ok) do
children = [
worker(RigInboundGateway.ApiProxy.PresenceHandler, _args = [[pubsub_server: Rig.PubSub]])
{RigInboundGateway.ApiProxy.PresenceHandler, [pubsub_server: Rig.PubSub]}
]

Supervisor.init(children, strategy: :one_for_one)
Expand Down
2 changes: 1 addition & 1 deletion lib/rig_inbound_gateway/request_logger/kafka.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule RigInboundGateway.RequestLogger.Kafka do
}
}
|> Tracing.append_context(Tracing.context())
|> Poison.encode!()
|> Jason.encode!()

produce("partition", kafka_message)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/rig_inbound_gateway_web/v1/sse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ defmodule RigInboundGatewayWeb.V1.SSE do

{:error, reason} ->
req = :cowboy_req.reply(400, %{}, reason, req)
{:stop, req, :unknown_state}
# Returning :ok at this point simply closes the handler.
{:ok, req, :unknown_state}
end
end

Expand Down Expand Up @@ -84,7 +85,8 @@ defmodule RigInboundGatewayWeb.V1.SSE do

on_error = fn reason ->
req = :cowboy_req.reply(400, %{}, reason, req)
{:stop, req, :no_state}
# Returning :ok at this point simply closes the handler.
{:ok, req, :no_state}
end

ConnectionInit.set_up(
Expand Down
4 changes: 2 additions & 2 deletions lib/rig_inbound_gateway_web/v1/websocket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ defmodule RigInboundGatewayWeb.V1.Websocket do

# ---

@doc ~S"The client may send this as the response to the :ping heartbeat."
# The client may send this as the response to the :ping heartbeat.
@impl :cowboy_websocket
def websocket_handle({:pong, _app_data}, state), do: {:ok, state, :hibernate}
@impl :cowboy_websocket
def websocket_handle(:pong, state), do: {:ok, state, :hibernate}

@doc ~S"Allow the client to send :ping messages to test connectivity."
# Allow the client to send :ping messages to test connectivity.
@impl :cowboy_websocket
def websocket_handle({:ping, app_data}, _state), do: {:reply, {:pong, app_data}, :hibernate}

Expand Down
2 changes: 1 addition & 1 deletion lib/rig_outbound_gateway/kinesis/java_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ defmodule RigOutboundGateway.Kinesis.JavaClient do
@spec java_client_callback(data :: [{atom(), String.t()}, ...]) :: :ok
def java_client_callback(data) do
data[:body]
|> Poison.decode!()
|> Jason.decode!()
|> KinesisToFilter.kinesis_handler()
end
end
Loading

0 comments on commit 6543746

Please sign in to comment.