Skip to content

Commit 2754ee2

Browse files
committed
(PUP-12083) Update soft limit warning for fact value & name length
This commit updates the warning for exceeding the fact value length soft limit to include the fact name and updates the warning for exceeding the fact name length soft limit to give the fact name with dots & include the length that was used to evaluate if the length exceeds the limit.
1 parent 13dcf5a commit 2754ee2

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

lib/puppet/configurer.rb

+13-12
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,37 @@ 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 fact name 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)
151-
Puppet.warning _("Payload with the current size of: '%{payload}' exceeds the payload size limit: %{max_size}") % { payload: payload, max_size: max_size }
151+
Puppet.warning _("Payload with the current size of: %{payload} exceeds the payload size limit: %{max_size}") % { payload: payload, max_size: max_size }
152152
end
153153

154-
def check_fact_name_length(name, number_of_dots)
154+
def check_fact_name_length(fact_path, number_of_dots)
155155
max_length = Puppet[:fact_name_length_soft_limit]
156156
return if max_length.zero?
157157

158+
name_without_dots = fact_path.join()
158159
# rough byte size estimations of fact path as a postgresql btree index
159-
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+
size_as_btree_index = 8 + (number_of_dots * 2) + name_without_dots.to_s.bytesize
161+
warn_fact_name_length(fact_path.join('.'), max_length, size_as_btree_index) if size_as_btree_index > max_length
161162
end
162163

163-
def check_fact_values_length(values)
164+
def check_fact_values_length(name, values)
164165
max_length = Puppet[:fact_value_length_soft_limit]
165166
return if max_length.zero?
166167

167-
warn_fact_value_length(values, max_length) if values.to_s.bytesize > max_length
168+
warn_fact_value_length(name, values, max_length) if values.to_s.bytesize > max_length
168169
end
169170

170171
def check_top_level_number_limit(size)
@@ -204,8 +205,8 @@ def parse_fact_name_and_value_limits(object, path = [])
204205
path.pop
205206
end
206207
else
207-
check_fact_name_length(path.join(), path.size)
208-
check_fact_values_length(object)
208+
check_fact_name_length(path, path.size)
209+
check_fact_values_length(path.join('.'), object)
209210
@number_of_facts += 1
210211
end
211212
end

spec/unit/configurer_spec.rb

+7-11
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,11 @@
203203
Puppet[:payload_soft_limit] = 0
204204

205205
facts.values = { 'processors' => {
206-
'cores' => 1,
207-
'count' => 2,
208-
'isa' => "i386",
209-
'models' => [
210-
"CPU1 @ 2.80GHz"
211-
],
212-
'physicalcount' => 4 }
206+
'isa' => "i386" }
213207
}
214208
Puppet::Node::Facts.indirection.save(facts)
215209

216-
expect(Puppet).to receive(:warning).with(/Fact value '.+' with the value length: '[1-9]*' exceeds the value length limit: [1-9]*/).twice
210+
expect(Puppet).to receive(:warning).with(/Fact processors.isa with value i386 with the value length: 4 exceeds the value length limit: 1/)
217211
configurer.run
218212
end
219213

@@ -235,7 +229,7 @@
235229
}
236230
Puppet::Node::Facts.indirection.save(facts)
237231

238-
expect(Puppet).to receive(:warning).with(/Payload with the current size of: '\d*' exceeds the payload size limit: \d*/)
232+
expect(Puppet).to receive(:warning).with(/Payload with the current size of: \d* exceeds the payload size limit: \d*/)
239233
configurer.run
240234
end
241235

@@ -294,10 +288,12 @@
294288
Puppet[:number_of_facts_soft_limit] = 0
295289
Puppet[:payload_soft_limit] = 0
296290

297-
facts.values = {'my_new_fact_name' => 'my_new_fact_value'}
291+
facts.values = { 'processors' => {
292+
'isa' => "i386" }
293+
}
298294
Puppet::Node::Facts.indirection.save(facts)
299295

300-
expect(Puppet).to receive(:warning).with(/Fact .+ with length: '[1-9]*' exceeds the length limit: [1-9]*/)
296+
expect(Puppet).to receive(:warning).with(/Fact processors.isa with length: 25 exceeds the fact name length limit: 1/)
301297
configurer.run
302298
end
303299

0 commit comments

Comments
 (0)