Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate dimensional metrics #408

Merged
merged 20 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ defmodule NewRelic.Harvest.TelemetrySdk.DimensionalMetrics.Harvester do
%{type: :count, name: name, value: new_value, attributes: attributes} = metric,
metrics_acc
) do
attributes_hash = :erlang.phash2(attributes)
tpitale marked this conversation as resolved.
Show resolved Hide resolved

case Map.get(metrics_acc, {:count, name, attributes_hash}) do
case Map.get(metrics_acc, {:count, name, attributes}) do
nil ->
Map.put(metrics_acc, {:count, name, attributes_hash}, metric)
Map.put(metrics_acc, {:count, name, attributes}, metric)

%{type: :count, value: current_value} = current_metric ->
Map.put(metrics_acc, {:count, name, attributes_hash}, %{
Map.put(metrics_acc, {:count, name, attributes}, %{
current_metric
| value: current_value + new_value
})
Expand All @@ -95,24 +93,20 @@ defmodule NewRelic.Harvest.TelemetrySdk.DimensionalMetrics.Harvester do
%{type: :gauge, name: name, value: new_value, attributes: attributes} = metric,
metrics_acc
) do
attributes_hash = :erlang.phash2(attributes)

case Map.get(metrics_acc, {:gauge, name, attributes_hash}) do
case Map.get(metrics_acc, {:gauge, name, attributes}) do
nil ->
Map.put(metrics_acc, {:gauge, name, attributes_hash}, metric)
Map.put(metrics_acc, {:gauge, name, attributes}, metric)

%{type: :gauge} = current_metric ->
Map.put(metrics_acc, {:gauge, name, attributes_hash}, %{current_metric | value: new_value})
Map.put(metrics_acc, {:gauge, name, attributes}, %{current_metric | value: new_value})
end
end

defp merge_metric(
%{type: :summary, name: name, value: new_value, attributes: attributes},
metrics_acc
) do
attributes_hash = :erlang.phash2(attributes)

case Map.get(metrics_acc, {:summary, name, attributes_hash}) do
case Map.get(metrics_acc, {:summary, name, attributes}) do
nil ->
new_summary = %{
type: :summary,
Expand All @@ -126,12 +120,12 @@ defmodule NewRelic.Harvest.TelemetrySdk.DimensionalMetrics.Harvester do
attributes: attributes
}

Map.put(metrics_acc, {:summary, name, attributes_hash}, new_summary)
Map.put(metrics_acc, {:summary, name, attributes}, new_summary)

%{type: :summary} = current_metric ->
Map.put(
metrics_acc,
{:summary, name, attributes_hash},
{:summary, name, attributes},
%{current_metric | value: update_summary_value_map(current_metric, new_value)}
)
end
Expand Down