haproxy: fix mixing/invalid merging of stat entries

This commit is contained in:
Timothée Floure 2022-02-21 10:42:03 +01:00
parent 7a7fcd8e31
commit 9ddd999ed8
Signed by: tfloure
GPG key ID: 4502C902C00A1E12

View file

@ -40,11 +40,12 @@ defmodule HAHandler.HAProxy do
case mapping do
%{
"id" => id,
"proxyId" => proxy_id,
"objType" => type,
"field" => %{"name" => name},
"value" => %{"value" => value},
} ->
%{:id => id, :type => type, :field => name, :value => value}
%{:id => id, :proxy_id => proxy_id, :type => type, :field => name, :value => value}
_ ->
nil
end
@ -54,15 +55,16 @@ defmodule HAHandler.HAProxy do
extracted
|> List.flatten()
|> Enum.group_by(
fn mapping -> {mapping.type, mapping.id} end,
fn mapping -> {mapping.type, mapping.id, mapping.proxy_id} end,
fn mapping -> %{mapping.field => mapping.value} end
)
|> Enum.map(
fn {{type, id}, grouped_mappings} ->
fn {{type, id, proxy_id}, grouped_mappings} ->
grouped_mappings
|> Enum.reduce(fn l, r -> Map.merge(l,r) end)
|> Map.put("type", type)
|> Map.put("id", id)
|> Map.put("proxy_id", proxy_id)
end
)
|> Enum.group_by(