Skip to content

Commit dc0d2e6

Browse files
committed
(PUP-12083) Update soft limit warning for fact value & name length
This commit updates the soft limit warning for fact value length to include the fact name and updates the soft limit warning for fact name length to include the length that was used to evaluate if the length exceeds the limit.
1 parent e758d5c commit dc0d2e6

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

lib/puppet/configurer.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ def warn_number_of_facts(size, max_number)
135135
Puppet.warning _("The current total number of fact values: %{size} exceeds the fact values limit: %{max_size}") % { size: size, max_size: max_number }
136136
end
137137

138-
def warn_fact_name_length(name, max_length)
139-
Puppet.warning _("Fact %{name} with length: '%{length}' exceeds the length limit: %{limit}") % { name: name, length: name.to_s.bytesize, limit: max_length }
138+
def warn_fact_name_length(name, max_length, fact_name_length)
139+
Puppet.warning _("Fact %{name} with length: '%{length}' exceeds the length limit: %{limit}") % { name: name, length: fact_name_length, limit: max_length }
140140
end
141141

142142
def warn_number_of_top_level_facts(size, max_number)
143143
Puppet.warning _("The current number of top level facts: %{size} exceeds the top facts limit: %{max_size}") % { size: size, max_size: max_number }
144144
end
145145

146-
def warn_fact_value_length(value, max_length)
147-
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 }
146+
def warn_fact_value_length(name, value, max_length)
147+
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 }
148148
end
149149

150150
def warn_fact_payload_size(payload, max_size)
@@ -157,14 +157,14 @@ def check_fact_name_length(name, number_of_dots)
157157

158158
# rough byte size estimations of fact path as a postgresql btree index
159159
size_as_btree_index = 8 + (number_of_dots * 2) + name.to_s.bytesize
160-
warn_fact_name_length(name, max_length) if size_as_btree_index > max_length
160+
warn_fact_name_length(name, max_length, size_as_btree_index) if size_as_btree_index > max_length
161161
end
162162

163-
def check_fact_values_length(values)
163+
def check_fact_values_length(name, values)
164164
max_length = Puppet[:fact_value_length_soft_limit]
165165
return if max_length.zero?
166166

167-
warn_fact_value_length(values, max_length) if values.to_s.bytesize > max_length
167+
warn_fact_value_length(name, values, max_length) if values.to_s.bytesize > max_length
168168
end
169169

170170
def check_top_level_number_limit(size)
@@ -204,8 +204,9 @@ def parse_fact_name_and_value_limits(object, path = [])
204204
path.pop
205205
end
206206
else
207-
check_fact_name_length(path.join(), path.size)
208-
check_fact_values_length(object)
207+
name = path.join('.')
208+
check_fact_name_length(name, path.size - 1) # second param is number of dots in fact name
209+
check_fact_values_length(name, object)
209210
@number_of_facts += 1
210211
end
211212
end

spec/unit/configurer_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
}
214214
Puppet::Node::Facts.indirection.save(facts)
215215

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

@@ -288,16 +288,24 @@
288288
end
289289

290290
it "should warn the user when the fact name length limits are exceeded" do
291-
Puppet[:fact_name_length_soft_limit] = 1
291+
Puppet[:fact_name_length_soft_limit] = 30
292292
Puppet[:fact_value_length_soft_limit] = 0
293293
Puppet[:top_level_facts_soft_limit] = 0
294294
Puppet[:number_of_facts_soft_limit] = 0
295295
Puppet[:payload_soft_limit] = 0
296296

297-
facts.values = {'my_new_fact_name' => 'my_new_fact_value'}
297+
facts.values = { 'processors' => {
298+
'cores' => 1,
299+
'count' => 2,
300+
'isa' => "i386",
301+
'models' => [
302+
"CPU1 @ 2.80GHz"
303+
],
304+
'physicalcount' => 4 }
305+
}
298306
Puppet::Node::Facts.indirection.save(facts)
299307

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

0 commit comments

Comments
 (0)