Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shard plugin #877

Merged
merged 11 commits into from
Sep 22, 2016
43 changes: 43 additions & 0 deletions lib/ohai/plugins/shard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Author:: Phil Dibowitz <[email protected]>
# Copyright:: Copyright (c) 2016 Facebook, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

def get_dmi_thing(dmi, thing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't declare a global helper method in a plugin file, either make is a true global helper or put it in the plugin class.

%w{system base_board chassis}.each do |section|
unless dmi[:thing][thing].compact.empty?
return dmi[:thing][thing]
end
end
end

Ohai.plugin(:ShardSeed) do
depends "hostname", "dmi"
provides "shard_seed"

collect_data(:default) do
base = Ohai.config[:plugin][:shard_seed][:base] || :hostname
data = case base
when :hostname
fqdn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fqdns can, and often are, nil because DNS. machinename would possibly be better, but you get into a religious warfare there with the short-hostname people who may have collisions in short hostnames across their infrastructure.

when :serial
get_dmi_thing(dmi, :serial_number)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seen so many 0123456789 DMI serial numbers. mostly on silicon mechanics boxes, but also HPaq motherboard replacements.

when :uuid
get_dmi_thing(dmi, :uuid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd bet money this isn't guaranteed to be unique either -- of course i've also seen NIC cards with the same Mac address as well...

end
shard_seed Digest::MD5.hexdigest(data)[0...7].to_i(16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You aren't requireing either of the digest libraries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why trim to 8 characters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'll add the requires.

Um, I don't remember why we did the 8 characters. Something something crytpo widths. Let me see if I can track that down.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So best we can tell that 2^15 buckets seemed sufficient and I think we had overflowed a variable or something somewhere without that....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone know if this will be an issue with FIPS? ISTR that the md5 functions get removed if you have OpenSSL in FIPS mode (groan). Alternatively, just using SHA-2 probably won't hurt anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Digest::MD5 still works in FIPS mode, that's Ruby's internal implementation as opposed to OpenSSL's. It's still in C so probably just as fast. We could also use the Adler CRC implementation in the Zlib module if we didn't want either MD5 or SHA for some reason.

end
end