Skip to content

Commit 9dc7a3b

Browse files
authored
fix: track global payload size metric (#1496)
1 parent a8a163e commit 9dc7a3b

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/realtime/monitoring/prom_ex/plugins/tenant.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ defmodule Realtime.PromEx.Plugins.Tenant do
3535
[:realtime, :tenants, :payload, :size],
3636
event_name: [:realtime, :tenants, :payload, :size],
3737
measurement: :size,
38-
description: "Payload size",
38+
description: "Tenant payload size",
3939
tags: [:tenant],
4040
unit: :byte,
4141
reporter_options: [
42-
buckets: [100, 250, 500, 1000, 2000, 3000, 5000]
42+
buckets: [100, 250, 500, 1000, 2000, 3000, 5000, 10_000, 25_000]
43+
]
44+
),
45+
distribution(
46+
[:realtime, :payload, :size],
47+
event_name: [:realtime, :tenants, :payload, :size],
48+
measurement: :size,
49+
description: "Payload size",
50+
unit: :byte,
51+
reporter_options: [
52+
buckets: [100, 250, 500, 1000, 2000, 3000, 5000, 10_000, 25_000]
4353
]
4454
)
4555
]

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
44
def project do
55
[
66
app: :realtime,
7-
version: "2.42.1",
7+
version: "2.42.2",
88
elixir: "~> 1.17.3",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,

test/realtime/monitoring/prom_ex/plugins/tenant_test.exs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ defmodule Realtime.PromEx.Plugins.TenantTest do
227227
assert metric_value(bucket_pattern) > 0
228228
end
229229

230-
test "metric payload size", context do
230+
test "tenant metric payload size", context do
231231
external_id = context.tenant.external_id
232232

233233
pattern =
@@ -246,6 +246,24 @@ defmodule Realtime.PromEx.Plugins.TenantTest do
246246

247247
assert metric_value(bucket_pattern) > 0
248248
end
249+
250+
test "global metric payload size", context do
251+
external_id = context.tenant.external_id
252+
253+
pattern = ~r/realtime_payload_size_count\s(?<number>\d+)/
254+
255+
metric_value = metric_value(pattern)
256+
257+
message = %{topic: "a topic", event: "an event", payload: ["a", %{"b" => "c"}, 1, 23]}
258+
RealtimeWeb.TenantBroadcaster.pubsub_broadcast(external_id, "a topic", message, Phoenix.PubSub)
259+
260+
Process.sleep(200)
261+
assert metric_value(pattern) == metric_value + 1
262+
263+
bucket_pattern = ~r/realtime_payload_size_bucket{le="100"}\s(?<number>\d+)/
264+
265+
assert metric_value(bucket_pattern) > 0
266+
end
249267
end
250268

251269
defp metric_value(pattern) do

0 commit comments

Comments
 (0)