forked from lexmag/statix
-
Notifications
You must be signed in to change notification settings - Fork 4
Add UDS support #6
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1e39001
Initial
sanchda 3deb5a4
Fixups
sanchda 28f2c54
Add chomky tests
sanchda b06d817
Test server fixups
sanchda 424ee46
More
sanchda 0085161
oops forgot the app
sanchda d9eda0d
are you winning son
sanchda 9b8dc7b
Add... stuff
sanchda da94cc6
Fixup in comments only
sanchda db55fc9
Mix format
sanchda 1da4e46
Add cleanup
sanchda 254fb2c
Fixups
sanchda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| Code.require_file("../support/uds_test_server.exs", __DIR__) | ||
|
|
||
| defmodule Statix.UDSTest do | ||
| use ExUnit.Case | ||
|
|
||
| @moduletag :uds | ||
|
|
||
| defmodule TestStatix do | ||
| use Statix, runtime_config: true | ||
| end | ||
|
|
||
| setup_all do | ||
| socket_path = "/tmp/statix_test_#{:erlang.unique_integer([:positive])}.sock" | ||
| {:ok, _} = Statix.UDSTestServer.start_link(socket_path, __MODULE__.Server) | ||
|
|
||
| on_exit(fn -> | ||
| File.rm(socket_path) | ||
| end) | ||
|
|
||
| {:ok, socket_path: socket_path} | ||
| end | ||
|
|
||
| setup context do | ||
| Statix.UDSTestServer.setup(__MODULE__.Server) | ||
| TestStatix.connect(socket_path: context[:socket_path]) | ||
| :ok | ||
| end | ||
|
|
||
| test "increment via UDS", _context do | ||
| TestStatix.increment("sample") | ||
| assert_receive {:test_server, _, "sample:1|c"} | ||
|
|
||
| TestStatix.increment("sample", 2) | ||
| assert_receive {:test_server, _, "sample:2|c"} | ||
|
|
||
| TestStatix.increment("sample", 3, tags: ["foo:bar", "baz"]) | ||
| assert_receive {:test_server, _, "sample:3|c|#foo:bar,baz"} | ||
| end | ||
|
|
||
| test "decrement via UDS", _context do | ||
| TestStatix.decrement("sample") | ||
| assert_receive {:test_server, _, "sample:-1|c"} | ||
|
|
||
| TestStatix.decrement("sample", 2) | ||
| assert_receive {:test_server, _, "sample:-2|c"} | ||
|
|
||
| TestStatix.decrement("sample", 3, tags: ["foo:bar", "baz"]) | ||
| assert_receive {:test_server, _, "sample:-3|c|#foo:bar,baz"} | ||
| end | ||
|
|
||
| test "gauge via UDS", _context do | ||
| TestStatix.gauge("sample", 2) | ||
| assert_receive {:test_server, _, "sample:2|g"} | ||
|
|
||
| TestStatix.gauge("sample", 2.1) | ||
| assert_receive {:test_server, _, "sample:2.1|g"} | ||
|
|
||
| TestStatix.gauge("sample", 3, tags: ["foo:bar", "baz"]) | ||
| assert_receive {:test_server, _, "sample:3|g|#foo:bar,baz"} | ||
| end | ||
|
|
||
| test "histogram via UDS", _context do | ||
| TestStatix.histogram("sample", 2) | ||
| assert_receive {:test_server, _, "sample:2|h"} | ||
|
|
||
| TestStatix.histogram("sample", 2.1) | ||
| assert_receive {:test_server, _, "sample:2.1|h"} | ||
|
|
||
| TestStatix.histogram("sample", 3, tags: ["foo:bar", "baz"]) | ||
| assert_receive {:test_server, _, "sample:3|h|#foo:bar,baz"} | ||
| end | ||
|
|
||
| test "timing via UDS", _context do | ||
| TestStatix.timing("sample", 2) | ||
| assert_receive {:test_server, _, "sample:2|ms"} | ||
|
|
||
| TestStatix.timing("sample", 2.1) | ||
| assert_receive {:test_server, _, "sample:2.1|ms"} | ||
|
|
||
| TestStatix.timing("sample", 3, tags: ["foo:bar", "baz"]) | ||
| assert_receive {:test_server, _, "sample:3|ms|#foo:bar,baz"} | ||
| end | ||
|
|
||
| test "set via UDS", _context do | ||
| TestStatix.set("sample", "user1") | ||
| assert_receive {:test_server, _, "sample:user1|s"} | ||
|
|
||
| TestStatix.set("sample", "user2", tags: ["foo:bar"]) | ||
| assert_receive {:test_server, _, "sample:user2|s|#foo:bar"} | ||
| end | ||
|
|
||
| test "measure via UDS", _context do | ||
| result = TestStatix.measure("sample", [], fn -> :measured end) | ||
| assert result == :measured | ||
| assert_receive {:test_server, _, <<"sample:", _::binary>>} | ||
| end | ||
|
|
||
| test "sample rate via UDS", _context do | ||
| TestStatix.increment("sample", 1, sample_rate: 1.0) | ||
| assert_receive {:test_server, _, "sample:1|c|@1.0"} | ||
|
|
||
| TestStatix.increment("sample", 1, sample_rate: 0.0) | ||
| refute_received {:test_server, _, _} | ||
| end | ||
|
|
||
| test "large packet over 1024 bytes via UDS maintains atomicity", _context do | ||
| # Create tags that will result in a packet > 1024 bytes | ||
| # Each tag is roughly 30 chars, so ~35 tags = ~1050 bytes total packet | ||
| tags = | ||
| for i <- 1..35 do | ||
| "very_long_tag_name_#{i}:very_long_tag_value_#{i}" | ||
| end | ||
|
|
||
| TestStatix.increment("sample.with.long.metric.name", 1, tags: tags) | ||
|
|
||
| # Verify we receive the complete packet atomically (all or nothing) | ||
| assert_receive {:test_server, _, packet}, 1000 | ||
|
|
||
| # Verify packet structure is intact and complete | ||
| assert packet =~ ~r/^sample\.with\.long\.metric\.name:1\|c\|#/ | ||
| assert String.contains?(packet, "very_long_tag_name_1:very_long_tag_value_1") | ||
| assert String.contains?(packet, "very_long_tag_name_35:very_long_tag_value_35") | ||
|
|
||
| # Verify packet size exceeds 1024 bytes | ||
| assert byte_size(packet) > 1024 | ||
| end | ||
|
|
||
| test "very large packet over 4096 bytes via UDS maintains atomicity", _context do | ||
| # ~140 tags at 30 chars each = ~4200 bytes total | ||
| tags = | ||
| for i <- 1..140 do | ||
| "very_long_tag_name_#{i}:very_long_tag_value_#{i}" | ||
| end | ||
|
|
||
| TestStatix.gauge("sample.metric.with.many.tags", 12345, tags: tags) | ||
|
|
||
| assert_receive {:test_server, _, packet}, 1000 | ||
|
|
||
| assert packet =~ ~r/^sample\.metric\.with\.many\.tags:12345\|g\|#/ | ||
| assert String.contains?(packet, "very_long_tag_name_1:very_long_tag_value_1") | ||
| assert String.contains?(packet, "very_long_tag_name_140:very_long_tag_value_140") | ||
| assert byte_size(packet) > 4096 | ||
|
|
||
| # Verify atomicity: all 140 tags present (no truncation) | ||
| tag_count = packet |> String.split(",") |> length() | ||
| assert tag_count == 140 | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.