Skip to content

Commit

Permalink
Merge pull request #2 from Optum/proposed-name-changes
Browse files Browse the repository at this point in the history
updating  method and var names
  • Loading branch information
Esity authored Mar 23, 2022
2 parents 52a1416 + 8228a51 commit 33b4382
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions lib/telemetry/metrics/parser/line_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ def hash_to_line(hash)
end
module_function :hash_to_line

def line_is_current?(timestamp, limit: 86_400)
def line_is_recent?(timestamp, max_age_sec: 86_400)
return false unless timestamp.is_a?(Integer)
return false unless limit.is_a?(Integer)
return false unless max_age_sec.is_a?(Integer)

current_time = DateTime.now.strftime('%s%9N').to_i
time_limit = current_time - (limit * 1000 * 1000 * 1000 * 3)
timestamp >= time_limit
current_epoch_ns = DateTime.now.strftime('%s%9N').to_i
timestamp >= current_epoch_ns - (max_age_sec * 1000 * 1000 * 1000 * 3)
end
module_function :line_is_current?
module_function :line_is_recent?

def field_is_number?(value)
return false if value.nil?
Expand Down Expand Up @@ -113,7 +112,7 @@ def valid_tag_chars

def line_is_valid?(line) # rubocop:disable Metrics/AbcSize
line = parse(line) if line.is_a?(String)
return "line is too old, #{line}" unless line_is_current?(line[:timestamp])
return "line is too old, #{line}" unless line_is_recent?(line[:timestamp])
return "line is missing influxdb_database, #{line}" unless node_group_tag? line[:tags]
return "line is missing influxdb_node_group, #{line}" unless database_tag? line[:tags]
return "measurement name #{line[:measurement]} is not valid" unless measurement_valid?(line[:measurement])
Expand Down
6 changes: 3 additions & 3 deletions spec/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
end

it 'can validate the line is current' do
expect(described_class.line_is_current?(1_465_839_830_100_400_200)).to eq false
expect(described_class.line_is_current?(2_665_839_830_100_400_200)).to eq true
expect(described_class.line_is_current?('11111')).to eq false
expect(described_class.line_is_recent?(1_465_839_830_100_400_200)).to eq false
expect(described_class.line_is_recent?(2_665_839_830_100_400_200)).to eq true
expect(described_class.line_is_recent?('11111')).to eq false
end

it 'can verify a node_group tag exists' do
Expand Down

0 comments on commit 33b4382

Please sign in to comment.