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

Passing the base platform name to the nodemanager #3612

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions components/ingest-service/backend/chef_client_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (ccr *ChefClientRun) initializeNodeInfo() (sharedNodeInfo NodeInfo, err err
UptimeSeconds: int64(uptimeSeconds),
OrganizationName: ccr.OrganizationName,
Environment: ccr.NodePayload.ChefEnvironment,
Platform: getPlatformWithVersion(ccr.NodePayload),
Platform: ccr.PlatformWithVersion(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is cleaning up the way we grab the platform.

PlatformFamily: EmptyStringIfNil(ccr.NodePayload.Automatic["platform_family"]),
PlatformVersion: EmptyStringIfNil(ccr.NodePayload.Automatic["platform_version"]),
// Tags ccr. TODO: Is this compliance tags?
Expand Down Expand Up @@ -286,6 +286,10 @@ func (ccr *ChefClientRun) initializeNodeInfo() (sharedNodeInfo NodeInfo, err err
return // nolint: nakedret
}

func (ccr *ChefClientRun) Platform() string {
return EmptyStringIfNil(ccr.NodePayload.Automatic["platform"])
}

// ChefVersion Returns a chef version string retrieved from automatic attributes or an empty string if it is not present
func (ccr *ChefClientRun) ChefVersion() string {
chefPackages := extractMapOrEmpty(ccr.NodePayload.Automatic, "chef_packages")
Expand Down Expand Up @@ -492,9 +496,9 @@ func countNumberOfValueObject(object interface{}) int {
return count
}

func getPlatformWithVersion(nodePayload NodePayload) string {
platform := EmptyStringIfNil(nodePayload.Automatic["platform"])
platformVersion := EmptyStringIfNil(nodePayload.Automatic["platform_version"])
func (ccr *ChefClientRun) PlatformWithVersion() string {
platform := ccr.Platform()
platformVersion := EmptyStringIfNil(ccr.NodePayload.Automatic["platform_version"])

platformAndVersion := ""

Expand Down
2 changes: 2 additions & 0 deletions components/ingest-service/pipeline/message/chef_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ChefRun struct {
NodeRun backend.Run
NodeAttribute backend.NodeAttribute
BulkableRequests []elastic.BulkableRequest
Platform string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the raw platform to the message that is passed along in the pipeline.

Ctx context.Context
errc chan<- error
}
Expand All @@ -43,6 +44,7 @@ func NewChefRun(ctx context.Context, run *chef.Run, err chan<- error) ChefRun {
backend.Run{},
backend.NodeAttribute{},
[]elastic.BulkableRequest{},
"",
ctx,
err,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func ChefRunTransmogrify(in <-chan message.ChefRun, out chan<- message.ChefRun,
continue
}

// Needed for the nodemanager because the platform field is combined with the version.
msg.Platform = ccr.Platform()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only place we have access to the raw platform. So, we set the pipeline msg platform here.


message.PropagateChefRun(out, &msg)
}
close(out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func nodeManagerPublisher(in <-chan message.ChefRun, nodeManagerClient manager.N
continue
}

nodeMetadata, err := gatherInfoForNode(msg.Node)
nodeMetadata, err := gatherInfoForNode(msg)
if err != nil {
log.Errorf("unable parse node data to be send to manager. aborting attempt to send info to mgr for node %s -- %v", msg.Node.NodeName, err)
out <- msg
Expand All @@ -51,7 +51,9 @@ func nodeManagerPublisher(in <-chan message.ChefRun, nodeManagerClient manager.N
return out
}

func gatherInfoForNode(node backend.Node) (*manager.NodeMetadata, error) {
func gatherInfoForNode(msg message.ChefRun) (*manager.NodeMetadata, error) {
node := msg.Node

// convert node check in time to proto timestamp
timestamp, err := ptypes.TimestampProto(node.Checkin)
if err != nil {
Expand Down Expand Up @@ -82,7 +84,7 @@ func gatherInfoForNode(node backend.Node) (*manager.NodeMetadata, error) {
return &manager.NodeMetadata{
Uuid: node.EntityUuid,
Name: node.NodeName,
PlatformName: node.PlatformFamily,
PlatformName: msg.Platform,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then at this point, we can set the platform from the pipeline message.

PlatformRelease: node.PlatformVersion,
LastContact: timestamp,
SourceId: node.CloudID,
Expand Down