Skip to content

Commit

Permalink
Hash host ID so its stable and well distributed
Browse files Browse the repository at this point in the history
This PR takes the host ID and runs it through a hash so that it is well
distributed. This makes it so that machines that report similar host IDs
are easily distinguished.

Instances of similar IDs occur on EC2 where the ID is prefixed and on
motherboards created in the same batch.
  • Loading branch information
dadgar committed Apr 10, 2017
1 parent 3f92cc7 commit 7f6d95f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"crypto/sha512"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -645,6 +646,17 @@ func (a *Agent) makeNodeID() (string, error) {
return a.makeRandomID()
}

// Hash the input to make it well distributed. The reported Host UUID may be
// similar across nodes if they are on a cloud provider or on motherboards
// created from the same batch.
buf := sha512.Sum512([]byte(id))
id = fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
buf[0:4],
buf[4:6],
buf[6:8],
buf[8:10],
buf[10:16])

a.logger.Printf("[DEBUG] Using unique ID %q from host as node ID", id)
return id, nil
}
Expand Down

0 comments on commit 7f6d95f

Please sign in to comment.