Skip to content

Commit

Permalink
Remove leading underscores in tag/field keys (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
burmajam authored Jul 12, 2023
1 parent 309cc24 commit 31eee7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.11.6

- Remove leading underscores in tag and field keys.

## v0.11.5

- Default `empty` value in fields must be quoted to be valid string field value.
Expand Down
10 changes: 8 additions & 2 deletions lib/fluxter/packet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ defmodule Fluxter.Packet do
|> to_string()
|> String.trim()
|> case do
"" -> "empty"
other -> to_string(other) |> escape(' ,')
"" ->
"empty"

other ->
other
|> to_string()
|> String.trim_leading("_")
|> escape(' ,')
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/fluxter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ defmodule FluxterTest do
assert_receive {:echo, "foo,bar=equal\=baz value=0i"}
end

test "tag key starting with underscore" do
TestFluxter.write("foo", [{:__under_bar, "baz"}], 0)
assert_receive {:echo, "foo,under_bar=baz value=0i"}
end

test "field key starting with underscore" do
TestFluxter.write("foo", [{:bar, "baz"}], [{:_under_qux, 16}])
assert_receive {:echo, "foo,bar=baz under_qux=16i"}
end

test "nil tag" do
TestFluxter.write("foo", [bar: "baz", qux: "baz", nil: nil], 0)
assert_receive {:echo, "foo,bar=baz,nil=nil,qux=baz value=0i"}
Expand Down

0 comments on commit 31eee7b

Please sign in to comment.