Skip to content

Commit

Permalink
feat(data_point): to_s == line protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
kimburgess committed Dec 12, 2019
1 parent 1397e7f commit 9e4828d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/flux/data_point_spec.cr
Expand Up @@ -26,4 +26,14 @@ describe Flux::DataPoint do
point.tags.should eq({:test => "bar"})
end
end

describe "to_s" do
it "serializes to line procotol" do
time = Time.now
ts = time.to_unix
point = Flux::DataPoint.new "foo", time, a: 1
point.tag :test, "bar"
point.to_s.should eq("foo,test=bar a=1 #{ts}\n")
end
end
end
6 changes: 6 additions & 0 deletions src/flux/data_point.cr
@@ -1,3 +1,5 @@
require "./line_protocol"

# Model for InfluxDB data points.
struct Flux::DataPoint
alias TagSet = Hash(Symbol, String | Symbol)
Expand Down Expand Up @@ -31,4 +33,8 @@ struct Flux::DataPoint
def tagged?
!@tags.nil?
end

def to_s(io)
LineProtocol.serialize self, io
end
end

0 comments on commit 9e4828d

Please sign in to comment.