Skip to content

Commit

Permalink
Merge pull request #17 from jaronoff97/update-opamp-protos
Browse files Browse the repository at this point in the history
update to new opamp version
  • Loading branch information
jaronoff97 authored Jul 11, 2024
2 parents 32e7fd6 + f3972a7 commit be7c697
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
38 changes: 35 additions & 3 deletions lib/tails_web/protobufs/opamp.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule Opamp.Proto.AgentToServer do

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:instance_uid, 1, type: :string, json_name: "instanceUid")
field(:instance_uid, 1, type: :bytes, json_name: "instanceUid")
field(:sequence_num, 2, type: :uint64, json_name: "sequenceNum")
field(:agent_description, 3, type: Opamp.Proto.AgentDescription, json_name: "agentDescription")
field(:capabilities, 4, type: :uint64)
Expand All @@ -126,6 +126,13 @@ defmodule Opamp.Proto.AgentToServer do
type: Opamp.Proto.ConnectionSettingsRequest,
json_name: "connectionSettingsRequest"
)

field(:custom_capabilities, 12,
type: Opamp.Proto.CustomCapabilities,
json_name: "customCapabilities"
)

field(:custom_message, 13, type: Opamp.Proto.CustomMessage, json_name: "customMessage")
end

defmodule Opamp.Proto.AgentDisconnect do
Expand Down Expand Up @@ -166,7 +173,7 @@ defmodule Opamp.Proto.ServerToAgent do

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:instance_uid, 1, type: :string, json_name: "instanceUid")
field(:instance_uid, 1, type: :bytes, json_name: "instanceUid")
field(:error_response, 2, type: Opamp.Proto.ServerErrorResponse, json_name: "errorResponse")
field(:remote_config, 3, type: Opamp.Proto.AgentRemoteConfig, json_name: "remoteConfig")

Expand All @@ -189,6 +196,13 @@ defmodule Opamp.Proto.ServerToAgent do
)

field(:command, 9, type: Opamp.Proto.ServerToAgentCommand)

field(:custom_capabilities, 10,
type: Opamp.Proto.CustomCapabilities,
json_name: "customCapabilities"
)

field(:custom_message, 11, type: Opamp.Proto.CustomMessage, json_name: "customMessage")
end

defmodule Opamp.Proto.OpAMPConnectionSettings do
Expand Down Expand Up @@ -471,7 +485,7 @@ defmodule Opamp.Proto.AgentIdentification do

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:new_instance_uid, 1, type: :string, json_name: "newInstanceUid")
field(:new_instance_uid, 1, type: :bytes, json_name: "newInstanceUid")
end

defmodule Opamp.Proto.AgentRemoteConfig do
Expand Down Expand Up @@ -513,3 +527,21 @@ defmodule Opamp.Proto.AgentConfigFile do
field(:body, 1, type: :bytes)
field(:content_type, 2, type: :string, json_name: "contentType")
end

defmodule Opamp.Proto.CustomCapabilities do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:capabilities, 1, repeated: true, type: :string)
end

defmodule Opamp.Proto.CustomMessage do
@moduledoc false

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field(:capability, 1, type: :string)
field(:type, 2, type: :string)
field(:data, 3, type: :bytes)
end
17 changes: 9 additions & 8 deletions lib/tails_web/serializer/opampserializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,35 @@ defmodule TailsWeb.OpAMPSerializer do
data::binary
>>) do
proto = Opamp.Proto.AgentToServer.decode(data)
instance_uuid = UUID.binary_to_string!(proto.instance_uid)
# IO.puts("-----------------------")
# IO.puts("is a memember?")
# IO.inspect(Agent.get(:connections, &MapSet.member?(&1, proto.instance_uid)))
# IO.inspect(Agent.get(:connections, &MapSet.to_list/1))
# IO.puts("-----------------------")

case Agent.get(:connections, &MapSet.member?(&1, proto.instance_uid)) do
false -> respond_join(proto)
true -> respond_heartbeat(proto)
case Agent.get(:connections, &MapSet.member?(&1, instance_uuid)) do
false -> respond_join(proto, instance_uuid)
true -> respond_heartbeat(proto, instance_uuid)
end
end

defp respond_join(proto) do
Agent.update(:connections, &MapSet.put(&1, proto.instance_uid))
defp respond_join(proto, instance_uuid) do
Agent.update(:connections, &MapSet.put(&1, instance_uuid))
IO.puts("JOINING")

%Message{
topic: "agents:" <> proto.instance_uid,
topic: "agents:" <> instance_uuid,
event: "phx_join",
payload: proto,
ref: proto.sequence_num,
join_ref: "join"
}
end

defp respond_heartbeat(proto) when proto.sequence_num > 0 do
defp respond_heartbeat(proto, instance_uuid) when proto.sequence_num > 0 do
%Message{
topic: "agents:" <> proto.instance_uid,
topic: "agents:" <> instance_uuid,
event: "heartbeat",
payload: proto,
ref: proto.sequence_num,
Expand Down

0 comments on commit be7c697

Please sign in to comment.