Skip to content

Commit

Permalink
(PUP-12083) Update soft limit warning for fact value length to includ…
Browse files Browse the repository at this point in the history
…e name

This commit updates the soft limit warning for fact value length to include
the fact name.
  • Loading branch information
AriaXLi committed Oct 30, 2024
1 parent e758d5c commit 7fe146b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/puppet/configurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def warn_number_of_top_level_facts(size, max_number)
Puppet.warning _("The current number of top level facts: %{size} exceeds the top facts limit: %{max_size}") % { size: size, max_size: max_number }
end

def warn_fact_value_length(value, max_length)
Puppet.warning _("Fact value '%{value}' with the value length: '%{length}' exceeds the value length limit: %{max_length}") % { value: value, length: value.to_s.bytesize, max_length: max_length }
def warn_fact_value_length(name, value, max_length)
Puppet.warning _("Fact '%{name}' with value '%{value}' with the value length: '%{length}' exceeds the value length limit: %{max_length}") % { name: name, value: value, length: value.to_s.bytesize, max_length: max_length }
end

def warn_fact_payload_size(payload, max_size)
Expand All @@ -160,11 +160,11 @@ def check_fact_name_length(name, number_of_dots)
warn_fact_name_length(name, max_length) if size_as_btree_index > max_length
end

def check_fact_values_length(values)
def check_fact_values_length(name, values)
max_length = Puppet[:fact_value_length_soft_limit]
return if max_length.zero?

warn_fact_value_length(values, max_length) if values.to_s.bytesize > max_length
warn_fact_value_length(name, values, max_length) if values.to_s.bytesize > max_length
end

def check_top_level_number_limit(size)
Expand Down Expand Up @@ -204,8 +204,9 @@ def parse_fact_name_and_value_limits(object, path = [])
path.pop
end
else
check_fact_name_length(path.join(), path.size)
check_fact_values_length(object)
name = path.join
check_fact_name_length(name, path.size)
check_fact_values_length(name, object)
@number_of_facts += 1
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/configurer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
}
Puppet::Node::Facts.indirection.save(facts)

expect(Puppet).to receive(:warning).with(/Fact value '.+' with the value length: '[1-9]*' exceeds the value length limit: [1-9]*/).twice
expect(Puppet).to receive(:warning).with(/Fact '.+' with value '.+' with the value length: '[1-9]*' exceeds the value length limit: [1-9]*/).twice
configurer.run
end

Expand Down

0 comments on commit 7fe146b

Please sign in to comment.