Skip to content

Commit 33b4382

Browse files
authored
Merge pull request #2 from Optum/proposed-name-changes
updating method and var names
2 parents 52a1416 + 8228a51 commit 33b4382

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/telemetry/metrics/parser/line_protocol.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ def hash_to_line(hash)
5656
end
5757
module_function :hash_to_line
5858

59-
def line_is_current?(timestamp, limit: 86_400)
59+
def line_is_recent?(timestamp, max_age_sec: 86_400)
6060
return false unless timestamp.is_a?(Integer)
61-
return false unless limit.is_a?(Integer)
61+
return false unless max_age_sec.is_a?(Integer)
6262

63-
current_time = DateTime.now.strftime('%s%9N').to_i
64-
time_limit = current_time - (limit * 1000 * 1000 * 1000 * 3)
65-
timestamp >= time_limit
63+
current_epoch_ns = DateTime.now.strftime('%s%9N').to_i
64+
timestamp >= current_epoch_ns - (max_age_sec * 1000 * 1000 * 1000 * 3)
6665
end
67-
module_function :line_is_current?
66+
module_function :line_is_recent?
6867

6968
def field_is_number?(value)
7069
return false if value.nil?
@@ -113,7 +112,7 @@ def valid_tag_chars
113112

114113
def line_is_valid?(line) # rubocop:disable Metrics/AbcSize
115114
line = parse(line) if line.is_a?(String)
116-
return "line is too old, #{line}" unless line_is_current?(line[:timestamp])
115+
return "line is too old, #{line}" unless line_is_recent?(line[:timestamp])
117116
return "line is missing influxdb_database, #{line}" unless node_group_tag? line[:tags]
118117
return "line is missing influxdb_node_group, #{line}" unless database_tag? line[:tags]
119118
return "measurement name #{line[:measurement]} is not valid" unless measurement_valid?(line[:measurement])

spec/validate_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
end
3434

3535
it 'can validate the line is current' do
36-
expect(described_class.line_is_current?(1_465_839_830_100_400_200)).to eq false
37-
expect(described_class.line_is_current?(2_665_839_830_100_400_200)).to eq true
38-
expect(described_class.line_is_current?('11111')).to eq false
36+
expect(described_class.line_is_recent?(1_465_839_830_100_400_200)).to eq false
37+
expect(described_class.line_is_recent?(2_665_839_830_100_400_200)).to eq true
38+
expect(described_class.line_is_recent?('11111')).to eq false
3939
end
4040

4141
it 'can verify a node_group tag exists' do

0 commit comments

Comments
 (0)